User Tools

Site Tools


hibernate_from_a_non_activate_swapfile_from_btrfs

This is an old revision of the document!


Hibernate from a non activate swapfile from btrfs

Create swapfile

  • Create a separate swap volume (not necessary)
sudo btrfs subvolume create /mnt/btrfsbase/swap

* Add it to /etc/fstab
UUID=8f9ede3a-912f-40d6-9335-90ed3186e3e4   		      	    /swap	      	     btrfs defaults,noatime,subvol=swap	0 0
  • Be sure there is no discard nor autodefrag options activated for this subvolume
  • Create a swapfile
cd /swap
sudo truncate -s 0 swapfile
sudo chattr +C swapfile
btrfs property set swapfile compression none
sudo chmod 600 swapfile
sudo dd if=/dev/zero of=swapfile bs=1M count=24576 #reserve 24GB
sudo mkswap /swap/swapfile

Find out resume device and offset

  • Find out resume device:
sudo findmnt -no UUID -T /swap/swapfile
gcc -O2 -o btrfs_map_physical btrfs_map_physical.c
  • Calculate offset
  • Write down the last number from the output of the following command:
sudo btrfs_map_physical /swap/swapfile | head -n 2
  • 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:
sudo getconf PAGESIZE
Result: 4096
  • Calculate offset: Divide the first number under the PAGESIZE: offset = PHYSICAL_OFFSET/PAGESIZE

4594864128/4096=1121793

Configure system for hibernation

  • Install u
hibernate_from_a_non_activate_swapfile_from_btrfs.1608109502.txt.gz · Last modified: 2021/02/01 05:55 (external edit)