How to enable Hibernate Mode on Linux Mint

The hibernation feature support in Linux Mint is not out-of-the-box or an included default feature. You have to perform some technical maneuvers if you want to use it. This article will be referencing the Linux Mint swap file to enable the Hibernate mode.

If you ask a Linux community user why their love and loyalty for Linux Mint continues to be undeterred, you will get a colorful response. This community-driven Linux distro never disappoints in its elegance. The UI, together with the desktop environment, is comfortable enough. It is up-to-date and easy to use. Since it is Ubuntu-based, you are guaranteed a wide variety of free and open-source system software applications at your disposal. It also supports proprietary software like multimedia codecs for users seeking complete out-of-the-box multimedia support.

Conceptualizing the System Hibernation Mode

Despite these praises directed towards Linux Mint, the user experience is not a guaranteed smooth train ride. You have to adjust to some technical configurations and setups to fully declare that you have control of Linux Mint in the palm of your hands. One of the technicalities this article explores relates to Linux Mint’s hibernation mode. It is an operating system feature that is especially useful when you want to sign off from your OS usage but not completely Shutdown the OS. Hibernation keeps your operating system in a low-power mode and retains the state of the work or projects you worked on for easy resumption the next time you sign in.

The hibernation feature support in Linux Mint is not out-of-the-box or an included default feature. You have to perform some technical maneuvers if you want to use it. This article will be referencing the Linux Mint swap file to achieve its objective. Think of the swap file as an assistant to the machine’s RAM or main memory. It offers assistive storage to data retrieved from your system’s RAM. You can also think of it as RAM’s secondary storage device. The assistive storage it gives the system RAM is essential in the performance improvement of your OS. It helps keep the system RAM from being overwhelmed when more system and user programs are being loaded on it for efficiency in their execution.

Enabling the Hibernate Mode on Linux Mint

With the swipe files, the approaches to configure and enable hibernation in Linux Mint depend on the file systems in use as some file system formats do not support this Hibernate mode. A good example is the Btrfs storage format. You should consider the use of a file system like ext4.

Preparations

The easiest way to relate to this hibernate function is to think of it as a suspend to disk system feature. Since system hibernation keeps your computer system in a powered-off mode without losing your work or active files, it makes it very different from the system suspend feature. The two features might be from the same household, but they are not siblings. Suspend only keeps your machine in a low power consumption mode. During hibernation, the swap file will store active files from the system RAM, whose state you want to retain once you power back on your machine from its presumed to-be shutdown mode. You will also note that the system resumption period from hibernation mode is longer than the one from suspend mode because your system really adopted a shutdown state.

Hibernation is not a guaranteed success factor in all operating systems, and the factors that contribute to this unsuccessfulness are mainly Bios and system driver issues. A recommended precaution to keep your operating system from boot failure issues once you complete this article tutorial is to use your Linux Mint’s pre-installed Timeshift tool. It will help you configure a system snapshot that functions as a system restore feature similar to the one on Windows operating system.

It restores an OS to a previous state where everything was working normally. An ideal way to efficiently implement the usefulness of the Timeshift tool is to have a Linux Mint live USB/DVD media nearby if the configurations you implement here lead to more complex system issues or cause a boot failure. We have a tutorial on creating a Live USB drive on this Ubuntu-based distro.

Swap File Size Requirements

Since the system kernel is responsible for initiating the actions that facilitate OS hibernation, it has to automate itself to write or create a compressed hibernation image by default. This image file’s maximum size is set to 2/5 the system RAM’s size. If a significant proportion of the RAM’s size is already occupied by other resource-driven system processes before the compressed hibernation image size is created, the swap file is used to hold the surplus of this compressed hibernation image size. Since the swipe file is now the ultimate determiner of whether system hibernation will take place, its allocated size or storage needs to be considerable, or else system hibernation won’t be able to take place.

We cannot confidently quote a safe swap file size allocation. The operations and performances of an operating system can be unpredictable. Your system’s unpredictable nature depends on how much the system apps and services frequent using the assigned swap space and installed RAM. To be safe, Linux community users are advised to adhere to a rule of thumb when setting up the swap file size. The least requirement is that it should match your machine’s RAM size. The advisable requirement is that it should double the size of your machine’s RAM.

Running the following command on your terminal will display useful information regarding your system RAM and currently allocated swap usage.

$ free -h

On my end, I got an output like the following:

Checking RAM and Swap Status on Your Linux Mint Machine
Checking RAM and Swap Status on Your Linux Mint Machine

The succeeding commands in this article will assume that the system file path /swapfile is the default location of your swap file configurations. It is not recommended to work with a manually customized swap file location.

