GNU/Linux >> Tutoriales Linux >  >> Linux

Hibernación sin intercambio habilitado

  1. Deshabilitar el intercambio cuando ya sabe que su sistema puede llegar al punto en que no tendrá suficiente memoria es una mala idea. . Justo en el momento en que el kernel no tiene memoria para asignar, su sistema probablemente será muy-muy no responde o simplemente se cuelga, por lo que tendrá que reiniciarlo. Los bloqueos pueden causar pérdidas de datos, a veces daños en el sistema de archivos. Depende del sistema de archivos, se puede arreglar automáticamente (ext* family, fat family, btrfs y algunos otros), pero no todos los FS admiten esta función. Apuesto a que probablemente no te gustará ejecutar fsck en modo de usuario único cada vez que tenga una corrupción...

  2. Kernel no es tan estúpido como para escribir todo lo que quiere en su SSD, se comporta de manera diferente en comparación con los HDD e intenta hacer la menor escritura posible usando cosas como TRIM. No hay tanto daño a su unidad como puede pensar.

  3. La hibernación es un incorporado subsistema del núcleo que opera en un nivel bajo. Todavía tiene que tener una partición separada con tamaño ≥ tamaño de RAM que le permita hacer una instantánea completa de su memoria. Aquí puede leer cómo Linux gestiona la hibernación. Si no hay un lugar para almacenar permanentemente la imagen de la memoria, no hay forma de que funcione la hibernación. No se pueden almacenar datos en el aire. Sin almacenamiento físico permanente =sin hibernación. Esa es también la respuesta a su pregunta:no puede usar la hibernación sin cambiar en Linux .

Entonces, mi punto es que, por supuesto, puede vivir sin intercambio y habilitarlo solo para la hibernación, pero solo si está seguro de que el 99.9% del tiempo que el sistema está encendido tiene suficiente memoria para todo. Si ese no es tu caso, debes usar swap.

Ahora a la posible solución:

Cuando ejecutas systemctl hibernate systemd inicia un servicio llamado systemd-hibernate.service . Unidad de archivo de la que normalmente se encuentra /usr/lib/systemd/system/ directorio

En Debian se ve así:

#  SPDX-License-Identifier: LGPL-2.1+
#
#  This file is part of systemd.
#
#  systemd is free software; you can redistribute it and/or modify it
#  under the terms of the GNU Lesser General Public License as published by
#  the Free Software Foundation; either version 2.1 of the License, or
#  (at your option) any later version.

[Unit]
Description=Hibernate
Documentation=man:systemd-suspend.service(8)
DefaultDependencies=no
Requires=sleep.target
After=sleep.target

[Service]
Type=oneshot
ExecStart=/lib/systemd/systemd-sleep hibernate

Como puede ver, hay Requisitos y después opciones Podemos escribir otra unidad que permita el intercambio y agregar su nombre a estos campos. Lo llamaremos swap-on.service y colóquelo en /etc/systemd/system/ directorio

Nuestro archivo se verá así:

# Unit filed is not required in our case so you can skip it
[Unit]
Description=Enable swap partition

[Service]
# This line means that service will be executed just once and immediately stop when
# swapon enables swap on /dev/sda3
Type=oneshot

# Change /dev/sda3 with device named after your swap partition 
# like /dev/sdb3 or /dev/nvme0n1p3
# Use lsblk to determine your swap partition (partition with [SWAP] as mountpoint)
# Of course you can think of a more complex solution like running external script
# that determines your swap partition automatically every time service is executed
# but for now I'll go with simple /dev/sda3
ExecStart=/sbin/swapon /dev/sda3

Ahora debemos modificar el systemd-hibernate.service de nuestro sistema :

#  SPDX-License-Identifier: LGPL-2.1+
#
#  This file is part of systemd.
#
#  systemd is free software; you can redistribute it and/or modify it
#  under the terms of the GNU Lesser General Public License as published by
#  the Free Software Foundation; either version 2.1 of the License, or
#  (at your option) any later version.

[Unit]
Description=Hibernate
Documentation=man:systemd-suspend.service(8)
DefaultDependencies=no
Requires=sleep.target swap-on.service <--
After=sleep.target swap-on.service <--

[Service]
Type=oneshot
ExecStart=/lib/systemd/systemd-sleep hibernate

Estamos duplicando swap-on.service en After para asegurarse de que systemd inicie la hibernación after el intercambio está activado y no al revés y en Obligatorio para asegurarse de que systemd no intentará hibernar si swap-on.service fallado.

Ahora cuando ejecutamos systemctl hibernate systemd ejecuta nuestro systemd-hibernate.service modificado que ejecuta swap-on.service que permite el intercambio. Cuando el intercambio está habilitado y los campos Requerido y Después están satisfechos, systemd finalmente puede hacer que nuestro sistema hiberne.

Para hacer que systemd deshabilite el intercambio después de reanudar la hibernación, no necesitaremos crear otro archivo de servicio llamado swap-off.service que hará lo mismo que nuestro swap-on.service , colóquelo en el mismo directorio que el servicio "on" (/etc/systemd/system/). La única diferencia es que este servicio ejecutará swapoff en lugar de intercambio :

[Unit]
Description=Disable swap partition

[Service]
Type=oneshot

#  again, change /dev/sda3 to your swap partition /dev file
ExecStart=/sbin/swapoff /dev/sda3 <--

El siguiente paso es modificar el archivo de servicio llamado [email protected] ubicado en el mismo /usr/lib/systemd/system directorio:

[Unit]
Description=Resume from hibernation using device %f
Documentation=man:[email protected](8)
DefaultDependencies=no
BindsTo=%i.device
Wants=local-fs-pre.target
After=%i.device
Before=local-fs-pre.target
ConditionPathExists=/etc/initrd-release

[Service]
Type=oneshot
ExecStart=/lib/systemd/systemd-hibernate-resume %f

Necesitamos modificar Antes campo ahora. Agregar servicio de intercambio junto a local-fs-pre.target :

...
After=%i.device
Before=local-fs-pre.target swap-off.service <--
ConditionPathExists=/etc/initrd-release
...

Ahora, cuando salga de la hibernación, systemd ejecutará swap-off.service después de que la imagen de intercambio se cargue en la memoria (de hecho, un poco más tarde, pero eso no nos importa)

Tenga en cuenta que esta es una solución completamente teórica, no la probé todavía, pero según lo que sé sobre systemd, debería funcionar. Dado que UPower le pide a systemd que hiberne, lo cual, como expliqué, ejecuta systemd-hibernate.service, esto es probablemente lo que está buscando


Linux
  1. ¿Es el intercambio un anacronismo?

  2. Servicio del sistema operativo Linux 'dhcpd'

  3. Servicio de sistema operativo Linux 'nfs'

  4. Servicio del sistema operativo Linux 'microcode_ctl'

  5. Servicio de sistema operativo Linux 'NetFS'

Cómo enumerar los servicios de inicio en el arranque en Linux

Servicio de sistema operativo Linux 'red'

Servicio de sistema operativo Linux 'mapa de puertos'

Servicio de SO Linux 'auditoría'

Servicio del sistema operativo Linux 'hplip'

¿Puedo ejecutar un servidor Oracle sin intercambio?