Boot Partition Isn’t Big Enough Anymore…

I’ve had some of my OpenSuse servers for a loooong time, through a lot of upgrades.  When they were originally built, a 150 MB /boot partition was plenty large… but it sure isn’t anymore.  In fact, if you analyze it and try to modify it with Yast, it tells you as much, and won’t let you make it too small.  Which would be fine if I were building new, but now I’m trying to modify my partitions just to give me breathing room, and as a result, Yast won’t help me because I’m not giving enough.

The premise is this:  On a few servers, I have the following partition setup from the old days:

  • /boot = /dev/sda1 = 150 MB
  • swap = /dev/sda2 = 550 MB
  • / = /dev/sda3 = 10 (or more) GB

But the problem is that the /boot slice can’t be extended with that swap partition in the way (because it must be contiguous)…  So let’s move it around!  I’m going to do a “shell game” by creating some space a the end, relocate swap to the new end place, and and push the /boot into the space vacated by the old swap location.  The only real tricks here are that, like I mentioned, Yast won’t help me because the size is too small (go ahead and try it yourself), and resizing the boot can be tricky, so I’m going to use gparted-live, because it’s so doggone easy.  Let’s get to it!

First, download gparted.  Put the ISO somewhere where you can mount it to your VM cdrom drive.  I useded gparted-live-1.2.0-1-amd64.iso

Make a full export of the VM.  I’m using Hyper-V in this scenario, so I use the built-in export feature to have a standby copy in case I mess it up.  And, I like to make sure there’s no snapshots before making an export, so it is clean.

Add space by extending the disk.  In Hyper-V, for a gen1 VM, you shut down the VM, edit the virtual hard disk in the settings, and add like a GB or something.  Remember, in my case, whatever I add is only going to be used by swap, so the minimum 1 GB is fine.

Now swap the swap.  Now boot up, and let’s shut down the existing swap:

swapoff /dev/sda2

…and make a new one:

fdisk /dev/sda

(follow the steps to create a swap partition: p to print tables, n to add new partition in empty space, in my case p for primary, default partition 4, default size, t to change type, 4 to select, set to type 82 (swap), and w to write to the disk.)

…now, create the swap and turn it on:

mkswap /dev/sda4

swapon /dev/sda4

…and of course edit your fstab to change the swap entry from sda2 to sda4:

vi /etc/fstab

init 6

At this point you just want to make sure that the system boots up with the new swap without any problems.  So reboot and as long as it boots okay, we now know we have a good new swap space, and the old swap to kick to the curb.

Next, shut down the VM, attach the gparted-live CD, and boot into it.  Just hit enter on the default options (3 times) until you are in the GUI tool.  Next, we want to select and delete the old /dev/sda2 swap partition, and select & “Resize/Move” (expand) the /dev/sda1 partition (by dragging the end boundary in the GUI) to fill the space.  Click Apply, Quit, Exit.

Then, reboot and everything should be fine.

Leave a Comment

Your email address will not be published. Required fields are marked *