gissf1 / zram-hibernate

Allows dynamic swap changes to activate disk-based storage as swap for hibernation support when a system typically uses only zram swap during normal operation.
Apache License 2.0
34 stars 3 forks source link

Problem with LUKS (I think) #4

Open priyadi opened 1 year ago

priyadi commented 1 year ago

My setup is a swapfile in a btrfs filesystem under a LUKS volume. Normal hibernate without zram is working, but I can't get zram-hibernate to work.

zram is initialized using zram-generator. Distro is Gentoo Linux.

# zram-hibernate -nt
[584518] creating tmpfile...
[584518] lock acquired.
getResumeInfo() Not a valid block device: KERNEL_RESUME_DEVICE=
ensureDiskSwap(): Initial swap status...
[19:55:46] Used=37G MemFree=3320M SwapUsed=0K/67G Overcommit=0K
     swapfile:  0.0% (0K/63G) [-2]
        zram0:  0.0% (0K/4095M) [100]
WARNING: swap file on btrfs filesystem is not well tested and could be dangerous: /mnt/rootfs/swap/swapfile: on /dev/mapper/root
         Sleeping for 5 seconds... Press Ctrl+C to abort.
Testing underlying block device for: /mnt/rootfs/swap/swapfile: /dev/mapper/root
Unknown device type: /dev/mapper/root: 0:0 
FATAL: no valid swaps found. cannot suspend to disk.

# zram-hibernate -d
[585050] creating tmpfile...
[585050] lock acquired.
 ----- getMemInfo() ----------------------------------------
MemTotal=65496852
MemFree=3337088
MemAvailable=26165256
SwapTotal=71303160
SwapFree=71303160
 ----- getResumeInfo() ----------------------------------------
getResumeInfo() Not a valid block device: KERNEL_RESUME_DEVICE=
getResumeInfo() returned: 128
 ----- getActiveSwapInfo() ----------------------------------------
ACTIVESWAP0_Filename=/mnt/rootfs/swap/swapfile
ACTIVESWAP0_Type=file
ACTIVESWAP0_Size=67108860
ACTIVESWAP0_Used=0
ACTIVESWAP0_Priority=-2
ACTIVESWAP1_Filename=/dev/zram0
ACTIVESWAP1_Type=partition
ACTIVESWAP1_Size=4194300
ACTIVESWAP1_Used=0
ACTIVESWAP1_Priority=100
ACTIVESWAPS=2
 ----- getFstabSwapInfo() ----------------------------------------
FSTABSWAP0_DEVICE="/mnt/rootfs/swap/swapfile"
FSTABSWAP0_OPTIONS="defaults"
FSTABSWAP0_TYPE="swap"
FSTABSWAPS=1
 ----- getSwapInfo() ----------------------------------------
getResumeInfo() Not a valid block device: KERNEL_RESUME_DEVICE=
SWAP0_ACTIVE=1
SWAP0_DEVICE=/mnt/rootfs/swap/swapfile
SWAP0_IS_RESUME=0
SWAP0_OPTIONS=defaults
SWAP0_PRIORITY=-2
SWAP0_SIZE=67108860
SWAP0_TYPE=file
SWAP0_USED=0
SWAP1_ACTIVE=1
SWAP1_DEVICE=/dev/zram0
SWAP1_IS_RESUME=0
SWAP1_PRIORITY=100
SWAP1_SIZE=4194300
SWAP1_TYPE=partition
SWAP1_USED=0
SWAPS=2
 ---------------------------------------------

# lsblk
NAME       MAJ:MIN RM   SIZE RO TYPE  MOUNTPOINTS
zram0      252:0    0     4G  0 disk  
nvme0n1    259:0    0   1,8T  0 disk  
├─nvme0n1p1
│          259:1    0   512M  0 part  /boot
└─nvme0n1p2
           259:2    0   1,8T  0 part  
  └─root   253:0    0   1,8T  0 crypt /home
                                      /mnt/rootfs
                                      /

# swapon
NAME                      TYPE      SIZE USED PRIO
/mnt/rootfs/swap/swapfile file       64G   0B   -2
/dev/zram0                partition   4G   0B  100

# stat -c '%d    %Hr     %Lr'  /dev/mapper/root
5    0     0

# grep -Fx 'Block devices:' -A9999 /proc/devices | sed -r 's/^$//g ; T ; q'
Block devices:
  7 loop
  8 sd
  9 md
 11 sr
 65 sd
 66 sd
 67 sd
 68 sd
 69 sd
 70 sd
 71 sd
128 sd
129 sd
130 sd
131 sd
132 sd
133 sd
134 sd
135 sd
252 zram
253 device-mapper
254 mdp
259 blkext

# cat /proc/cmdline 
BOOT_IMAGE=/vmlinuz-2023-02-06-6.1.10-gentoo-x86_64 root=UUID=a47a317b-c56d-4977-a5fd-61e2aff852b8 ro rootflags=subvol=root crypt_root=UUID=cdb10de8-05d9-4fce-8e3b-31e51b13befc real_root=LABEL=priyadi-root rootfstype=btrfs rootflags=subvol=root root_keydev=/dev/disk/by-label/KEYCHAIN root_key=luks/priyadi-2023.gpg real_resume=LABEL=priyadi-root resume_offset=304948480 root_trim=yes usbcore.autosuspend=-1 i915.enable_guc=2 i915.enable_gvt=1 i915.enable_fbc=1 i915.fastboot=1 i915.enable_psr=1 zswap.enabled=1 zswap.max_pool_percent=25 zswap.compressor=lz4hc mem_sleep_default=deep intel_pstate=disable
gissf1 commented 1 year ago

I think your primary issue is pretty simple: the message getResumeInfo() Not a valid block device: KERNEL_RESUME_DEVICE= indicates that it can't detect a resume= parameter on your kernel command line, which makes sense since the script doesn't look for real_resume=.

If you feel comfortable enough with the code to submit a PR adding real_resume= as a fallback when resume= doesn't exist, I would appreciate it. If not, I can work on putting it together over the next few weeks.

There may be another issue with handling /dev/mapper/ devices, but off the top of my head, I can't be sure if that's a side effect of the failure to detect resume=.