Povolení hibernace na Linuxu: Porovnání verzí

Z ZděchovNET
Skočit na navigaci Skočit na vyhledávání
Bez shrnutí editace
Bez shrnutí editace
 
(Nejsou zobrazeny 3 mezilehlé verze od stejného uživatele.)
Řádek 1: Řádek 1:
==Ubuntu 24.04==
Povolení hibernace pro Ubuntu 22.04 se swap souborem:


Jako u [[#Ubuntu 22.04]] a dále:
* Make your /swapfile have at least the size of your RAM


* Pro zobrazení menu hibernace vložit text do souboru:
sudo swapoff /swapfile
<source lang="bash">sudo mcedit /etc/polkit-1/rules.d/10-enable-hibernate.rules</source>
sudo dd if=/dev/zero of=/swapfile bs=$(cat /proc/meminfo | grep MemTotal | grep -oh '[0-9]*') count=1024 conv=notrunc
<pre>
sudo mkswap /swapfile
polkit.addRule(function(action, subject) {
sudo swapon /swapfile
if (action.id == "org.freedesktop.login1.hibernate" ||
action.id == "org.freedesktop.login1.hibernate-multiple-sessions" ||
action.id == "org.freedesktop.upower.hibernate" ||
action.id == "org.freedesktop.login1.handle-hibernate-key" ||
action.id == "org.freedesktop.login1.hibernate-ignore-inhibit")
{
return polkit.Result.YES;
}
});
</pre>


==Ubuntu 22.04==
Note the UUID of the partition containing your /swapfile:


Povolení hibernace se swap souborem:
$ sudo findmnt -no SOURCE,UUID -T /swapfile
/dev/nvme0n1p5 20562a02-cfa6-42e0-bb9f-5e936ea763d0


* Make your /swapfile have at least the size of your RAM
* Edit the SystemD hibernate service using sudo systemctl edit systemd-hibernate.service and fill it with the following content:
<source lang="bash">
sudo swapoff /swapfile
sudo dd if=/dev/zero of=/swapfile bs=$(cat /proc/meminfo | grep MemTotal | grep -oh '[0-9]*') count=1024 conv=notrunc
sudo mkswap /swapfile
sudo swapon /swapfile
</source>


Note the UUID of the partition containing your /swapfile:
[Service]
ExecStart=
ExecStartPre=-/bin/run-parts -v -a pre /lib/systemd/system-sleep
ExecStart=/usr/sbin/s2disk
ExecStartPost=-/bin/run-parts -v --reverse -a post /lib/systemd/system-sleep


<source lang="bash">sudo findmnt -no SOURCE,UUID -T /swapfile</source>
* Note the resume offset of your /swapfile:
<pre>/dev/nvme0n1p5 20562a02-cfa6-42e0-bb9f-5e936ea763d0</pre>

* Get the resume offset of your /swapfile:
** Run sudo filefrag -v /swapfile
** Run sudo filefrag -v /swapfile
** In the "physical_offset" column, copy the first row number (without dots). Value example: 34816.
** In the "physical_offset" column, copy the first row number (without dots). Value example: 34816.


* Configure Grub to resume from the swapfile by editing /etc/default/grub and modify the following line:
* Configure Grub to resume from the swapfile by editing /etc/default/grub and modify the following line:
<pre>GRUB_CMDLINE_LINUX_DEFAULT="resume=UUID=20562a02-cfa6-42e0-bb9f-5e936ea763d0 resume_offset=34816 quiet splash"</pre>

GRUB_CMDLINE_LINUX_DEFAULT="resume=UUID=20562a02-cfa6-42e0-bb9f-5e936ea763d0 resume_offset=34818 quiet splash"


* Update Grub:
* Update Grub:
<source lang="bash">sudo update-grub</source>

sudo update-grub


* Create the following /etc/initramfs-tools/conf.d/resume:
* Create the following /etc/initramfs-tools/conf.d/resume:


<pre>
RESUME=UUID=20562a02-cfa6-42e0-bb9e-5e936ea763d0 resume_offset=34816
RESUME=UUID=20562a02-cfa6-42e0-bb9e-5e936ea763d0 resume_offset=34816
# Resume from /swapfile
# Resume from /swapfile
</pre>


* Update initramfs:
* Update initramfs:
<source lang="bash">sudo update-initramfs -u -k all</source>

sudo update-initramfs -u -k all


* K povolení volby hibernace v menu upravte soubor:
* K povolení volby hibernace v menu upravte soubor:
sudo mcedit /var/lib/polkit-1/localauthority/50-local.d/com.ubuntu.enable-hibernate.pkla
<source lang="bash">sudo mcedit /var/lib/polkit-1/localauthority/50-local.d/com.ubuntu.enable-hibernate.pkla</source>


Přidat následující obsah:
Přidat následující obsah:
<pre>
[Re-enable hibernate by default in upower]
[Re-enable hibernate by default in upower]
Identity=unix-user:*
Identity=unix-user:*
Action=org.freedesktop.upower.hibernate
Action=org.freedesktop.upower.hibernate
ResultActive=yes
ResultActive=yes
[Re-enable hibernate by default in logind]

Identity=unix-user:*
[Re-enable hibernate by default in logind]
Action=org.freedesktop.login1.hibernate
Identity=unix-user:*
ResultActive=yes
Action=org.freedesktop.login1.hibernate
ResultActive=yes
</pre>


Now you can hibernate with:
Now you can hibernate with:
* From power off menu
sudo systemctl hibernate.
* From command line:
<source lang="bash">sudo systemctl hibernate</source>
* From command line:
<source lang="bash">sudo pm-hibernate</source>

=Troubleshooting=

Check why systemctl hibernate doesn't work:
<source lang="bash">systemctl status systemd-hibernate.service</source>


=See also=
[https://askubuntu.com/a/1132154 Původní návod na stackoverflow]
* [https://askubuntu.com/a/1132154 Původní návod na stackoverflow]
* [https://feriman.com/enable-hibernate-on-ubuntu-2404-easily-step-by-step-instructions/ Enable Hibernate on Ubuntu 24.04 Easily: Step-by-Step Instructions]


[[Kategorie:Linux]]
[[Kategorie:Linux]]

Aktuální verze z 12. 10. 2024, 06:59

Ubuntu 24.04

Jako u #Ubuntu 22.04 a dále:

  • Pro zobrazení menu hibernace vložit text do souboru:
sudo mcedit /etc/polkit-1/rules.d/10-enable-hibernate.rules
polkit.addRule(function(action, subject) {
    if (action.id == "org.freedesktop.login1.hibernate" ||
        action.id == "org.freedesktop.login1.hibernate-multiple-sessions" ||
        action.id == "org.freedesktop.upower.hibernate" ||
        action.id == "org.freedesktop.login1.handle-hibernate-key" ||
        action.id == "org.freedesktop.login1.hibernate-ignore-inhibit")
    {
        return polkit.Result.YES;
    }
});

Ubuntu 22.04

Povolení hibernace se swap souborem:

  • Make your /swapfile have at least the size of your RAM
sudo swapoff /swapfile
sudo dd if=/dev/zero of=/swapfile bs=$(cat /proc/meminfo | grep MemTotal | grep -oh '[0-9]*') count=1024 conv=notrunc
sudo mkswap /swapfile
sudo swapon /swapfile

Note the UUID of the partition containing your /swapfile:

sudo findmnt -no SOURCE,UUID -T /swapfile
/dev/nvme0n1p5 20562a02-cfa6-42e0-bb9f-5e936ea763d0
  • Get the resume offset of your /swapfile:
    • Run sudo filefrag -v /swapfile
    • In the "physical_offset" column, copy the first row number (without dots). Value example: 34816.
  • Configure Grub to resume from the swapfile by editing /etc/default/grub and modify the following line:
GRUB_CMDLINE_LINUX_DEFAULT="resume=UUID=20562a02-cfa6-42e0-bb9f-5e936ea763d0 resume_offset=34816 quiet splash"
  • Update Grub:
sudo update-grub
  • Create the following /etc/initramfs-tools/conf.d/resume:
RESUME=UUID=20562a02-cfa6-42e0-bb9e-5e936ea763d0 resume_offset=34816
# Resume from /swapfile
  • Update initramfs:
sudo update-initramfs -u -k all
  • K povolení volby hibernace v menu upravte soubor:
sudo mcedit /var/lib/polkit-1/localauthority/50-local.d/com.ubuntu.enable-hibernate.pkla

Přidat následující obsah:

[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

Now you can hibernate with:

  • From power off menu
  • From command line:
sudo systemctl hibernate
  • From command line:
sudo pm-hibernate

Troubleshooting

Check why systemctl hibernate doesn't work:

systemctl status systemd-hibernate.service

See also