Howto – Resize linux partition and move swap space

Most of the time when you install a linux system, and when not making usage of LVM, the default parition layout will consist of something like a large main partition, and an extended partition with a swap volume on it.

If you want to extend a disk of a linux virtual machine, you will have to reconfigure your disk on the hypervisor, and afterwards, re-arrange your partition lay-out on your linux virtual machine. This howto serves as a working procdure to resize your virtual disk in the right way.

First disable your swap space.

$ swapoff /dev/sda5

Comment out the swap partition out in /etc/fstab

Now edit your partition table, delete the swap partitions:

$ fdisk /dev/sda 

#-- delete partition 5, then 2 and write changes
#-- shutdown the vm
#-- resize vm disk in hypervisor
#-- boot up the vm 

Now edit your partition table to resize your main partition, and re-create the swap partition:

$ fdisk /dev/sda 

#-- delete partition 1, and recreate it with new size leaving room for swap partition
#-- create extended partition 2
#-- create logical partition 5
#-- change type of logical partition to 82
#-- write changes
#-- reboot 

$ mkswap /dev/sda5
$ blkid /dev/sda5

#-- enter uuid in /etc/fstab
#-- enter uuid in /etc/initramfs-tools/conf.d/resume

$ update-initramfs -u
$ reboot
$ resize2fs /dev/sda1 


Published by

Ronny Van den Broeck

I'm a network and system engineer for more than 20 years now. During this period I became a pro in hunting down one's and zero's, with an eager mindset to help people accomplish the same or abstract them away from the matrix.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s