Skip to Content

Extend Linux Disk (disk space)

Published on November 12, 2024

Time to read: 4 minutes

Why extend a disk?
What is LVM Partition
Check Existing Space
Extend Partition using the Script
Extend Partition Manually

Why extend a disk?

Many of our images (primarily on openstack) do not grow their partition/file system size automatically if you choose a flavor (openstack resource definition) that allocates more disk space to your instance than was available in the original image. It is possible to use tools such as cloud-init to do this automatically. However, in our public images, which we use on multiple environments (openstack, virtualbox, vmware, etc), we find cloud-init can sometimes cause issues. Instead, we have scripts designed to resize the partitions for the user.

What is LVM Partition

Historically, many 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 partition or LVM size (using fdisk):

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 Partition 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-disk.sh. The script is found in the home directory of the student user under the extend-disk folder. NOTE:Older images may have the script called extend-lvm.sh, found in the extend-lvm folder in the student home directory

To run the script:

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

To update or download the script:

Extend Partition Manually

Here are the steps to manually extend the partition and the filesystem, including for the LVM case.

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

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!