Linux Exercise: Logical Volume Management

Preparation

  1. If you have not done so, stop your Linux instance. In the virtualization console, make sure you assign at least two extra disks (for a total of at least three) to your instance. The two additional disks need to have a size of about 8 GB. Then start your Linux instance again.
  2. Verify with the lsblk command that you have at least two additional disks. There should not be any partitions on these disks.
    • # lsblk

Implementing LVM

  1. On the first of the additional disks, create a single partition that spans the whole disk. The partition type should be 8e (Linux LVM).
    • # fdisk /dev/sdb
      Use the "n" command to create a new partition. Use the "t" command to change the type. Use the "p" command to list your current partition table. Use the "w" command to write the partition table to disk.
  2. If necessary, run the partprobe command so that the kernel recognizes the new partition table. If partprobe doesn't work, reboot the system.
    • # partprobe
  3. Format your newly created partition as a Physical Volume. Then create a Volume Group ExtraVG using this partition. Check the VG properties such as the PE size.
    • # pvcreate /dev/sdb1
    • # pvdisplay /dev/sdb1
    • # vgcreate ExtraVG /dev/sdb1
    • # vgdisplay ExtraVG
  4. Create a Logical Volume, ExtraLV, in the ExtraVG. Make the LV 50 MB in size.
    • # lvcreate -n ExtraLV -L 50M ExtraVG
      Note that the size will be rounded up to the nearest full PE (4 MB).
  5. Format this LV with an XFS filesystem, and mount the partition on /mnt/extra. Verify that it is mounted and that the free space is about 50 MB.
    • # mkfs -t xfs /dev/ExtraVG/ExtraLV
    • # mkdir /mnt/extra
    • # mount /dev/ExtraVG/ExtraLV /mnt/extra
    • # mount
    • # df

Enlarging Logical Volumes

  1. Enlarge the size of the LV, and of the filesystem contained within, to 100 MB. Verify that the filesystem was indeed increased.
    • # lvextend -L +50M /dev/ExtraVG/ExtraLV
    • # xfs_growfs /dev/ExtraVG/ExtraLV
    • # df

Enlarging and Migrating Volume Groups

  1. Prepare your third hard disk as a PV as well. Add this PV to the VG. Then, migrate all data from the first to the second partition without unmounting the filesystem. Then, remove the first partition from the VG.
    • # fdisk /dev/sdc
      Use the "n" command to create a new partition. Use the "t" command to change the type. Use the "p" command to list your current partition table. Use the "w" command to write the partition table to disk.
    • # partprobe
    • # pvcreate /dev/sdc1
    • # vgextend ExtraVG /dev/sdc1
    • # pvmove /dev/sdb1 /dev/sdc1
    • # vgreduce ExtraVG /dev/sdb1
    • # pvremove /dev/sdb1

Determining the Default Configuration

  1. Use partitioning, LVM and filesystem commands to figure out how the default installation of your distribution uses LVM.
    • # lsblk
    • # fdisk -l /dev/sda
    • # vgdisplay
    • # vgdisplay centos
    • # vgdisplay -v centos
    • # df
    • # mount
    • # cat /proc/swaps
End of exercise