Ubuntu – How to redetect swap partition after formating to enable hibernation

boothibernatepartitioningswapuuid

I had this setup working on my laptop:

/dev/sda1 (ext4) /
/dev/sda2 (ext4) /home
/dev/sda3 swap partition
/dev/sda4 (ntfs) /media/windows

After getting sick of windows, I removed the last partition. Since swap was in the middle, I removed sda3 too and used the space to expand /home so I had to rebuild the swap partition at the end. Now the setup is this:

/dev/sda1 (ext4) /
/dev/sda2 (ext4) /home
/dev/sda3 swap partition

The swap partition works perfectly, it's mounted on boot or manually with swapon an unmounted with swapoff. By the way, I have removed it from /etc/fstab since the laptop has 4GB of RAM and I never use the swap while the system is running. I wrote a little script that mounts the partition before hibernating and unmounts it when the system is recovered from hibernation.The problem is now when I hibernate and boot the system, the boot process doesn't look for data on it. My guess after some tests is that the system doesn't "trust" this new partition and doesn't check for data on it. I guess the UUID has changed?

The weird thing is, if I manually mount the partition with "sudo swapon /dev/sda3" and then I hibernate the system, the data get saved. I know this because when I'm back on the desktop and remount the partition manually, the swapon utility complains that "there's data on this filesystem, cleaning up" (not this exact message, I don't have the laptop right now with me).

Is there a way to force the redetection of this partition as the default hibernation file to look on boot?

EDIT: I just realized that I made a mistake when I rearanged the file system: I gave it only 2 GB instead of 4… So, the partition is not big enough for the 4 RAM in the system. Shouldn't it be still able to hibernate if the memory in use was only 500 MB, which is the case? Or would I need to resize it? If so, can I resize the sda3 partition to make it 2GB smaller? The enlarging process was quite straight forward but I'm not sure if shrink a partition is more dangerous, because involves moving some physical data.

Best Answer

  • Yep, it must be greater or equal RAM size (let it strictly greater).

  • Partition shrinking needs to move some data blocks. It's up to you to backup or to take the risk. However, 2GB is considered a short time operation, if it is taken from the end of partition (ie sda2). If it was from the beginning of a large partition (example: sda4), my advice forget it.

  • To fix the hibernation

    1. Get the new UUID

      sudo blkid
      
    2. Update the resume configuration file with the correct UUID

      gksu gedit /etc/initramfs-tools/conf.d/resume
      
    3. Update RAMDisk

      sudo update-initramfs -u
      
    4. Reboot

    Reference: Community Wiki: Swap FAQ