I have asked our vcenter admin to add some disk space to one of my servers, but I can't find how to actually make it useable. My output for fdisk -l is like this:

Disk /dev/sda: 40 GiB, 42949672960 bytes, 83886080 sectors
Disk model: Virtual disk
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xc7917a47

Device     Boot    Start      End  Sectors Size Id Type
/dev/sda1  *        2048 29360127 29358080  14G 83 Linux
/dev/sda2       29362174 33552383  4190210   2G  5 Extended
/dev/sda5       29362176 33552383  4190208   2G 82 Linux swap / Solaris

The disk should've 40gb now but only 18gb is used, how would I add the rest of the space to /dev/sda1?


First off, BACK UP. This is high risk.

It appears that you have swap at the end of your system, so you need to delete this, then delete the main partition and recreate it as a bigger size with the same starting point, then grow the filesystem and handle swap.

Step 1 - disable swap

"swapoff -a" should unmount your swap. Then comment swap out of /etc/fstab

Step 2 - rejig partition.

In fdisk /dev/SDA -

Delete /dev/sda5 and then /dev/sda2.

Take careful note of /dev/sda1, then delete it and recreate it with the same starting position, but taking up all available disk. Ensure the new partition is toggled to be bootable and of type 83.

Reboot the VM and prey to $deity that it starts. If not, recover from backup or fluff around with testdisk.

Once the system restarts you can then fix things up to use the new space (as root) -

  1. Grow the disk using a command like resize2fs /dev/sda1. (Might be resize4fs /dev/sda1 depending on distro). - this will expand the filesystem so the new disk is usable.

  2. Add swap.

Create a file on the disk to use as swap - with a command like truncate -s M 2000 /swap.file

Format the file with mkswap /swap.file Re-add swap by modifying /etc/fstab to have /swap.file as the source dusk for swap. Add swap to running instance with" swapon -a"

  • Thank you. I will try this once I back up everything. – Ser Nov 6 '19 at 18:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.