Extend root partition, Ubuntu 24.04 LTS

This applies to different scenarios but perhaps most common is a virtual machine which needs more disk space. This guide assumes you have extended the disk in your hypervisor. This guide is for non LVM, if you’re running lvm check this post instead.

Check disk by listing them with:
fdisk -l

Partition size by running:
df -h

If the new size isn’t listed/shown, we have to scan for changes:
ls /sys/class/scsi_device/

Example output could be:
2:0:0:0  3:0:0:0  32:0:0:0

The scan all devices individually:
echo 1 > /sys/class/scsi_device/2\:0\:0\:0/device/rescan
echo 1 > /sys/class/scsi_device/3\:0\:0\:0/device/rescan
echo 1 > /sys/class/scsi_device/32\:0\:0\:0/device/rescan

After that we can use cfdisk to resize the root partition.
When you run that cmd you will enter that utility, use arrows to navigate.

  • Select ex. /dev/sda3 or your device for root partition.
  • Select “Resize”.
  • Select “Write”.
  • Type “Yes”.
  • Select “Quit” to exit.

Verify the changes by running:
fdisk -l

Finally, run resize2fs to apply the changes:
resize2fs /dev/sda3

We are done. Verify free disk space with:
df -h