Differences between revisions 14 and 43 (spanning 29 versions)
Revision 14 as of 2009-04-08 15:59:27
Size: 2293
Comment:
Revision 43 as of 2016-04-09 12:48:11
Size: 5658
Editor: ?JavierRodriguez
Comment:
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
## page was renamed from Hibernate/Hibernate_Without_Swap_Partition
## page was renamed from Hibernate_Without_Swap_Partition
## page was renamed from Hibernate
#language en
''Translations :'' [[de/Hibernate|Deutsch]]
Line 2: Line 8:
First, create a swap file:
{{{
fallocate -l 256m /swap
Line 3: Line 12:
First, create a swap file:

{{{ dd if=/dev/zero of=/swap bs=1024k count=256

mkswap /swap }}}

256MB for the 512MB eeePC.
mkswap /swap
}}}
"256" refers to the size in MBs ('m' after it). Set this for at least half the size of your RAM.
"/swap" is a location of your swap file. It can be located on any partition (root or home, for example).
Line 12: Line 18:

{{{ /swap swap swap defaults 0 0 }}}
{{{
/swap swap swap defaults 0 0
}}}
Line 16: Line 22:

{{{ sysctl -w vm.swappiness=1 }}}

Edi
t the last line of /etc/sysctl.conf so it sticks:
{{{
sysctl -w vm.swappiness=1
}}}
Create a file called local.conf in /etc/sysctl.d and add the kernel variable there so it sticks:
{{{
Line 22: Line 28:
}}}
Line 24: Line 30:
{{{
Line 26: Line 32:

Now use µswsusp which is an alternate suspend method for the linux kernel that can use a swap file instead of a swap partition and also supports features like compression and encryption.
}}}
Now use uswsusp which is an alternate suspend method for the linux kernel that can use a swap file instead of a swap partition and also supports features like compression and encryption.
Line 30: Line 36:
{{{
aptitude install uswsusp
}}}
Configure uswsusp:
{{{
dpkg-reconfigure -pmedium uswsusp
}}}
At the "Continue without a valid swap space?" question, answer Yes.
Line 31: Line 45:
aptitude install uswsusp At the "Swap space to resume from:" prompt, select the partition where the file above was created.
Line 33: Line 47:
Don't forget to add yourself to the powerdev group and enable memory compression. Answer the "Encrypt snapshot?" and "Show splash screen?" questions as you please.

You might have to add yourself to the powerdev group.
Line 36: Line 52:
{{{
Line 52: Line 68:
}}}
The "resume offset = 8288" is where the swapfile actually is. You may obtain this value by running:
Line 53: Line 71:
The "resume offset = 8288" is where the swapfile actually is, and "resume device" must be the partition and not the swap file. {{{
swap-offset /swap
}}}
Line 55: Line 75:
To test it: The "resume device" must be the partition and not the swap file.
Line 57: Line 77:
Note that after editing the `/etc/uswsusp.conf` file, you may need to run:

{{{
update-initramfs -u
}}}

