- Run as root
sudo su
- Create swap file
Note: set count to your RAM capacity + 2, eg 8GB RAM so count=10
dd if=/dev/zero of=/swapfile bs=1G count=10 status=progress
chmod 600 /swapfile
mkswap /swapfile
echo "/swapfile none swap sw 0 0" | tee -a /etc/fstab
mount -a
swapon -a
- Find the swap device
This will be referred to as SWAP_DEVICE later on
findmnt -no UUID -T /swapfile
- Find the swap file offset
This will be referred to as SWAP_FILE_OFFSET later on
filefrag -v /swapfile | awk '{ if($1=="0:"){print substr($4, 1, length($4)-2)} }'
- Configure GRUB
nano /etc/default/grub
On line GRUB_CMDLINE_LINUX_DEFAULT
Append in the speech marks:
resume=UUID=SWAP_DEVICE resume_offset=SWAP_FILE_OFFSET
Exit and save
Update GRUB
grub-mkconfig -o /boot/grub/grub.cfg
- Configure the initial ramdisk
nano /etc/mkinitcpio.conf
On HOOKS=(base udev ... filesystems fsck)
After filesystems add resume
Example:
HOOKS=(base udev ... filesystems resume fsck)
Exit and save
Generate initial ramdisk
mkinitcpio -P
- Reboot
shutdown now -r
I've since moved to NixOS and with this guide being 4yo my memory is a bit flaky, but:
Check if the swap has been activated
If nothing shows, activate it:
swapon /swapfileCheck the
resumeandresume_offsetparameters in/etc/default/grubmatch the correct UUID and offset for the swapfile:findmnt -no UUID -T /swapfilefilefrag -v /swapfile | awk '{ if($1=="0:"){print substr($4, 1, length($4)-2)} }'.Example config in
/etc/default/grubGRUB_CMDLINE_LINUX_DEFAULT="quiet splash resume=UUID=123e4567-e89b-12d3-a456-426614174000 resume_offset=123456"Then regenerate GRUB config:
grub-mkconfig -o /boot/grub/grub.cfg.Check that the
resumehook is correctly placed in/etc/mkinitcpio.conf(afterfilesystemsbut beforefsck):HOOKS=(base udev ... filesystems resume fsck)Regenerate the initramfs:
mkinitcpio -PMake sure to reboot afterwards and check to see if hibernation works.
Personally, I've moved to using a swap partition over a swapfile so if this doesn't work I'd recommend looking into swap partitions.