version 1.0.0, 2014-07-05 : Initial version
LVM management commands on RedHat based distributions
These are various LVM-related commands you can find on a RedHat based Linux distribution.1. Raw commands
-
pvs
→ Displays physical volumes -
vgs
→ Displays volume groups -
lvs
→ Displays logical volumes
-
pvdisplay
→ Displays detailed informations on PV -
vgdisplay
→ Displays detailed informations on VG -
lvdisplay
→ Displays detailed informations on LV
-
pvcreate
→ Initializes a disk or partition for use by LVM -
vgcreate
→ Creates a VG -
lvcreate
→ Creates a LV inside a VG
-
vgextend
→ Adds one or more PV to an existing VG -
vgreduce
→ Removes one or mode PV to an existing VG -
lvextend
→ Increases the size of an existing LV -
lvresize
→ Changes the size of an existing LV -
lvreduce
→ Reduces the size of an existing LV
-
pvremove
→ Removes LVM labels from a PV -
vgremove
→ Removes a VG definition -
lvremove
→ Removes a LV definition
-
pvchange
-
vgchange
-
lvchange
-
lvrename
→ renames a LV -
pvmove
→ Migrates data from one PV to another
2. Real life cases
2.1. Creating a new VG
Here we are creating a VG called vg_test and containing a 3GB LV named lv_test on the sdb disk.
# PV initialisation and verification pvcreate /dev/sdb pvdisplay /dev/sdb # VG creation and verification vgcreate vg_test /dev/sdb vgdisplay -v vg_test # LV creation and check lvcreate -L 3G -n lv_test vg_test vgdisplay -v vg_test lvdisplay vg_test/lv_test # Then create your FS as usual mkfs -t ext4 /dev/vg_test/lv_test # Mount it and update fstab mkdir /media/test_fs mount /dev/vg_test/lv_test /media/test_fs echo -e "$(blkid /dev/mapper/vgtest-lvtest | cut -d" " -f2) \t /media/test_fs \t ext4 \t defaults \t 1 \t 1" >> /etc/fstab
2.2. Removing PV from a VG
For mode fun, let’s consider that a LV named VolGroup/lv_root containing / has been allocated to 2 disks (/dev/sda and /dev/sdb) and that you want to remove one of the PV (/dev/sdb).
1st things first, as it is a root partition, you should boot on e CD in rescue mode but don’t mount the current system in /mnt/sysimage.
# Then activate all known volumes in the system if not automatically done with vgchange -a y # Then check the unmounted LV e2fsck -f /dev/VolGroup/lv_root # Then resize the FS to the minimum size possible resize2fs -M /dev/VolGroup/lv_root # Then reduce the LV lvreduce -r -L 5G VolGroup/lv_root # The mode the data from /dev/sdb1 to /dev/sda2 pvmode /dev/sdb1 /dev/sda2 # Then remove the PV from the VG vgreduce VolGroup /dev/sdb1 # Then extend the LV and FS of the max available extents lvextend -r -l +100%FREE VolGroup/lv_root
Then reboot, removing the rescue CD.
-r
option of lvreduce
to resize both the FS and the LV
together. This will call resize2fs automatically.