Create a new Logical Volume
The following command creates new logical volume made up with
- 5 Gbyte in size
- striped over 3 disks
- block size is 64K
- called lv_root2
- volume group vg01.
sudo lvcreate -L5G -i3 -I64 -n lv_root2 vg01
All that is left is to put the file system on the new stripped partition.
sudo mkfs.ext4 /dev/vg01/lv_root2
You can check all was created as expected with the following:
sudo lvs -o +stripes
Enlarging a Logical Volume
First display the names of the logical volumes, so you know the name of the logical volume you are going to extend.
sudo lvdisplay
Te command above will tell you, if you named your lvm disks with a little for thought, which volume group the logical volume is in. Use the command below to find the VG and see how much free space is still left unallocated.
sudo vgdisplay
Extending LVM
To extend a lvm by adding a further say 40Gb
sudo lvextend -L+40G /dev/vg01/lv_data
and then resize the file system.
sudo resize2fs /dev/vg01/lv_data
You can now check that the extension has taken correctly by using lvdisplay and finally using the disk free command
df -h /dev/mapper/vg01-lv_data
Filesystem Size Used Avail Use% Mounted on /dev/mapper/vg01-lv_data 220G 172G 50G 78% /backup
Shrinking LVM
To reduce a lvm logical volume from say 100G to 60G by removing 40Gb, we need to unmount the partuition, check the fs and then shrink the fs partition, FIRST make a backup!
sudo umount /data
e2fsck -f /dev/mapper/vg01-lv_data
resize2fs /dev/mapper/vg01-lv_data 60G
The resize2fs takes ages on a big hard dive. Time for a coffee followed by lunch 🙂
resize the LVM volume.
sudo lvreduce -L60G /dev/vg01/lv_data
we can now remount the fs and have a look to see what is left.
sudo mount /dev/vg01/lv_data /data
df -h /dev/mapper/vg01-lv_data
Remove a Logical Volume
sudo lvremove /dev/vg0/lv_root2