Series of the tutorial to learn LVM commands. In this part, learn how to extend, reduce and change the state of the logical volume (lvextend, lvreduce, lvchange)
In continuation of last part of a logical volume, we will be seeing more commands on lvol in this post. Previous posts of this LVM command tutorial can be found on below links :
- Part 1 : Physical Volume (pvcreate, pvdisplay)
- Part 1 : Physical Volume (pvchange, pvmove)
- Part 2 : Volume group (vgcreate, vgdisplay, vgscan)
- Part 2 : Volume group (vgextend, vgreduce, vgexport, vgimport)
- Part 2 : Volume group (vgcfgbackup, vgcfgrestore, vgchange)
- Part 2 : Volume group (vgremove, vgsync)
- Part 3 : Logical Volume (lvcreate, lvdisplay, lvremove)
- Part 3 : Logical Volume (lvsync, lvlnboot)
Logical volumes like VG can be extended and shrank. We will be seeing
lvchangecommands in this post.
To extend logical volume, you should have enough free space within that VG. Command syntax is pretty much similar to
lvcreate command for size. The only thing is you need to supply the final required size in command. For example, the current LV size is 1GB and you want to extend it with 2GB. Then you need to give the final 3GB size in the command argument.
# lvextend -L 3072 /dev/vg01/lvol1 Logical volume "/dev/vg01/lvol1" has been successfully extended. Volume Group configuration for /dev/vg01 has been saved in /etc/lvmconf/vg01.conf
Another important option is of mirror copies. It plays a vital role in root disk mirroring.
-m is the option with the number of mirror copies as an argument.
# lvextend -m 1 /dev/vg00/lvol1 /dev/disk/disk2_p2 The newly allocated mirrors are now being synchronized. This operation will take some time. Please wait .... Logical volume "/dev/vg00/lvol1" has been successfully extended. Volume Group configuration for /dev/vg00 has been saved in /etc/lvmconf/vg00.conf
This command used for decreasing the number of mirror copies or decreasing the size of LV. This is the data destroying command. Hence make sure you have data of related file system backed up first. The size and mirror copy options are works the same for this command as well.
-L for LE_reduce_size,
-l number of LE to be reduced and
-m is the number of copies to be reduced.
# lvreduce -L 500 /dev/vg01/lvol1 When a logical colume is reduced useful data might get lost; do you really want the command to proceed (y/n) : y Logical volume "/dev/vg01/lvol1" has been successfully reduced. Volume Group configuration for /dev/vg01 has been saved in /etc/lvmconf/vg01.conf
While reducing mirror copies if one of the PV is failed or missing then command won’t run successfully. you need to supply
-k option which will proceed to remove the mirror in case PV is missing.
This command is used for changing the characteristics of LV. There are numerous options that can be used.
- -a y/n Activate or deactivate LV
- -C y/n Change contiguous allocation policy
- -D y/n Change distributed allocation policy
- -p w/r Set permission
- -t timeout Set timeout in seconds
- -M y/n Change mirror write cache flag
- -d p/s Change scheduling policy
This is the end of the second post on LV commands. In the next post, we will see