Basic guide to manage LVM
With LVM we can manage our partition of a easy and flexible way. For this guide I’ll use three disk of 340 GB, 90 GB and 160 GB. With this basic guide We’ll create a simple group, add or remove partitions from a group and extend or reduce the size of a LVM device.

Create a simple LVM disk
1.- Partition the disk with fdisk with the type of partition LVM (8e) :

2.- Initialize the partitions with pvcreate:
3.- Create an LVM group containing the partitions:
4.- Use the command vgdisplay to see our LVM groups configured in our system:

5.- Create the LVM device:
6.- Use the command line lvdisplay to see our disk:

7.- Create the filesystem in our logical volume device:
Add a new disk to our Volume group
1.- Extend our Volume group adding the new partition:
2.- Execute vgdisplay to see the new changes:

Extend the size of a LVM
1.- Extend the volume size:
2.- Apply the extension to the xfs filesystem:
3.- Test the changes:

Reduce the size of a LVM
1.- reducing the size
**Note with xfs filesystem It’s not posible shrink the filesystem, you have to back up your files before the resize and format the volume. With ext2/3 the utility resize2fs or resize4fs for ext4, also with reiserfs you can use resize_reiserfs.
2.- Format the partition and see the changes:

Hot remove disk from a volume group
I’ll remove the disk 1 (/dev/sdb1) from the volume group mygrp. Firs we have to move the content of /dev/sdb1 to another partition equal or greater than the size of this partition. For this I’ll add another partition of 400GB to the volume group mygrp:


1.- First we have to move the content of /dev/sdb1 to the new partition /dev/sde1:
2.- Remove /dev/sdb1 from the volume group:
3.- Now we can remove the device:
4.- see the changes:
- Install LVM support package:
# apt-get install lvm2 |
1.- Partition the disk with fdisk with the type of partition LVM (8e) :
2.- Initialize the partitions with pvcreate:
# pvcreate /dev/sdb1Physical volume "/dev/sdb1" successfully created# pvcreate /dev/sdc1Physical volume "/dev/sdc1" successfully created# pvcreate /dev/sdd1Physical volume "/dev/sdd1" successfully created |
# vgcreate mygrp /dev/sdb1 /dev/sdd1Volume group "mygrp" successfully created |
4.- Use the command vgdisplay to see our LVM groups configured in our system:
5.- Create the LVM device:
# lvcreate -L 350G -n disk1 mygrpLogical volume "disk1" created |
7.- Create the filesystem in our logical volume device:
# mkfs.xfs /dev/mygrp/disk1# mount -t xfs /dev/mygrp/disk1 /mnt/disk1/ |
Add a new disk to our Volume group
1.- Extend our Volume group adding the new partition:
# vgextend mygrp /dev/sdc1Volume group "mygrp" successfully extended |
2.- Execute vgdisplay to see the new changes:
Extend the size of a LVM
1.- Extend the volume size:
# lvextend -L +10G /dev/mygrp/disk1Extending logical volume disk1 to 360.00 GiBLogical volume disk1 successfully resized |
# xfs_growfs /dev/mygrp/disk1meta-data=/dev/mapper/mygrp-disk1 isize=256 agcount=4, agsize=22937600 blks= sectsz=512 attr=2data = bsize=4096 blocks=91750400, imaxpct=25= sunit=0 swidth=0 blksnaming =version 2 bsize=4096 ascii-ci=0log =internal bsize=4096 blocks=44800, version=2= sectsz=512 sunit=0 blks, lazy-count=1realtime =none extsz=4096 blocks=0, rtextents=0data blocks changed from 91750400 to 94371840 |
3.- Test the changes:
Reduce the size of a LVM
1.- reducing the size
# lvreduce -L -190G /dev/mygrp/disk1WARNING: Reducing active and open logical volume to 130.00 GiBTHIS MAY DESTROY YOUR DATA (filesystem etc.)Do you really want to reduce disk1? [y/n]: yReducing logical volume disk1 to 130.00 GiBLogical volume disk1 successfully resized |
**Note with xfs filesystem It’s not posible shrink the filesystem, you have to back up your files before the resize and format the volume. With ext2/3 the utility resize2fs or resize4fs for ext4, also with reiserfs you can use resize_reiserfs.
2.- Format the partition and see the changes:
# mkfs.xfs -f /dev/mygrp/disk1 |
Hot remove disk from a volume group
I’ll remove the disk 1 (/dev/sdb1) from the volume group mygrp. Firs we have to move the content of /dev/sdb1 to another partition equal or greater than the size of this partition. For this I’ll add another partition of 400GB to the volume group mygrp:
1.- First we have to move the content of /dev/sdb1 to the new partition /dev/sde1:
# pvmove /dev/sdb1 /dev/sde1/dev/sdb1: Moved: 9.6%/dev/sdb1: Moved: 17.2%/dev/sdb1: Moved: 24.8%/dev/sdb1: Moved: 33.5%/dev/sdb1: Moved: 40.1%/dev/sdb1: Moved: 54.2%/dev/sdb1: Moved: 68.3%/dev/sdb1: Moved: 75.9%/dev/sdb1: Moved: 81.3%/dev/sdb1: Moved: 93.3%/dev/sdb1: Moved: 100.0% |
# vgreduce mygrp /dev/sdb1Removed "/dev/sdb1" from volume group "mygrp" |
# pvremove /dev/sdb1Labels on physical volume "/dev/sdb1" successfully wiped |
Nhận xét
Đăng nhận xét