The following command should confirm that your swap file system location is /swapfile. Also, check that its assigned size works for you or meets your system requirements depending on the OS activities you frequently perform or schedule.

$ swapon

On my end, I got the following output:

Determining the Location and Size of the Allocated System Swap
Determining the Location and Size of the Allocated System Swap

Swap File Setup

If you feel that your system’s configured swap file is not big enough or does not adhere to the previously stated rule of thumb, you can adjust it to meet your system specs preference.

The first step is to disable your Linux Mint machine’s currently active swap space. Since this operation is highly privileged, you will need to be a Sudoer user or possess Sudo privileges to execute its related command comfortably.

$ sudo swapoff -a

With no swap file currently active, you can now create and resize it to the desired swap file size. When assigning the swap file a custom size, your input preference should be in Gigabytes or GiB. For instance, if you want a swap file of 4 GB, the following command will achieve this objective. This command immediately succeeds in switching off all active swap partitions and their memory allocations.

$ SIZE=4

You can adjust the above input depending on how resourcefully performant your Linux Mint is characterized.

The above command will only execute successfully if you have enough system memory storage to be allocated. The following command string confirms whether your remaining system storage can handle the newly defined swap file size.

$ df / -h

The output of this command should have a parameter called Avail. It is the available system storage on your machine after you assigned the swap file the presumed 4 GB storage. Comparing it to the assigned swap file size value, the Avail parameter storage value should be significantly miles ahead or more in terms of its displayed storage value. In short, do not use up all your machine storage to meet the expectations of the swap file storage. The swap file storage should be a small fraction or proportion of the total machine storage but not too small that the RAM’s size supersedes it. The absence of sufficient swap file storage will hinder your expectation of enabling Hibernate mode in your Linux Mint machine.

If you managed to create the swap file storage by adhering to the rules and guidelines of the above-stated commands, you could proceed with the tutorial by copy-pasting the command strings and sequences below on your system terminal. Execute them one by one in an orderly fashion.

$ sudo dd if=/dev/zero of=/swapfile bs=1M count=$(($SIZE * 1024))
$ sudo chmod 0600 /swapfile
$ sudo mkswap /swapfile
$ sudo sed -i '/swap/{s/^/#/}' /etc/fstab
$ sudo tee -a /etc/fstab<<<"/swapfile none swap sw 0 0"

The above command string sequences configure a swap file with the 4 GB storage we specified in general. These configurations are necessary to make the swap file compatible with your Linux Mint system. These configuration steps also disable or deactivate any other existing swap file storage as their active location can lead to unnecessary swap conflicts that might be difficult to resolve. You are not limited to using one swap space on your system, but multiple swap file instances are difficult to troubleshoot when the said conflicts start to surface. It is advisable to leave that setup to expert users familiar with the Ins and Outs of their operating system.

Kernel Parameters Setup

The next step is to update the system kernel of the changes we have made regarding the newly created swap file and its allocated storage space. Copy-paste and run this command string on your Linux Mint terminal.

$ RESUME_PARAMS="resume=UUID=$(findmnt / -o UUID -n) resume_offset=$(sudo filefrag -v /swapfile|awk 'NR==4{gsub(/\./,"");print $4;}') "

The successful execution of the above command string should be followed by executing the following command string. Also, please copy and paste it on your Linux Mint terminal.

$ if grep resume /etc/default/grub>/dev/null;

If you get echo -e “\nERROR: Hibernation already configured. Remove the existing configuration from /etc/default/grub and add these parameters instead:

\n$RESUME_PARAMS";else sudo sed -i "s/GRUB_CMDLINE_LINUX_DEFAULT=\"/GRUB_CMDLINE_LINUX_DEFAULT=\"$RESUME_PARAMS/" /etc/default/grub;fi

It would help if you had a keen eye on the possibility of errors that might pop up from executing the above long command strings. They could be typos or other syntax-related errors. If everything is okay with the command strings on your side and they execute successfully, proceed to update your Linux Mint system GRUB with the following command. Also, run it on your terminal.

$ sudo update-grub

Your system GRUB will be updated of any system changes that concern its functional delivery.

Including the Hibernate Feature to the Shutdown Dialog

You now want your Linux Mint shutdown dialog to include the Hibernation option alongside the Shutdown, Restart, or Suspend Shutdown dialog. Running the following command on your terminal will help meet this system objective.

$ sudo tee /etc/polkit-1/localauthority/50-local.d/com.ubuntu.enable-hibernate.pkla <<'EOB' [Enable hibernate] Identity=unix-user:* Action=org.freedesktop.login1.hibernate;org.freedesktop.login1.handle-hibernate-key;org.freedesktop.login1;org.freedesktop.login1.hibernate-multiple-sessions ResultActive=yes EOB

