RSS Amplifier

Nathan Ellison · Jan 16, 2026

VM Resize with GParted

0
Sign in to vote or save

Nathan Ellison

I ran into an interesting issue with one of my virtual machines recently. I was playing a Hack The Box challenge and wanted to spin up a local version of the vulnerable app inside my virtual machine using Docker. I ran the script that retrieved the required packages and… used all of the available disk space in my VM. “Not to worry, I’ll just shut it down, increase the disk size and start it back up again”.

I increased the disk size using the hypervisor and attempted to boot the VM again. It wouldn’t boot. The startup process would begin but then it would just hang on a black screen. After doing a bit of googling, I found that even though I had increased the disk size available to the VM, the partition which contained the operating system remained the same size. This was a problem since I couldn’t boot into the VM to change the partition size from within the guest OS so that it could use the newly added disk space.

GParted is a handy utility that provides a graphical interface for managing and editing disk partitions.

For my use case, it allowed me to edit my overloaded VM’s partitions without needing to boot into the VM itself. GParted runs as a bootable USB, so actually being able to get into the VM wasn’t required (luckily).

Boot into GParted Live

To fix up my VM, I inserted the GParted ISO file to the virtual optical drive, started up the machine, and booted into the GParted Live interface (accepting all of the default options). This showed all of the partitions on the disk.

gparted live interface

The space that I had recently allocated to the machine using the hypervisor was denoted by the partition labelled unallocated and the current partition with the OS on it was labelled /dev/sda1.

GParted requires the unallocated partition and the partition that is being resized be adjacent to each other. This meant that I had to delete the swap partition in order to increase the size of the /dev/sda1 partition. Once the swap partition was out of the way, /dev/sda1 could be resized.

What is a Swap Partition?

A swap (either a swap file or swap partition) is a storage location that the operating system uses to temporarily store things when the RAM fills up. This allows more programs to run and helps prevent everything from crashing when there is no more RAM available.

Addressing the Swap Partition

Running an OS without a swap location can be a little risky, so I recreated it by decreasing the newly expanded partition (/dev/sda1) by 6GB.

unallocated swap partition

Using the unallocated space, I created a new extended partition and then created a Linux swap partition inside that.

new partitions ready for writing

After writing all of the changes to disk, all that was left to do was enable the swap by right clicking the swap partition and selecting Swapon.

enabling the swap in gparted

Once everything was configured, GParted could be closed and the VM rebooted.

Reboot VM and Check

There were a few extra steps required after fiddling around with the partitions.

  1. I used the swapon command to check that the swap partition was enabled properly.
swapon --show

NAME      TYPE      SIZE USED PRIO
/dev/sda5 partition 6.1G   0B   -2
  1. Check that the disk (and primary partition) size had been successfully increased. Using lsblk showed that the resize was successful.
lsblk

NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTS
sda      8:0    0  101G  0 disk
├─sda1   8:1    0 94.9G  0 part /
├─sda2   8:2    0    1K  0 part
└─sda5   8:5    0  6.1G  0 part [SWAP]
  1. The new swap partition was assigned a UUID which needed to be added to /etc/fstab. The UUID could be retrieved using the following command:
blkid

/dev/sda5: UUID="{UUID-HERE}" TYPE="swap" PARTUUID="{PART-UUID-HERE}"

Tldr;

Give your VMs enough disk space when you create them.

Read the original on nathan-ellison.com

Comments

Nothing yet. Say the first thing.

    Sign in to join the conversation.