Logical Volume Management

LVM scan

List Logical Volumes

lvm lvscan

List Logical Volume Groups

lvm vgscan

LVM resize

Resize a Logical Volume swap partition. This will shrink the swap partion by 2GB.

Remember to swapoff the partition if this is a swap-partition.

lvm lvresize /dev/vg_hostname/lv_swap -L-2G

Resize a root partition.

lvresize /dev/vg_rhel64/lv_root -L+2G

Remember to resize the partition for the OS as well:

resize2fs -p /dev/vg_rhel64/lv_root

Adding a disk to a logical volume

Add (or extend the existing disk) in the environment (physical, xen/kvm/vmware) and remember to reboot the virtual machine after adding/extending the virtual disk in xen/kvm/vmware.

fdisk /dev/sda

The following may help you out a bit with fdisk.

# p to print
# n to add partition
# use p for primary
# use next available number (1-4)
# select first free cylinder - NOTE! RHEL may skip the first cylinder, so "1" is not a good choice.
# select last cylinder - enter for default (which means the last available).

# p to print
# l to list partition types
# t to change the partition type
# 3 to select the newly created partition (may differ in your setup).
# type "8e" for Linux LVM
# p to print
# w to write AND quit.

Todo: pv_ create ??

Create a new Volume Group that uses the new logical volume

sudo lvm vgcreate vg_storage /dev/sda3

Create a Logical Volume in the new Volume Group - utilizing 100% of the space!

lvm lvcreate -l 100%FREE -n lv_storage1 vg_newvol

The fdisk utility should now list the new partition fdisk -l

Create a ext4 file-system on the partition

mkfs.ext4 /dev/mapper/vg_storage-lv_storage1

Now edit /etc/fstab to set proper mount point.

… if the VG already exists

Add the physical volume by initializing with pvcreate

lvm pvcreate /dev/sda3

… and add the physical device to the logical volume group with vgextend

lvm vgextend vg_rhel64 /dev/sda3

Remember to extend the logical volume by a little less than the physical size

lvm lvextend -L+1.99G /dev/vg_rhel64/lv_root

Now refresh the OS again with resixe2fs - and your good to go!

resize2fs -p /dev/vg_rhel64/lv_root


/dev/dm-* devices

Default RHEL LVM install mount swap through the /dev/dm-1 and disk through /dev/dm-0. Use the dmsetup command to list what is what.

dmsetup ls

Author: Rói á Torkilsheyggi

Created: 2015-12-16 Wed 01:39

Emacs 24.5.1 (Org mode 8.2.10)