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.
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
The disk is now ok and we can move onto resizing the partition. Start utility:parted
- Type “print” and enter. This lists the partitions.
- Type “resizepart” and enter. It asks you for the partition number, in my ex. “3” and enter.
- Type “quit” and enter.
Next, resize the physical volume:pvresize /dev/sda3
Now, extend the logical volume (remember to edit to match your system):lvextend -l +100%FREE /dev/mapper/ubuntu--vg-ubuntu--lv
Finally, run resize2fs to apply the changes:resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv
We are done. Verify free disk space with:df -h