Deleting your swap - the hard way

A default clean install usually doesn't fit me. However, I've installed Ubuntu LTS just like that on this machine when both were new. It has a small but fast SSD. It has been working flawlessly until now.

I've recently reconsidered that I could use a bit more space. From experience, I never had a need for swap, as I'm using zram. So I've decided to simply delete the swap partition.

Of course, solving it simply was only my dream. Technically, you need to delete the swap partition, optionally move middle partitions to the end, expand your root file system and be done with it. I've first made whole disk backups. I've booted off a flash drive containing Ubuntu 12.10. Deleting the partition with GParted was a breeze, as well as marking the rest of the needed operations, move and resize. But there was a catch: it bailed out with a cryptic message halfway. (I think it was "GNU Parted cannot resize this partition to this size. We're working on it!")

After wasting a lot of time trying to point to any errors that I made myself, I came to understood the situation better. The default Ubuntu install seemed to have created the following partitions in GPT:
  1. sda1 root (ext4)
  2. sda2 500MB boot (ext4)
  3. sda3 50MB EFI (FAT32)
  4. sda4 8GB swap (cryptswap)
The partitions were not cleanly aligned, perhaps it defaulted to cylinder alignment for some reason. Partition sizes were not round numbers because of that either. GParted wouldn't let you touch a partition without rounding its size up to the nearest MB, while also forcing growing the enclosed file system as well. Unfortunately, it has removed support for all file system level operations on FAT32 not long ago, leaving you unable to even physically move the partition.

Again this situation sounds a bit silly, and after wasting some more time trying to use a supported solution like parted from command line and fudging, I've resorted to the following kludge:
  • deleted the swap using GParted without touching EFI
  • created a new empty partition (sda4) in the beginning of the free space that is a bit larger than sda3 (EFI) to get the kind of rounding it needs
  • dd bs=50M if=/dev/zero of=/dev/sda4
  • dd bs=50M if=/dev/sda3 of=/dev/sda4
  • deleted sda3
  • recreated sda3 at the end of the drive with the size of sda4
  • dd bs=50M if=/dev/sda4 of=/dev/sda3
  • deleted sda4
  • GParted was now happy, so I could now realign and resize both sda1 and sda2
The last step was agonizing about whether the system would boot at all, because the boot partition containing GRUB 2 was touched. I was a bit nervous because recall that the live Ubuntu was not the same version as the installed system. I've prepared all needed information just to be safe, crossed my fingers, and the boot was successful!

That's following well supported default configurations to protect against headaches for you.

Comments

Popular posts from this blog

Hidden TFTP of TP-Link routers

Tftp secret of TL-WR740N uncovered

When both Google *and* AppStatus is down