To test hibernation:
{{{
Line 58: Line 86:
}}}
This will write the content of the RAM to the swap file and shut down. Press the power button to wake up. To enable this method as the default system for hibernation, edit /usr/lib/hal/scripts/linux/hal-system-power-hibernate . There is a bug in this script and it will look for s2disk in the wrong place, you will have to edit it so it looks like this:
{{{
/sbin/s2disk
}}}
This script is in the HAL package, which means it will break if HAL is updated. If hibernate doesn't work after an update, you will have to re-edit /usr/lib/hal/scripts/linux/hal-system-power-hibernate . A good idea would be to make a backup of the file for quick re-insertion after an update breakage.
Line 59: Line 93:
This will write the content of the RAM to the swap file and shutdown the eee. Press the power button on the eee to wake it up. To enable this method as the default system for hibernation, edit /usr/lib/hal/linux/scripts/hal-system-power-hibernate . There is a bug in this script and it will look for s2disk in the wrong place, you willll have to edit it so it looks like this: If s2disk hibernates, but initramfs fails to see your swap file on startup and system continues to boot up normally like the swap file is not there, you'll need to add the "resume" hook to your /etc/default/grub:
{{{
GRUB_CMDLINE_LINUX_DEFAULT="resume=/dev/sda1 quiet"
}}}
where "/dev/sda1" is a partition where your swap file is located.
Line 61: Line 99:
/sbin/s2disk After that, issue "update-grub" to recreate initramfs.
Line 63: Line 101:
This script is in the HAL package, which means it will break if HAL is updated. If hibernate doesn't work after an update, you will have to re-edit /usr/lib/hal/linux/scripts/hal-system-power-hibernate . A good idea would be to make a backup of the file for quick re-insertion after an update breakage. If you want to lock the screen, save the swap to disk (in case your system runs out of power) and suspend to ram (to resume quickly if it still has power), create a script called /usr/local/bin/gotosleep containing:
{{{
/usr/bin/xscreensaver-command -lock
sleep 2
sudo /usr/sbin/s2both
}}}
Line 65: Line 108:
Make sure sudo does not prompt you for a password:
{{{
sudo visudo -f /etc/sudoers.d/local

%powerdev ALL=NOPASSWD: /usr/sbin/s2both, /usr/sbin/s2ram
}}}
 
