6

Why don't I have a resume file in the path: /etc/initramfs-tools/conf.d? Shouldn't there be in this path?

I'm using Ubuntu 20.04 and while installation I created a swap partition (instead of swapfile) that is regularly in use, in fact the output of swapon -s is:

Filename                Type        Size    Used    Priority
/dev/sdb5                               partition   9765884 0   -2

N.B.: Actually I'm looking for this file because I want to migrate from swap partition to a swapfile, and for this purpose I found some simple instructions which, at the end, also suggest to edit this "resume" file (that I don't have)!

1
  • 1
    You'll have one if you hibernate your system, otherwise you don't have one. It doesn't relate to the swapfile/swap-partition change; it's created when you hibernate a system indicating the system should resume rather than cold-boot. wiki.ubuntu.com/DebuggingKernelHibernate – guiverc Dec 4 '20 at 8:25
4

You'll have one only after you hibernate your system (instead of shutting down), otherwise you don't have one.

Not having one is normal (if you watch the boot messages, you'll note an error with it not being found which leads to the normal cold boot). The file's presence tells the system it was hibernated and a resume is required (instead of cold-boot).

It doesn't relate to the swapfile/swap-partition change

https://wiki.ubuntu.com/DebuggingKernelHibernate

6

Swap Partition to Swapfile with Hibernation in 20.04:

Increase swapfile size to match RAM size up to 8GB.

  • Check the swap that is in use:

    sudo swapon -s

  • If swap partition(s) found:

    sudo swapoff -a

    sudo nano -Bw /etc/fstab

  • In /etc/fstab add "# " before the UUID of the swap partition(s):

    # UUID=XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX none swap sw 0 0

  • Add a line for the swapfile, if one does not exist:

    swapfile none swap sw 0 0

  • Create the swap file:

    sudo fallocate -l XG /swapfile*

Where X is the swapfile size in GB

    sudo mkswap /swapfile

    sudo chown 0600 /swapfile

    sudo swapon /swapfile
  • Reboot:

    sudo reboot

Setup Hibernation (Optional)

Add resume location and offset to grub.cfg:

  • Edit /etc/default/grub:

GRUB_CMDLINE_LINUX_DEFAULT="quiet splash resume=UUID=XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX resume_offset=XXXXX"

  • Use UUID from root.

  • Use offset from sudo filefrag -v /swapfile |grep " 0:"| awk '{print $4}'

  • Update GRUB sudo update-grub

  • Test hibernation sudo systemctl hibernate

A hibernate button can be added using gnome extensions.

*There is a slight possibility of getting holes in a swapfile when creating it with fallocate. /var/log/syslog can be searched for the phrase swapon: swapfile has holes to ensure there will be no data loss.

A swapfile can alternatively be created using dd: sudo dd if=/dev/zero of=/swapfile bs=1G count=8 Caution: An error when using dd may overwrite your HDD

4
  • Actually, I'm not interested in possibility of hibernating system but only in switch from swap partition to swapfile. So if I follow your instructions can I stop at "Reboot" step (without edit grub.cfg)? thanks – holdtheline Dec 4 '20 at 9:42
  • Yes, no need for hibernation if, like me, you never use it. – C.S.Cameron Dec 4 '20 at 9:58
  • After migrating from swap partion to a swapfile, can I remove swap partition and assign the space left blank to another partition? – holdtheline Dec 4 '20 at 12:18
  • 1
    @holdtheline: Yes you can, "#" the line out in /etc/fstab, or just delete it. I was not clear above and have made a small edit. – C.S.Cameron Dec 4 '20 at 13:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.