How to enable hibernation on your Linux computer
Hibernation allows to save the current state of the operating system on the hard disk before shutdown the computer, so you can restore it when the system boots up.
Table of Contents
- Create (and enable) a swap partition or file if it’s not already created
- Save the partition UUID
- Save the swap file offset (only for swap files)
- Modify /etc/default/grub
- Modify /etc/mkinitcpio.conf
- Hibernation commands
When you install a new Linux-based operating system, an option to enable hibernation may display (it’s usually inside the disk partition manager). If you want to enable hibernation on an already installed system, you can follow these steps.
Create (and enable) a swap partition or file if it’s not already created
In order to be able to hibernate you computer, a swap partition or file must be enabled. To check if swap is enabled, you can open
/proc/swaps. You’ll see swap location.
$ cat /proc/swaps Filename Type Size Used Priority /swapfile file 4194300 47148 -2
You can also open
/etc/fstab and check if a partition or file has the
$ cat /etc/fstab # Static information about the filesystems. # See fstab(5) for details. # swap /swapfile none swap defaults 0 0 ...
If there is no swap created, follow this tutorial.
Save the partition UUID
You need the swap partition UUID or the partition UUID where the swap file is located. Run:
lsblk -o name,uuid
and copy the UUID of the appropriate partition to a text editor (or any place) so you can use it later.
# In this example, sda5 is the partition where the swap file is located $ lsblk -o name,uuid NAME UUID sda ├─sda1 7B67-62DD ├─sda3 ├─sda4 76BE2E00BE2DBA0F ├─sda5 cbbf7ee3-ba60-4cee-b0c4-e9bf918a4e8e
Save the swap file offset (only for swap files)
If your system has a swap file (not a swap partition), you also need the swap file offset. Run (as root):
filefrag -v <swap_file>
and copy (to a file or somewhere else) the first code number below
physical offset column (including the dots). For example:
# filefrag -v /swapfile Filesystem type is: ef53 File size of /swapfile is 4294967296 (1048576 blocks of 4096 bytes) ext: logical_offset: physical_offset: length: expected: flags: 0: 0.. 14335: 12478464.. 12492799: 14336: ...
In this case, you need to copy
If GRUB is your bootloader, open
/etc/default/grub (as root) and modify the line that starts with
GRUB_CMDLINE_LINUX_DEFAULT. Inside the quotes, add (at the end):
If your system has a swap file, you also need to add:
GRUB_CMDLINE_LINUX_DEFAULT="loglevel=3 quiet resume=UUID=cbbf7ee3-ba60-4cee-b0c4-e9bf918a4e8e resume_offset=12478464.."
To apply these changes, run
update-grub (on Debian-based systems) or
grub-mkconfig -o <grub.cfg file path> (on Arch Linux). Both commands must be run as root.
# Arch Linux grub-mkconfig -o /boot/grub/grub.cfg
On Arch Linux (and maybe on other systems) you must modify
/etc/mkinitcpio.conf. Open the file (as root) and edit the line that starts with
HOOKS (there are several commented lines, look for the uncommented one). Inside the parentheses, add the word
fsck and always after
udev. For example:
HOOKS=(base udev autodetect modconf block filesystems keyboard resume fsck)
To apply the changes, run
mkinitcpio -P as root.
Your desktop environment may have an “Hibernate” button (KDE does). Systemd includes a command to hibernate the computer (and does not need root permissions to run it):
If you have any suggestion, feel free to contact me via social media or email.
Latest tutorials and articles: