Follow these steps to enable swap and hibernation on Arch Linux.
First, check your current RAM and swap usage to ensure the swap file is large enough to store the contents of your RAM:
free -h
If your swap file size doesn't match your RAM size, you'll need to create one.
While you can use a swap partition, using a swap file is easier. To create a swap file, run the following commands:
sudo fallocate -l <size> /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
Replace <size> with the size of your RAM (e.g., 8G for 8 GB).
To make sure your swap file is enabled on boot, add it to /etc/fstab by running:
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab
Create or modify the file /etc/systemd/system.conf.d/hibernate.conf and add the following configuration:
[Sleep]
HibernateMode=platform
HibernateDelaySec=0Edit /etc/mkinitcpio.conf to add the resume hook:
HOOKS=(base udev autodetect modconf block filesystems keyboard fsck resume)
Then regenerate the initramfs:
sudo mkinitcpio -P
Navigate to the /boot/loader/entries/ directory and open the relevant boot entry file (e.g., 2024-01-01-linux.conf):
sudo nano /boot/loader/entries/2024-01-01-linux.conf
At the end of the options line, add the following (replace <swap-UUID> with your actual swap UUID):
resume=UUID=<swap-UUID>
To find the UUID of your swap, run:
blkid
Finally, update the bootloader with:
sudo bootctl update
To test if everything is working correctly, run:
sudo systemctl hibernate
If your system hibernates and restores with all programs left open, hibernation is successfully configured!
Note: If you're using encryption for your home directory, additional steps may be required to configure hibernation properly.