Resize Linux Partition

My Linux partition was running low on disk space. A look in the Disk Utility showed that there were THREE swap partitions. They must have been created automatically when a free chunk of space was selected during a few installations.

I noticed that I could extend the partition if I deleted the extra swap partitions and moved the one in use over.

Which swap to delete?

The command cat /etc/fstab shows the partitions used during the install.

I simply used the Disk Utility to delete the other two swap partitions.

Moving the swap partition

It is only possible to move and resize partitions when they are not mounted. Use a Live USB stick to boot to Ubuntu and run the GParted Partition Editor.

To move the swap partition, it is necessary to unmount it first. Right click on it and select “Swapoff”. It is then possible to move it over to the free space area by using the “resize/move” command. Simply copy the value of “Space after” to “Space preceding”. GParted will automatically figure out that the swap partition is to be shifted.

Extend the Linux partition

Right click on the Linux partition and extend its size to take up all the free space.

Apply the changes by clicking on the green check mark in the toolbar.

Uh oh, the computer can’t boot!!

Rebooting after the changes were made resulted in a command prompt which just said “grub restore>”. Not good.

I booted back to the Live USB stick and googled around for instructions on how to reinstall the bootloader.

Unfortunately, the standard way of
sudo grub-install /dev/sda
did not work. It failed with an error message asking if the device is mounted.

I found some instructions at askubuntu.com. Basically I had to mount the partition to a mount point, then run
sudo grub-install --boot-directory=/mnt/boot /dev/sda
where /mnt is the location I mounted the Linux partition to.

That worked with no errors and after restarting, good ol’ grub comes up.

About these ads

Leave a Reply

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

WordPress.com Logo

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

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s