Extend / resize partition on Linux virtual machine

Modified on Wed, 18 Jan, 2023 at 4:03 PM

TABLE OF CONTENTS


Partition and file system changes are potentially destructive, therefore it is advised that the drives are backed up before proceeding. 


Resizing boot and regular partition are a similar process, but the boot partition cannot be extended / resized from within the OS.


If the boot partition need to be resized ...

Boot your system to systemrescue utility.


Easiest way - Gparted (graphical)

If system is booted with systemrescue utility, execute the following command in your terminal, please note that startx is a systemrescue utility and is not available under most standard linux distributions:


startx

Find gparted icon and launch the program.


Select partition you wish to resize and right click on it.


Select Resize/Move.


Drag the arrow till the end or use numeric fields.


Click Resize/Move button.


Click on 'Apply All Operations' check-mark on the top.


It's done, shutdown the machine and boot back into OS.


With fdisk (terminal)

Run the following to list/view partition tables:


sudo fdisk -l

From the output note the partition you wish to resize and unmount it:


sudo umount /dev/sdXn

Invoke the command again specifying the device this time: 


sudo fdisk -u /dev/sdX


Type p at the prompt to list the partitions on the disk - take note of 'Start' column value.


type d to delete this partition.


Type to re-create the partition.


Type p to select the partition type (primary).


Type partition number or 'ENTER' to agree with the default.


Type first sector (noted earlier) or default and 'ENTER'.


Type last sector (by default uses full space available on the disk).


Type p to list the updated partitions and verify the changes.


Type w to save the changes.


Verify that the file system has no errors:


sudo e2fsck -f /dev/sdXn

Resize the file system to use all available space on the partition:


sudo resize2fs /dev/sdXn

Mount back the partition:


sudo mount /dev/sdXn /your-mount-point # directory mast exist


Done, no system restart is required if this was done from within the OS and stop/start if systemrescue was used.



Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article