From 711c2f92854c205deb0621e5dbb7a7a49f7b56d7 Mon Sep 17 00:00:00 2001 From: natemaia Date: Mon, 18 May 2020 00:03:49 -0700 Subject: [PATCH] Support hibernation onto swapfile on btrfs --- installer | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/installer b/installer index 8cb3c02..844d074 100755 --- a/installer +++ b/installer @@ -1915,7 +1915,8 @@ install_cleanup() install_bootldr() { - local uuid_type="UUID" + local uuid_type="UUID" url='' + local offset=0 pagesize=0 echo "Installing $BOOTLDR" @@ -1939,7 +1940,16 @@ install_bootldr() if [[ $SWAP == /dev/mapper* ]]; then RESUME="resume=$SWAP " elif [[ $SWAP == "/swapfile" ]]; then - RESUME="resume=$ROOT_ID resume_offset=$(filefrag -v "${MNT}$SWAP" | awk '{if ($1=="0:") {gsub(/\./, ""); print $4}}') " + if [[ $BTRFS_MNT ]]; then + url='https://raw.githubusercontent.com/osandov/osandov-linux/master/scripts/btrfs_map_physical.c' + pagesize="$(getconf PAGESIZE)" + curl -fsSL "$url" -o btrfs_map_physical.c + gcc -O2 -o btrfs_map_physical btrfs_map_physical.c + offset="$(./btrfs_map_physical "${MNT}$SWAP" | awk -v i=$pagesize '{if ($1 == "0") {print $NF / i}}')" + else + offset="$(filefrag -v "${MNT}$SWAP" | awk '{if ($1 == "0:") {gsub(/\./, ""); print $4}}')" + fi + RESUME="resume=$ROOT_ID resume_offset=$offset " else RESUME="resume=$uuid_type=$(blkid -s $uuid_type -o value "$SWAP") " fi