Testing Your Configured Setup

Reboot your Linux Mint system. After the system reboot, you can verify through your system command-line whether the hibernate mode was successfully configured and is active. The following command string helps achieve this objective. Run it on your system terminal.

$ busctl call org.freedesktop.login1 /org/freedesktop/login1 org.freedesktop.login1.Manager CanHibernate

The expected output from executing this command should be a yes string response. If it is not the response you receive, we have some troubleshooting tips for you in the next section that follows this one.

With your command-line interface still active, attempt to manually hibernate your Linux Mint operating system from the Shutdown dialog. Give it time to Shutdown and then power it back on. If you log in to your Linux Mint OS and the current system session is the one you left before hibernating it, then your efforts were fruitful. You should be able to access the command-line interface you previously left active. The command-line utility is also a useful tool for hibernating your Linux Mint OS. It is straightforward through the following command string.

$ systemctl hibernate

Troubleshooting

If you are constantly running into a wall trying to enable Hibernation on your Linux Mint OS successfully, then one of the main contributors to this headache could be your machine’s BIOS/UEFI. You should double-check its pre-configured settings and ensure that it fully supports ACPI Sleep State S4. It is a Suspend to Disk feature that should be active for system Hibernation to take place. It takes a machine’s OS to its lowest power mode, a condition necessary for system hibernation. You can also disable UEFI’s fast boot and secure boot as they are likely to get in the way of your machine’s successful Hibernation.

If your system operates under a non-default Kernel, its compilation might not cater to full Hibernation support. You can troubleshoot this possibility with the following command string.

$ grep CONFIG_HIBERNATION /boot/config-$(uname -r)

Final Note

The complexity of troubleshooting the Hibernation functionality on your Linux Mint OS is the prime reason why the feature is excluded from the system’s Shutdown dialog. The tutorial walk-throughs in this article effectively bring the hibernation function on your Linux Mint OS back to life. The main hurdles you might face while trying to achieve this objective are related to the machine BIOS/UEFI setup. If you take the necessary precautions and adhere to every listed step in this article, and also their guidelines, you will be hibernating with a smile on your Linux Mint OS in no time.

Related Articles

7 COMMENTS

  1. Hi,

    I’m a 20+ year experienced Windoze tech just starting with Linux (Mint). My laptop is a HP ZBook 15-G5 with 512GB NVMe SSD and 32GB RAM. I gave it a 32GB swap partition (96GB for OS & 100MB for efi and the rest for /home). Therefore I did not follow your instructions to setup the swap space. (I’m guessing it would make the swap space in the OS partition and ignore the /swap partition.)

    Therefore the “RESUME_PARAMS…” command fails: “No such file or directory”.

    How do I change the “RESUME_PARAMS…” command to use a pre-existing /swap partition?

    (I’ll probably need the instructions to look up the dev name to insert into said command – I’m still learning how to find things in Linux.)

    After using the modified “RESUME_PARAMS…” command, what changes, if any, will need to be made the remaining commands?

    Thank you in advance,

    -LEGO Roboticist

  2. Great tutorial, although your HERE script is messed up. Remove the ticks and add newlines.

    Do you know why the Mint setup doesn’t do this by default?? It’s really a pity, because the end user will complain about that.

  3. So I followed this tutorial after the swap file setup since I had al ready done a swap file size change from 2G to 8G (I have 4G but this was recommended for me). The problem is that its not clear from the giant commands if something has to be modified to fit my configuration. Also some of the commands when imputed leave me with the prompt “>” asking for further commands so i just ^C out of it and it is not clear from the guide what to do. So the “canHibernate” command just outputs no.

  4. Hi,

    The if seems broken at the Kernel Parameters Setup.

    Can you please update it ?

    Thank you and have a nice day 😀

  5. I lost it on this command:
    $ if grep resume /etc/default/grub>/dev/null;
    which shows this
    >
    and the prompt, forever.
    Where did I go wrong? There is no type since I copied and pasted everything. Thanks

Leave a Reply to C Cancel reply

Please enter your comment!
Please enter your name here

22,858FansLike
446FollowersFollow
16SubscribersSubscribe

Latest Articles

Suggested

Top 8 alternative desktops for Fedora and how to install them

Are you looking for a way of giving your Fedora distro a new look and feel? If so, here is how to install a new Linux desktop environment on your Fedora and which ones are worth testing. Ideally, there are over 30 diverse desktop environments and window managers available for this distro. However, this article will break down the eight excellent desktop environments for you and cover how to install and switch between them in just a couple of minutes.

Featured

More Articles Like This