LVM Logical Volume Manager-example of increasing LV capacity

Source: Internet
Author: User
Tags hex code

Steps:

(1) add a new 8e systemID partition;

(2) use the pvcreate command to construct the PV;

(3) use the vgextend command to add PV to vg_1;

(4) Use the lvresize command to add the PE in the newly added PV to lv_1;

(5) Use the resize2fs command to expand the LV capacity to the entire file system;

 
(1) add a new 8e systemID partition. Since the previous four primary partitions are created, if you want to create another partition, delete/dev/sdb4, create an extended partition and add the 8e systemID partition under the extended partition. The steps are as follows:

[Root @ centos6 ~] # Df-h # Check the lvm mounting status
Filesystem Size Used Avail Use % Mounted on
/Dev/sda3 16G 1.5G 14G 11%/
Tmpfs 112 M 0 112 M 0%/dev/shm
/Dev/sda1 194 M 29 M 155 M 16%/boot
/Dev/mapper/vg_1-lv_1 20G 172 M 19G 1%/mnt/lvm
[Root @ centos6 ~] # Umount/mnt/lvm/# Uninstall lvm
[Root @ centos6 ~] # Df-h
Filesystem Size Used Avail Use % Mounted on
/Dev/sda3 16G 1.5G 14G 11%/
Tmpfs 112 M 0 112 M 0%/dev/shm
/Dev/sda1 194 M 29 M 155 M 16%/boot
[Root @ centos6 ~] # Lvremove/dev/vg_1/lv_1 # delete lv_1
Do you really want to remove active logical volume lv_1? [Y/n]: y
Logical volume "lv_1" successfully removed
[Root @ centos6 ~] # Lvs
[Root @ centos6 ~] # Vgreduce vg_1/dev/sdb4 # Remove/dev/sdb4 from vg_1
Removed "/dev/sdb4" from volume group "vg_1"
[Root @ centos6 ~] # Pvremove/dev/sdb4 # Remove/dev/sdb4 from pv
Labels on physical volume "/dev/sdb4" successfully wiped
[Root @ centos6 ~] # Pvs # View pv
Pv vg Fmt Attr PSize PFree
/Dev/sdb1 vg_1 lvm2 a -- 5.00g 5.00g
/Dev/sdb2 vg_1 lvm2 a -- 5.00g 5.00g
/Dev/sdb3 vg_1 lvm2 a -- 5.00g 5.00g
[Root @ centos6 ~] # Fdisk/dev/sdb # partition into/dev/sdb disk
WARNING: DOS-compatible mode is deprecated. It's stronugly recommended
Switch off the mode (command 'C') and change display units
Sectors (command 'u ').
Command (m for help): p
Disk/dev/sdb: 85.9 GB, 85899345920 bytes
255 heads, 63 sectors/track, 10443 cylinders
Units = cylinders of 16065*512 = 8225280 bytes
Sector size (logical/physical): 512 bytes/512 bytes
I/O size (minimum/optimal): 512 bytes/512 bytes
Disk identifier: 0x60710230
Device Boot Start End Blocks Id System
/Dev/sdb1 1 654 5253223 + 8e Linux LVM
/Dev/sdb2 655 1308 5253255 8e Linux LVM
/Dev/sdb3 1309 1962 5253255 8e Linux LVM
/Dev/sdb4 1963 2616 5253255 8e Linux LVM
Command (m for help): d # Delete/dev/sdb4 partition
Partition number (1-4): 4
Command (m for help): p
Disk/dev/sdb: 85.9 GB, 85899345920 bytes
255 heads, 63 sectors/track, 10443 cylinders
Units = cylinders of 16065*512 = 8225280 bytes
Sector size (logical/physical): 512 bytes/512 bytes
I/O size (minimum/optimal): 512 bytes/512 bytes
Disk identifier: 0x60710230
Device Boot Start End Blocks Id System
/Dev/sdb1 1 654 5253223 + 8e Linux LVM
/Dev/sdb2 655 1308 5253255 8e Linux LVM
/Dev/sdb3 1309 1962 5253255 8e Linux LVM
Command (m for help): n
Command action
E extended
P primary partition (1-4)
E
Selected partition 4 # create an extended partition
First cylinder (1963-10443, default 1963 ):
Using default value 1963
Last cylinder, + cylinders or + size {K, M, G} (1963-10443, default 10443): + 10G
Command (m for help): p
Disk/dev/sdb: 85.9 GB, 85899345920 bytes
255 heads, 63 sectors/track, 10443 cylinders
Units = cylinders of 16065*512 = 8225280 bytes
Sector size (logical/physical): 512 bytes/512 bytes
I/O size (minimum/optimal): 512 bytes/512 bytes
Disk identifier: 0x60710230
Device Boot Start End Blocks Id System
/Dev/sdb1 1 654 5253223 + 8e Linux LVM
/Dev/sdb2 655 1308 5253255 8e Linux LVM
/Dev/sdb3 1309 1962 5253255 8e Linux LVM
/Dev/sdb4 1963 3268 10490445 5 Extended
Command (m for help): n # Create a new partition
First cylinder (1963-3268, default 1963 ):
Using default value 1963
Last cylinder, + cylinders or + size {K, M, G} (1963-3268, default 3268): + 5G
Command (m for help): p
Disk/dev/sdb: 85.9 GB, 85899345920 bytes
255 heads, 63 sectors/track, 10443 cylinders
Units = cylinders of 16065*512 = 8225280 bytes
Sector size (logical/physical): 512 bytes/512 bytes
I/O size (minimum/optimal): 512 bytes/512 bytes
Disk identifier: 0x60710230
Device Boot Start End Blocks Id System
/Dev/sdb1 1 654 5253223 + 8e Linux LVM
/Dev/sdb2 655 1308 5253255 8e Linux LVM
/Dev/sdb3 1309 1962 5253255 8e Linux LVM
/Dev/sdb4 1963 3268 10490445 5 Extended
/Dev/sdb5 1963 2616 5253223 + 83 Linux
Command (m for help): t
Partition number (1-5): 5
Hex code (type L to list codes): 8e # Change the systemID of the/dev/sdb5 partition to 8e.
Changed system type of partition 5 to 8e (Linux LVM)
Command (m for help): p
Disk/dev/sdb: 85.9 GB, 85899345920 bytes
255 heads, 63 sectors/track, 10443 cylinders
Units = cylinders of 16065*512 = 8225280 bytes
Sector size (logical/physical): 512 bytes/512 bytes
I/O size (minimum/optimal): 512 bytes/512 bytes
Disk identifier: 0x60710230
Device Boot Start End Blocks Id System
/Dev/sdb1 1 654 5253223 + 8e Linux LVM
/Dev/sdb2 655 1308 5253255 8e Linux LVM
/Dev/sdb3 1309 1962 5253255 8e Linux LVM
/Dev/sdb4 1963 3268 10490445 5 Extended
/Dev/sdb5 1963 2616 5253223 + 8e Linux LVM
Command (m for help): w
The partition table has been altered!
Calling ioctl () to re-read partition table.
Syncing disks.
[Root @ centos6 ~] # Partprobe

Create a lv and mount it;


[Root @ centos6 ~] # Lvcreate-L 15G-n lv_1 vg_1
Logical volume "lv_1" created
[Root @ centos6 ~] # Lvs
Lv vg Attr LSize Pool Origin Data % Move Log Cpy % Sync Convert
Lv_1 vg_1-wi-a ----- 15.00g
[Root @ centos6 ~] # Mkfs-t ext4/dev/vg_1/lv_1
[Root @ centos6 ~] # Mount/dev/vg_1/lv_1/mnt/lvm
[Root @ centos6 ~] # Df-h
Filesystem Size Used Avail Use % Mounted on
/Dev/sda3 16G 1.5G 14G 11%/
Tmpfs 112 M 0 112 M 0%/dev/shm
/Dev/sda1 194 M 29 M 155 M 16%/boot
/Dev/mapper/vg_1-lv_1 15G 166 M 14G 2%/mnt/lvm


(2) create a new PV;


[Root @ centos6 ~] # Pvcreate/dev/sdb5
Physical volume "/dev/sdb5" successfully created
[Root @ centos6 ~] # Pvs
Pv vg Fmt Attr PSize PFree
/Dev/sdb1 vg_1 lvm2 a -- 5.00g 0
/Dev/sdb2 vg_1 lvm2 a -- 5.00g 0
/Dev/sdb3 vg_1 lvm2 a -- 5.00g 0
/Dev/sdb5 lvm2 a -- 5.01g 5.01g

