Skip to content

Instantly share code, notes, and snippets.

@cstrahan
Created June 14, 2022 04:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cstrahan/61d4fdab3a1f9a4def4272eda8650c0e to your computer and use it in GitHub Desktop.
Save cstrahan/61d4fdab3a1f9a4def4272eda8650c0e to your computer and use it in GitHub Desktop.
wget https://raw.githubusercontent.com/osandov/osandov-linux/58e0c5f1bc7f0866ce7a18bcb67f3eabf4be7868/scripts/btrfs_map_physical.c
gcc -O2 -o btrfs_map_physical btrfs_map_physical.c
sudo mount /dev/mapper/data-root /mnt
sudo btrfs sub create /mnt/@swap
sudo umount /mnt
sudo mkdir /swap
sudo mount -o subvol=@swap /dev/mapper/data-root /swap
sudo touch /swap/swapfile
sudo chmod 600 /swap/swapfile
sudo chattr +C /swap/swapfile
sudo btrfs property set /swap/swapfile compression none
sudo dd if=/dev/zero of=/swapfile bs=$(cat /proc/meminfo | awk '/MemTotal/ {print $2}') count=1024 conv=notrunc
offset=$(sudo ./btrfs_map_physical /swap/swapfile | awk 'NR==2{print $9}')
offset=$(($offset / $(getconf PAGESIZE))
uuid=$(findmnt -no UUID /swap)
echo "UUID=$uuid /swap btrfs defaults,noatime,subvol=swap 0 0" | sudo tee -a /etc/fstab
echo "/swap/swapfile none swap sw 0 0" | sudo tee -a /etc/fstab
echo "resume=UUID=$uuid resume_offset=$offset" | sudo tee -a /etc/initramfs-tools/conf.d/resume
sudo findmnt --verify --verbose
sudo kernelstub -a "resume=UUID=$uuid resume_offset=$offset"
sudo update-initramfs -u
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment