What is LVM Partition
Check Existing Space
Extend LVM using the script
Extend LVM manually

What is LVM Partition

Most of our standard images for OpenStack and VirtualBox virtual machines use LVM (Linux Logical Volume Manager) to provide the disk volume for the operating system, as well as additional storage volumes (if applicable). LVM makes it easy to resize and re-purpose space within Linux, usually without even requiring a reboot.

You can learn more about LVM here: LVM – UbuntuLVM is available for most Linux distros.

Check Existing Space

Before you can enlarge the disk, first you have to check to see if it is possible:

Check physical disk size versus the LVM size (using fdisk):

  • Run fdisk, to see if there is more space available that could be added to the LVM:
    sudo fdisk -l
  • In most of our basic images, this should show just a single physical device, such as:
    Disk /dev/vda: 32 GiB, 34359738368 bytes, 67108864 sectors32 GB physical disk
  • It will also show the partition being used for the LVM:
    Device Boot Start End Sectors Size Id Type
    /dev/vda1 2048 16777215 16775168 8G 8e Linux LVM

    In this case it is an 8 GB partition (/dev/vda1)
  • And finally it will also show the LVM itself:
    Disk /dev/mapper/COMPbase--vg-root: 8 GiB, 8585740288 bytes, 16769024 sectors

So, in this case, the Physical disk is 32 GB, but only 8 GB are currently allocated to the LVM, and no other partitions are using the rest of the space for anything else. So we can extend it!

Extend LVM using the script

If you are using one of our standard SCS images, either for OpenStack or for VirtualBox virtual machines, it usually comes with a small script called extend-lvm.sh. The script is found in the home directory of the student user under the extend-lvm folder. Older images may have it just in the student home directory itself rather than in a sub-folder.

To run the script:

  • Open a terminal
  • Go to the directory with the script, usually: cd ~student/extend-lvm/
  • Enter: sudo ./extend-lvm.sh /dev/vdaNOTE: the /dev/vda may be different on your system. It is the device you found in Check Existing Space above

That’s it! Now when you run fdisk, you should see the LVM partition is the full size of the physical disk: sudo fdisk -l

To update or download the script:

  • If you do not have the script, you can get it using git:
    git clone https://git.scs.carleton.ca/git/extend-lvm.git
  • If you have the script and it was pulled from the git repository, then you can pull updates:
    cd extend-lvm go into the extend-lvm git folder
    git pull to pull the updates
    NOTE: If you are unsure if it was pulled from the git repository, then check if there is a .git hidden folder in the extend-lvm folder (check for hidden folders with ls -la); If not, then you need to clone the repository using the git clone command above.

Extend LVM manually

Here are the steps to manually extend the LVM.

NOTE: We assume the same setup as the above Check Existing Space

  • Extend the physical drive partition:
    • sudo fdisk /dev/vdaEnter the fdisk tool to modify /dev/vda
      NOTE: End each one letter command by pressing [Enter]; if the instructions do not specify a specific response to a question, just press [Enter] to accept the default
    • pp command prints the disk info, same as running fdisk -l /dev/vda
    • dd command delete the last partition (in this case, /dev/vda1)
    • n e n command creates a new partition; e makes that an extended partition
    • tt changes the type of partition
      8eEnter 8e (lvm) as the partition type
      NOTE: In some cases, the disk uses GPT signature rather than DOS. In that case, use the 31 (lvm) as the partition type
    • ww writes the changes to disk and exits fdisk
  • Modify (extend) the LVM:
    • Tell LVM the physical partition size has changed: sudo pvresize /dev/vda1
    • Find the actual path of the LVM logical volume: sudo lvdisplayThe LV Path is the value needed
    • Tell LVM to extend the logical volume to use all of the new partition size: sudo lvextend -l +100%FREE /dev/COMPbase-vg/root Using the LV Path from above
  • Resize the file system:
    sudo resize2fs /dev/COMPbase-vg/root

That’s it! Now, when you run sudo fdisk -l, it will show that the LVM is using all of the space on the physical disk!