Skip to content

Instantly share code, notes, and snippets.

@Aikufurr
Created November 17, 2021 19:07
Show Gist options
  • Save Aikufurr/00daae657631e2c9d9506f38734696a0 to your computer and use it in GitHub Desktop.
Save Aikufurr/00daae657631e2c9d9506f38734696a0 to your computer and use it in GitHub Desktop.
How to add hibernation to Arch Linux using a swapfile
  1. Run as root
sudo su

  1. 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

  1. Find the swap device

This will be referred to as SWAP_DEVICE later on

findmnt -no UUID -T /swapfile

  1. 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)} }'

  1. 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

  1. 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

  1. Reboot
shutdown now -r
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment