Hibernate on linux mint

Hibernate on linux mint

Для работы Гибернации (hibernation) необходим swap-файл размером не меньше RAM. Если мало оперативки, то наверняка используется подкачка и размер swap-файла должен быть больше вплоть до 2xRAM.

Смотрим, объём оперативки, подкачки и как используется:

Swap-файл должен быть расположен в корневой папке файловой системы(/swapfile). Проверяем:

Если swap-файла нет или он недостаточного размера, создадим его. Сначала отключаем пространство подкачки:

Присваиваем переменной значение желаемого размера swap-файла в Гигабайтах, я установил 6:

Проверяем хватит ли свободного места для нашего файла?:

Далее создаём swap-файл, устанавливаем права, создаём пространство подкачки и отключаем любое другое пространство подкачки чтобы исключить конфликты:

sudo dd if=/dev/zero of=/swapfile bs=1M count=$(($SIZE * 1024)) sudo chmod 0600 /swapfile sudo mkswap /swapfile sudo sed -i ‘/swap/’ /etc/fstab sudo tee -a /etc/fstab

2. Настраиваем параметры ядра

RESUME_PARAMS=»resume=UUID=$(findmnt / -o UUID -n) resume_offset=$(sudo filefrag -v /swapfile|awk ‘NR==4‘) «

if grep resume /etc/default/grub>/dev/null; then 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

Если выдаёт ошибку, то выполняем инструкции. Если ошибки нет – обновляем GRUB:

3. Добавляем пункт Гибернация в диалоговое окно Выключения

Перезагружаем систему.
Проверяем возможность гибернации:

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

Должен быть ответ «yes». Не закрывая запущенные приложения пробуем войти в гибернацию через меню выключения. После отключения компьютера включаем его снова. Всё должно вернуться на рабочий стол.

Чтобы уйти в гибернацию из терминала:

4. Возможные неисправности и их устранение (я не встречался, но попробуйте)

Если вышло сообщение, что система не поддерживает гибернацию, то, скорее всего, это связано с вашим BIOS/UEFI. Загрузитесь в BIOS/UEFI и проверьте настройки, должен поддерживаться ACPI sleep state S4. Функции UEFI’s secure boot и fast boot могут также запрещать гибернацию, отключите их.

Если вы используете ядро не по умолчанию, возможно оно было скомпилировано без поддержки гибернации. Проверяем:

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

Если система допускает режим гибернации, она все равно может сломаться в состоянии сна или вероятнее во время возобновления работы. Это опять же может быть вызвано проблемами с BIOS/UEFI, некоторые из них имеют дефектную реализацию ACPI, или проблемами с аппаратным обеспечением, включая драйверы ядра и прошивки.

Поэтому обновите BIOS, удалите/отключите как можно больше устройств и повторите попытку, возможно, этого уже достаточно. Попробуйте и другие ядра.

Устранение неполадок в спящем режиме не всегда легко (есть причина, по которой эта функция отключена по умолчанию!), лучше всего искать на форумах и в Интернете решение, касающееся вашего оборудования. К сожалению, решение не может быть найдено во всех случаях.

  • Вы здесь:
  • Главная
  • Linux
  • Как включить Гибернацию в Linux Mint 19
Читайте также:  Linux check which process is running

Источник

How to Enable Hibernate Option in Linux Mint 20.x & 21

Hibernate is a feature to save your work from computer memory into hard drive, and then power-off the machine completely. On next boot, it will revert system status and go directly to where you left it.

Suspend does the same job but saving all the work into RAM memory. So the system is not completely turned off and needs battery or power supply to serve it.

Verify if hibernate works:

Hibernate function does not work in may case in Linux Mint 20 by default. You can test it out by opening “terminal” from start menu, and run command:

You need to disable 'Secure Boot' in BIOS/UEFI settings before being able to use hibernate

NOTE: Save your work before running the command in case hibernate does not work! When your system is shutdown completely, start it again and see if it reverts to where you left it.

Enable Hibernate in Linux Mint 20/21

If the function does not work for you, do the steps below one by one to enable it.

1.) Check the swap area UUID:

As I mentioned, the hibernate function saves all the work into hard drive. The location is usually the Swap area. To check it out, open “terminal” from start menu and run command:

It usually outputs the partition /dev/sdaX you created while installing the system.

Next run the blkid command should tell you the UUID for this partition.

Copy the ID and it will be used in next step.

2.) Enable hibernate via kernel parameter:

You can add a kernel parameter to boot menu easily via editing the configuration file. However, a graphical tool will be friendly for beginners.

a.) Search for and install ‘Grub Customizer‘ from Software Manager app. Or open terminal and run command to install the tool:

sudo apt install grub-customizer
For Linux Mint 21, grub-customizer is NOT available in system repository due to upstream changes. Open terminal and run the 2 commands to add its official PPA and update cache before running 'apt install' command: sudo add-apt-repository ppa:danielrichter2007/grub-customizer sudo apt update

b.) Next launch the tool from start menu, and navigate to ‘General Settings’ tab. Finally add following in kernel parameters box after ‘quiet splash’

resume=UUID=the_id_you_got_in_previous_step

Click the top-left “Save” button and restart your computer. And test the hibernate function again via ‘systemctl hibernate‘ command.

Add Hibernate Option in Shutdown menu

The default ‘Quit’ menu options lack hibernate. It is however easy to add back if the function works!

Читайте также:  Linux где файлы сервисов

Firstly open terminal from start menu. When it opens, run command to create & edit the configuration file:

sudo xed /etc/polkit-1/localauthority/50-local.d/com.linuxmint.enable-hibernate.pkla

When the file opens, paste following lines and save it!

[Re-enable hibernate by default in upower]
Identity=unix-user:*
Action=org.freedesktop.upower.hibernate
ResultActive=yes

[Re-enable hibernate by default in logind]
Identity=unix-user:*
Action=org.freedesktop.login1.hibernate;org.freedesktop.login1.handle-hibernate-key;org.freedesktop.login1;org.freedesktop.login1.hibernate-multiple-sessions;org.freedesktop.login1.hibernate-ignore-inhibit
ResultActive=yes

OK, now open the Shutdown menu and see the magic!

In case for those do not have a swap partition, you can create a swap file instead and use UUID of root partition along with physical offset.

Источник

Guide on how to enable hibernation on Linux Mint 20 Cinnamon (Ubuntu 20) and prevent unwanted wakeups

just a minor heads-up: for swapon —show you don’t need sudo . — be rather stingy than generous with sudo s; elevated privileges should be given sparingly!

another one for enabling hibernate in the GUI: it is advised to rather use /etc/polkit-1/localauthority/50-local.d/com.ubuntu.enable-hibernate.pkla instead of /var/lib/. (sorry i can’t link the source, because it shows a 404, but it was directly from help.ubuntu.com.) || also the line for logind should be Action=org.freedesktop.login1.hibernate;org.freedesktop.login1.handle-hibernate-key;org.freedesktop.login1;org.freedesktop.login1.hibernate-multiple-sessions;org.freedesktop.login1.hibernate-ignore-inhibit instead of just Action=org.freedesktop.login1.hibernate .

This solution didn’t work for Linux Mint 20.2. However, the Hibernate button has appeared — it restarted OS. Finally, found solution Enabling hibernation in Linux Mint 20.2. Increased swap partition to double as RAM and configured as first answer and now it recovers fine.

Thank you for taking the time to write this up, but please post things in the Q&A format. If you want to share your knowlegde, then ask a question and post the answer yourself, but we do need everything to be in the form of a question or answer. I will post your answer as a community wiki, but please ping me if you see this and would like post it as a regular answer so you can get your well-deserved rep.

1 Answer 1

The following was originally posted as part of the question, so I (terdon) am reproducing it here.

UPDATE: I have encountered some inconsistencies with my script in section 4 that is meant to be executed on every wake-up. Turns out, /proc/acpi/wakeup settings are only reset sometimes. Not on every shutdown/restart/hibernate/suspend. So, from time to time, my script would enable wakeups. I have updated the script. Now it checks if it says enabled anywhere in /proc/acpi/wakeup and only then outputs to it.

This is, in a way, a memo for myself in the future. I do not understand why hibernation on linux is not a simple feature that just works and why enabling it has to be so complicated. I hope it also helps people having questions about hibernation.

  1. First, you need to make sure you have a large enough swap file. Swap is where your RAM is saved on disk when you hibernate.
  • Check the size of your swap either through System Monitor -> Resources or by running sudo swapon —show . You probably do not have enough. Your swap size should be somewhat larger than you RAM size. There are some guides online. I go for 5GB swap on my 4GB RAM machine.
  • How to make your swap larger depends on how you have it set up. Maybe you need to create a larger swap file, maybe you need to open GParted and simply resize partitions there. I have an encrypted LVM with /dev/vgmint/root and /dev/vgmint/swap volumes. You cannot resize LVM while it is mounted, so you boot from a USB stick with Linux Mint. There you can use Disks app to unlock your encrypted LVM and use this beautiful guide to safely reduce the size of your /dev/vgmint/root volume:
    • Force check file system sudo e2fsck -f /dev/vgmint/root
    • Shrink your file system sudo resize2fs /dev/vgmint/root 180G . Replace 180G with about 90% of the size you want the final volume to be.
    • Reduce your volume to its final size sudo lvreduce -L 200G /dev/vgmint/root , where 200G is your volume’s final size.
    • Grow your file system to take up the rest of the free space of your volume sudo resize2fs /dev/vgmint/root
    sudo -i cd /var/lib/polkit-1/localauthority/50-local.d/ nano com.ubuntu.enable-hibernate.pkla 
    [Re-enable hibernate by default in upower] Identity=unix-user:* Action=org.freedesktop.upower.hibernate ResultActive=yes [Re-enable hibernate by default in logind] Identity=unix-user:* Action=org.freedesktop.login1.hibernate ResultActive=yes 
    • Here is how to disable a device: echo DEVICE_NAME | sudo tee /proc/acpi/wakeup . (Thanks to this thread.)
    • Figure out which devices cause you problems (I have disabled all) and write a bash script that would disable them. (File might need to be owned by root, since root will be executing it.) It would look something like:
    #!/bin/bash filename='/proc/acpi/wakeup' n=0 fix=false while read line; do if [[ "$line" == *"enabled"* ]]; then fix=true #break fi n=$((n)) done < $filename if [[ "$fix" == "true" ]]; then echo RP01 | tee /proc/acpi/wakeup echo RP02 | tee /proc/acpi/wakeup echo RP03 | tee /proc/acpi/wakeup echo RP05 | tee /proc/acpi/wakeup echo RP06 | tee /proc/acpi/wakeup echo XHC1 | tee /proc/acpi/wakeup echo LID0 | tee /proc/acpi/wakeup fi 

    Do not forget to make your script executable for root. sudo su and then chmod +x /your-script.sh

    • Now, we need to create a systemctl service that will be calling the script. (Thanks to this article and many other posts on this website for inspiration). I call the service wakeups. Create the file using sudo nano /etc/systemd/system/wakeups.service . The contents of the file:
    [Unit] Description=Fix unwanted wakeups from suspend [Service] Type=oneshot TimeoutSec=0 StandardOutput=syslog User=root ExecStart=/path-to-your-script/script.sh [Install] WantedBy=multi-user.target suspend.target hibernate.target 
    • Enable the service by running systemctl enable wakeups.service
    1. Alright, that is all it takes to have hibernate properly functioning! Test and make sure everything works correctly when booting regularly and when returning from hibernate/suspend.

    Источник

Оцените статью
Adblock
detector