hibernate_from_a_non_activate_swapfile_from_btrfs
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
hibernate_from_a_non_activate_swapfile_from_btrfs [2020/12/16 06:47] – created memeruiz | hibernate_from_a_non_activate_swapfile_from_btrfs [2021/02/01 05:55] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== Hibernate from a non activate swapfile from btrfs ====== | ====== Hibernate from a non activate swapfile from btrfs ====== | ||
+ | |||
+ | *** Important! *** This didn't work! It is not secure! When wiping happens, the file gets moved to another place by btrfs, then, this doesn' | ||
+ | |||
+ | * This was just a stupid experiment. | ||
===== Create swapfile ===== | ===== Create swapfile ===== | ||
Line 11: | Line 15: | ||
- | UUID=8f9ede3a-912f-40d6-9335-90ed3186e3e4 | + | UUID=8f9ede3a-912f-40d6-9335-90ed3186e3e4 |
+ | * Be sure there is no discard nor autodefrag options activated for this subvolume | ||
* Create a swapfile | * Create a swapfile | ||
Line 23: | Line 27: | ||
sudo chmod 600 swapfile | sudo chmod 600 swapfile | ||
sudo dd if=/ | sudo dd if=/ | ||
+ | sudo mkswap / | ||
===== Find out resume device and offset ===== | ===== Find out resume device and offset ===== | ||
Line 30: | Line 35: | ||
sudo findmnt -no UUID -T / | sudo findmnt -no UUID -T / | ||
- | * swap_offset doesn' | + | * swap_offset |
gcc -O2 -o btrfs_map_physical btrfs_map_physical.c | gcc -O2 -o btrfs_map_physical btrfs_map_physical.c | ||
Line 38: | Line 43: | ||
sudo btrfs_map_physical / | sudo btrfs_map_physical / | ||
+ | |||
+ | * Result: | ||
+ | |||
+ | FILE OFFSET FILE SIZE EXTENT OFFSET EXTENT TYPE LOGICAL SIZE LOGICAL OFFSET PHYSICAL SIZE DEVID PHYSICAL OFFSET | ||
+ | 0 134217728 0 regular 134217728 4594864128 134217728 1 4594864128 | ||
* Write down the output of the following command: | * Write down the output of the following command: | ||
sudo getconf PAGESIZE | sudo getconf PAGESIZE | ||
+ | |||
+ | Result: 4096 | ||
* Calculate offset: Divide the first number under the PAGESIZE: offset = PHYSICAL_OFFSET/ | * Calculate offset: Divide the first number under the PAGESIZE: offset = PHYSICAL_OFFSET/ | ||
+ | |||
+ | 4594864128/ | ||
+ | |||
+ | |||
+ | ===== Configure system for hibernation ===== | ||
+ | |||
+ | |||
+ | * Create / | ||
+ | |||
+ | RESUME=UUID=8f9ede3a-912f-40d6-9335-90ed3186e3e4 resume_offset=1121793 | ||
+ | |||
+ | * Modify / | ||
+ | |||
+ | GRUB_CMDLINE_LINUX_DEFAULT=" | ||
+ | |||
+ | * Activate the swap file | ||
+ | |||
+ | sudo swapon / | ||
+ | |||
+ | * Install uswsusp package | ||
+ | * Edit / | ||
+ | |||
+ | resume device = / | ||
+ | early writeout = y | ||
+ | image size = 0 | ||
+ | RSA key file = / | ||
+ | shutdown method = platform | ||
+ | resume offset = 1121793 | ||
+ | |||
+ | * Activate a systemd service: | ||
+ | |||
+ | sudo systemctl edit systemd-hibernate.service | ||
+ | |||
+ | * With: | ||
+ | |||
+ | [Service] | ||
+ | ExecStart= | ||
+ | ExecStartPre=-/ | ||
+ | ExecStart=/ | ||
+ | ExecStartPost=-/ | ||
+ | |||
+ | * Update initramfs and grub | ||
+ | |||
+ | sudo update-grub | ||
+ | sudo update-initramfs -k all -u | ||
+ | sudo update-grub | ||
+ | |||
+ | * Test the hibernation: | ||
+ | |||
+ | sudo s2disk | ||
+ | |||
+ | I have a system with encrypted swap, but I don't want to have encryption on the hibernation swap file. My idea is to use hibernation only when strictly necessary, because I don't want to need to put a password during booting. | ||
+ | |||
+ | #!/bin/bash | ||
+ | |||
+ | echo " | ||
+ | sudo swapon / | ||
+ | sleep 1 | ||
+ | echo " | ||
+ | sleep 0.2 | ||
+ | xtrlock -b & | ||
+ | sudo s2disk | ||
+ | echo " | ||
+ | sleep 10 | ||
+ | echo " | ||
+ | sudo swapoff / | ||
+ | sleep 5 | ||
+ | echo " | ||
+ | #sudo wipe -k -f -q -Q 1 / | ||
+ | sudo dd if=/ | ||
+ | sync | ||
+ | sleep 1 | ||
+ | echo " | ||
+ | sudo mkswap / | ||
+ | echo "All done, ready to hiberante again" | ||
+ | |||
+ | ===== References ===== | ||
+ | |||
+ | |||
+ | https:// | ||
+ | |||
+ | https:// | ||
+ | |||
+ | https:// | ||
+ | |||
+ | https:// | ||
+ | |||
+ | https:// | ||
+ | |||
+ | https:// | ||
+ | |||
+ | https:// | ||
+ | |||
+ | |||
hibernate_from_a_non_activate_swapfile_from_btrfs.txt · Last modified: 2021/02/01 05:55 by 127.0.0.1