Support hibernation onto swapfile on btrfs

This commit is contained in:
natemaia 2020-05-18 00:03:49 -07:00
parent 212b8b77ce
commit 711c2f9285

View File

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