(3) use the vgextend command to add PV to vg_1;


[Root @ centos6 ~] # Vgextend vg_1/dev/sdb5
Volume group "vg_1" successfully extended
[Root @ centos6 ~] # Vgs
VG # PV # LV # SN Attr VSize VFree
Vg_1 4 1 0 wz -- n-20.00g 5.00g
[Root @ centos6 ~] # Vgdisplay
--- Volume group ---
VG Name vg_1
System ID
Format lvm2
Metadata Areas 4
Metadata Sequence No 15
VG Access read/write
VG Status resizable
Max lv 0
Cur LV 1
Open LV 1
Max PV 0
Cur PV 4
Act PV 4
VG Size 20.00 GiB
PE Size 16.00 MiB
Total PE 1280
Alloc PE/Size 960/15 .00 GiB
Free PE/Size 320/5 .00 GiB # remaining 320 PES with a capacity of 5 GB
Vg uuid NpO8m2-s4rx-WOIA-SbCt-yqQV-MU1w-wru4cS

(4) Use the lvresize command to add the PE in the newly added PV to lv_1;


[Root @ centos6 ~] # Lvresize-l + 320/dev/vg_1/lv_1
Extending logical volume lv_1 to 20.00 GiB
Logical volume lv_1 successfully resized
[Root @ centos6 ~] # Lvdisplay
--- Logical volume ---
LV Path/dev/vg_1/lv_1
LV Name lv_1
VG Name vg_1
Lvuuid n2bChT-rimu-eRDs-5onU-mgUF-ukuh-NqO7me
LV Write Access read/write
LV Creation host, time centos6.5, 19:04:37 + 0800
LV Status available
# Open 1
LV Size 20.00 GiB # check that the LV capacity has changed to 20 GB
Current LE 1280
Segments 4
Allocation inherit
Read ahead sectors auto
-Currently sets to 256
Block device 253: 0
[Root @ centos6 ~] # Df-h/mnt/lvm/
Filesystem Size Used Avail Use % Mounted on
/Dev/mapper/vg_1-lv_1 15G 166 M 14G 2%/mnt/lvm # View/mnt/lvm directory capacity is still 15G, no change
[Root @ centos6 ~] # Dumpe2fs/dev/vg_1/lv_1

(5) Use the resize2fs command to expand the LV capacity to the entire file system;


[Root @ centos6 ~] # Resize2fs/dev/vg_1/lv_1
Resize2fs 1.41.12 (17-May-2010)
Filesystem at/dev/vg_1/lv_1 is mounted on/mnt/lvm; on-line resizing required
Old desc_blocks = 1, new_desc_blocks = 2
Ming an on-line resize of/dev/vg_1/lv_1 to 5242880 (4 k) blocks.
The filesystem on/dev/vg_1/lv_1 is now 5242880 blocks long.
[Root @ centos6 ~] # Df-h/mnt/lvm/
Filesystem Size Used Avail Use % Mounted on
/Dev/mapper/vg_1-lv_1 20G 170 M 19G 1%/mnt/lvm #/mnt/lvm directory capacity has changed to 20G

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.