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
  • 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

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
  • Write down the output of the following command:
sudo getconf PAGESIZE
  • Calculate offset: Divide the first number under the PAGESIZE: offset = PHYSICAL_OFFSET/PAGESIZE
hibernate_from_a_non_activate_swapfile_from_btrfs.1608101251.txt.gz · Last modified: 2021/02/01 05:55 (external edit)