Line 68: Line 118:
To-Do -- Create the swapfile at the moment of hibernation - and delete (optionally) after resuming. == Tricks when the system is fully encrypted ==
Line 70: Line 120:
For more on Partitioning, Swap and Hibernation - see - (http://wiki.debian.org/DebianEeePC/HowTo/Install#Partitioningandswap) - and - (http://wiki.debian.org/Hibernation) This works even with Debian Jessie and systemd: the steps are the same, but once configured uswsusp with dpkg, edit ''/etc/uswsusp.conf'' and change the resume device:
{{{
resume device = /dev/mapper/sda2_crypt
}}}

Being ''sda2_crypt'' the name of your encripted partition, you can list the ones available in "''/dev/mapper''".

Then, re-execute the configuration, but this time select the new detected partition. This is necessary to reconfigure initramfs:

{{{
dpkg-reconfigure -pmedium uswsusp
}}}

You should also make the proper modifications in "''/etc/default/grub''", and re-execute "''update-grub''":

{{{
GRUB_CMDLINE_LINUX_DEFAULT="resume=/dev/mapper/sda2_crypt quiet"
}}}

== Debian Jessie requirement: make it work with systemd ==

Systemd does not use this kind of hibernation to a file by default. That means that if you try to hibenate using Gnome, KDE or similar, it may not work. To make it compatible with systemd:

{{{
cp /lib/systemd/system/systemd-hibernate.service /etc/systemd/system/
}}}

Now edit ''"/etc/systemd/system/systemd-hibernate.service"'' and change the last line:
{{{
ExecStart=/bin/sh -c 's2disk && run-parts --regex .\* -a post /lib/systemd/system-sleep'
}}}

Finally restart systemd:

{{{
systemctl daemon-reload
}}}


== To-Do ==

-- Create the swapfile at the moment of hibernation - and delete (optionally) after resuming.

For more on Partitioning, Swap and Hibernation - see -
 * [[Hibernation|General Hibernation]]
 * [[DebianEeePC/HowTo/Install]]
 * [[DebianEeePC/HowTo/Configure#Hibernate_.28suspend-to-disk.29]]

----
## Done == ToDo: This page name is ambiguous. it should be merged in [[Hibernation]], or renamed into something more explicit, like [[Hibernation/ToFile]] or [[HowToHibernateToFile]]

Translations : Deutsch

How to use hibernation without a swap partition.

First, create a swap file:

fallocate -l 256m /swap

mkswap /swap 

"256" refers to the size in MBs ('m' after it). Set this for at least half the size of your RAM. "/swap" is a location of your swap file. It can be located on any partition (root or home, for example).

Add this to /etc/fstab:

/swap   swap    swap    defaults        0       0 

Now stop the kernel from using the swap file for swapping:

sysctl -w vm.swappiness=1 

Create a file called local.conf in /etc/sysctl.d and add the kernel variable there so it sticks:

vm.swappiness=1

Activate the swap file:

swapon /swap

Now use uswsusp which is an alternate suspend method for the linux kernel that can use a swap file instead of a swap partition and also supports features like compression and encryption.

Install it:

aptitude install uswsusp

Configure uswsusp:

dpkg-reconfigure -pmedium uswsusp

At the "Continue without a valid swap space?" question, answer Yes.

At the "Swap space to resume from:" prompt, select the partition where the file above was created.

Answer the "Encrypt snapshot?" and "Show splash screen?" questions as you please.

You might have to add yourself to the powerdev group.

Typically a uswsusp.conf file looks like this:

# /etc/uswsusp.conf(8) -- Configuration file for s2disk/s2both

resume device = /dev/sda1

compress = y

early writeout = y

image size = 238941634

RSA key file = /etc/uswsusp.key

shutdown method = platform

resume offset = 8288

The "resume offset = 8288" is where the swapfile actually is. You may obtain this value by running:

swap-offset /swap

The "resume device" must be the partition and not the swap file.

Note that after editing the /etc/uswsusp.conf file, you may need to run:

update-initramfs -u

To test hibernation:

s2disk

This will write the content of the RAM to the swap file and shut down. Press the power button to wake up. To enable this method as the default system for hibernation, edit /usr/lib/hal/scripts/linux/hal-system-power-hibernate . There is a bug in this script and it will look for s2disk in the wrong place, you will have to edit it so it looks like this:

/sbin/s2disk

This script is in the HAL package, which means it will break if HAL is updated. If hibernate doesn't work after an update, you will have to re-edit /usr/lib/hal/scripts/linux/hal-system-power-hibernate . A good idea would be to make a backup of the file for quick re-insertion after an update breakage.

If s2disk hibernates, but initramfs fails to see your swap file on startup and system continues to boot up normally like the swap file is not there, you'll need to add the "resume" hook to your /etc/default/grub:

GRUB_CMDLINE_LINUX_DEFAULT="resume=/dev/sda1 quiet"

where "/dev/sda1" is a partition where your swap file is located.

After that, issue "update-grub" to recreate initramfs.

If you want to lock the screen, save the swap to disk (in case your system runs out of power) and suspend to ram (to resume quickly if it still has power), create a script called /usr/local/bin/gotosleep containing:

/usr/bin/xscreensaver-command -lock
sleep 2
sudo /usr/sbin/s2both

Make sure sudo does not prompt you for a password:

sudo visudo -f /etc/sudoers.d/local

%powerdev ALL=NOPASSWD: /usr/sbin/s2both, /usr/sbin/s2ram

Caveats. -- The console is apparently broken. More on this later.

Tricks when the system is fully encrypted

This works even with Debian Jessie and systemd: the steps are the same, but once configured uswsusp with dpkg, edit /etc/uswsusp.conf and change the resume device:

resume device = /dev/mapper/sda2_crypt

Being sda2_crypt the name of your encripted partition, you can list the ones available in "/dev/mapper".

Then, re-execute the configuration, but this time select the new detected partition. This is necessary to reconfigure initramfs:

dpkg-reconfigure -pmedium uswsusp

You should also make the proper modifications in "/etc/default/grub", and re-execute "update-grub":

GRUB_CMDLINE_LINUX_DEFAULT="resume=/dev/mapper/sda2_crypt quiet"

Debian Jessie requirement: make it work with systemd

Systemd does not use this kind of hibernation to a file by default. That means that if you try to hibenate using Gnome, KDE or similar, it may not work. To make it compatible with systemd:

cp /lib/systemd/system/systemd-hibernate.service /etc/systemd/system/

Now edit "/etc/systemd/system/systemd-hibernate.service" and change the last line:

ExecStart=/bin/sh -c 's2disk && run-parts --regex .\* -a post /lib/systemd/system-sleep'

Finally restart systemd:

systemctl daemon-reload

To-Do

-- Create the swapfile at the moment of hibernation - and delete (optionally) after resuming.

For more on Partitioning, Swap and Hibernation - see -