How to Expand a Boot Partition

What do you do when you have a boot partition that is too small? This is the exact problem I tried to solve in my home lab. Read on to learn more!

Background

I had an Ubuntu VM that I had been upgrading since at least 10.04. This VM started its life with a 200MB /boot partition. Since then, multiple other partitions have been adding to the same drive as the /boot partition and these additional partitions were joined together as a LVM. In addition to the growth of the disk space, I have also enabled the automatic upgrade of the kernel.

While 200MB may have been enough room for /boot back in the day, it is no longer enough and I find myself with a full /boot partition all the time. In order to work around this issue, I need to manually cleanup older kernel packages, force an install to get out of the interim state and then run autoremove to clean up space. The process looks something like this:

Needless to say, this process is tedious, error prune even when automated, and runs the risk of causes major issues to my VM (e.g. not being able to boot). I needed to expand the /boot partition, the question was how?

Options

In order to resize or move partitions, you need to boot a live CD. I went ahead and downloaded gparted, copied the ISO to the VMs datastore, mounted and connected the ISO and then shutdown my VM. Of course, I created a snapshot as the changes I was about to make ran the risk of causing major issues. Next, I edited the settings on the VM and adding an additional 1GB of disk space to the existing virtual disk. I then powered on the VM.

I had a variety of options to fix my /boot partition including:

  • Attempt to expand the existing /boot partition — this would require moving all the other partitions that had been created
  • Attempt to create a new /boot partition and dd the data over — all my primary partitions were used and attempting to reconfigure grub did not sound like fun.
  • Give up and just deal with the existing problem — I am not quitter!

Expanding Partition

Since expanding the existing partition seemed like the best option, I decided to try it. In theory, you need to move each partition from left to right going from bottom to top:

The first problem I experienced was that I could not move the bottom partition (/dev/sda4). You will notice a lock icon next to it and others above it. To resolve this, right-click the last partition and select the Deactivate option. Now when you select the partition you can move it. I took all the space available after the partition (1024MB) and entered it into the value before the partition (which was 0). I repeated this exercise for the second to last partition (/dev/sda3). After this I hit the Apply button and waited about 15 minutes will the operation completed. Note, you will need to select the Ignore option each time it pops up (about four times if I recall correctly).

The next partition (/dev/sda2) is interesting because it is an extended partition. This mean you need to grow the extended partition first, move the containing partition to the right from bottom to top, and then shrink the extended partition back to its original size. It is worth noting that I hit an interesting issue when attempting to perform these operations — I received an error from┬álibparted messages: cannot have overlapping partitions. The solution was to change the alignment drop-down option under the Resize/Move option from the default of Mb to none. Again, you will need to select the Ignore option for every pop-up. Now you can finally expand the boot partition (/dev/sda1). You will notice when I was done I ended up with a 1 MiB unallocated within the extended partition — this is likely because of a pre-existing alignment issue with the drive layout.

With all the operations completed, I shut down the VM, disconnected the ISO, and powered on the VM. To my delight, the VM powered on successfully and the boot partition had been extended!

© 2017, Steve Flanders. All rights reserved.

2 thoughts on “How to Expand a Boot Partition

  1. I would have added a second disk and copied my boot partition over there. Then update grub and fstab. At that point you could recreate all of your partitions if you wanted to.

Leave a Reply