Leo's Technical Blog

Ubuntu: Changing Swap Size Without Loosing Hibernation

Introduction

user

Leo Soto


me, tips, linux

Ubuntu: Changing Swap Size Without Loosing Hibernation

Posted by Leo Soto on .
Featured

me, tips, linux

Ubuntu: Changing Swap Size Without Loosing Hibernation

Posted by Leo Soto on .

Short recipe:

After resizing your swap partition (if you resized the swap partition instead of adding another one), use vol_id -u /dev/<device-name> to get the new partion UUID, and put it at the appropriate place on /etc/fstab and /etc/initramfs-tools/conf.d/resume. Then, run:

 $ sudo dpkg-reconfigure  initramfs-tools

Now, the not so long history:

When I made the changed on my partitions to go back to Linux, I made a mistake reserving only 1Gb of space for the swap partition. It sounded like a reasonable amount as I'd have a total of 3Gb of virtual memory, enough for my typical usage.

I forgot about hibernation, which, on Linux, uses the swap partition to store the main memory contents (unlike Windows, which have a separate file for hibernation). To be honest I didn't even considered hibernation when installing Ubuntu, it never worked in the past. But now it worked. At least when I wasn't using too much main memory. If i was, then it wouldn't fit in the swap file and the laptop couldn't hibernate.

GParted came to the rescue again, and my swap partition grew to a little more than 2Gb, which is the size of my main memory. Reboot on Ubuntu again and...no swap was recognized. WTF!?

After looking at the /etc/fstab I realized that the partitions are identified by an UUID rather than by their device name. So no /dev/sda5 (my swap partition) there. Just a bunch of hexadecimal digits. I thought of wiping that mess out and go back to my familiar devices names, but googling first was a better option. Then I found that I can easily know the new UUID of the partion using:

 $ sudo vol_id -u /dev/sda5

And, what really saved me from another headache was discovering that, after a change of UUID you must update two files: the “classic” /etc/fstab and also /etc/initramfs-tools/conf.d/resume. And finally run:

 $ sudo dpkg-reconfigure  initramfs-tools

Not that straightforward as it could be, but I have no real complaints, as I now can hibernate my laptop whenever I want.