You are not logged in.

#1 2019-11-29 09:23:37

forGGe
Member
From: Ukraine
Registered: 2014-06-12
Posts: 14

Hibernate to swapfile and dm-crypt

Hello, Arch users!

I have following filesystem structure:

> lsblk -o UUID,NAME,MAJ:MIN

UUID                                 NAME          MAJ:MIN
                                     sda             8:0  
BA8C-29E6                            ├─sda1          8:1  
887135e7-18a1-4e96-8b06-be2d2be1c788 ├─sda2          8:2  
8d121994-7a1c-49d2-9f26-54c43e1b7be6 │ └─crypthome 254:1  
996225ec-a266-43ba-99a0-264e6aa38711 └─sda3          8:3  
f3c32c7d-b525-4522-a0d3-7560cee6233e   └─cryptroot 254:0  

I have created a swap file:

> swapon
NAME      TYPE SIZE USED  PRIO
/swapfile file  16G   0B 32767

Its offset:

> sudo filefrag -v /swapfile | awk '{ if($1=="0:"){print $4} }'
23563055..

and offset added to kernel params:

> cat /proc/cmdline
BOOT_IMAGE=/vmlinuz-linux root=/dev/mapper/cryptroot rw nowatchdog sysrq_always_enabled=1 libata.force=noncq cryptdevice=UUID=996225ec-a266-43ba-99a0-264e6aa38711:cryptroot:allow-discards resume=UUID=f3c32c7d-b525-4522-a0d3-7560cee6233e resume_offset=23563055

but still, when I hibernate:

> systemctl hibernate

Laptop fails to enter it:

> dmesg | grep swap
[    0.208284] Spectre V1 : Mitigation: usercopy/swapgs barriers and __user pointer sanitization
[    0.747396] zswap: loaded using pool lzo/zbud
[   11.224744] Adding 16777212k swap on /swapfile.  Priority:32767 extents:1 across:16777212k SSFS
[  152.398830] PM: Cannot find swap device, try swapon -a
[  152.399792] PM: Cannot get swap writer

Hibernate configuration is correctly written to /sys/power:

> cat /sys/power/resume
254:0
> cat /sys/power/resume_offset
23563055

mkinitcpio.conf:

> cat /etc/mkinitcpio.conf | grep "^HOOKS="
HOOKS="base udev autodetect encrypt modconf block filesystems keyboard resume fsck"

What I tried:

1. Using uresume instead of resume.
2. Changing order of HOOKS (resume between filesystems, resume after filesystems, etc.).
3. Trying device name instead of UUID boot parameters.


You play, you pay, you bastard.

Offline

#2 2019-11-29 11:12:37

sabroad
Member
Registered: 2015-05-24
Posts: 242

Re: Hibernate to swapfile and dm-crypt

Is the swapfile on root filesystem with btrfs?

On Btrfs, the "physical" offset you get from filefrag is not the real physical offset on disk; there is a virtual disk address space in order to support multiple devices. Due to this the above method will not work for a swap file from a Btrfs file system.


--
saint_abroad

Offline

#3 2019-11-29 22:30:50

forGGe
Member
From: Ukraine
Registered: 2014-06-12
Posts: 14

Re: Hibernate to swapfile and dm-crypt

sabroad wrote:

Is the swapfile on root filesystem with btrfs?

On Btrfs, the "physical" offset you get from filefrag is not the real physical offset on disk; there is a virtual disk address space in order to support multiple devices. Due to this the above method will not work for a swap file from a Btrfs file system.

Actually, FS is f2fs:

 df -Th
Filesystem            Type      Size  Used Avail Use% Mounted on
dev                   devtmpfs  7.8G     0  7.8G   0% /dev
run                   tmpfs     7.8G  1.2M  7.8G   1% /run
/dev/mapper/cryptroot f2fs      110G   86G   25G  78% /
tmpfs                 tmpfs     7.8G   72M  7.8G   1% /dev/shm
tmpfs                 tmpfs     7.8G     0  7.8G   0% /sys/fs/cgroup
/dev/sda1             vfat      511M  111M  401M  22% /boot
tmpfs                 tmpfs     7.8G  8.0K  7.8G   1% /tmp
/dev/mapper/crypthome f2fs      128G  104G   25G  81% /home
tmpfs                 tmpfs     1.6G   12K  1.6G   1% /run/user/1000

You play, you pay, you bastard.

Offline

#4 2019-12-02 11:55:51

sabroad
Member
Registered: 2015-05-24
Posts: 242

Re: Hibernate to swapfile and dm-crypt

F2FS swapfile support is pretty new in 5.3 and may've been broken by recent changes. YMMV.


--
saint_abroad

Offline

#5 2019-12-02 12:36:31

frostschutz
Member
Registered: 2013-11-15
Posts: 1,417

Re: Hibernate to swapfile and dm-crypt

there was a similar thread about f2fs/swapfile/hibernate https://bbs.archlinux.org/viewtopic.php?id=248116

'filefrag' showed that the swapfile kept changing its offset, however you need the offset to remain the same across reboots for hibernate to work. it has to be the same for all fragments, not just the starting ones

no idea if the proposed solution (last post of thread with chattr) works at all or not, I don't use it myself so I can't test

luck,

Last edited by frostschutz (2019-12-02 12:39:40)

Offline

#6 2019-12-02 14:07:52

nl6720
The Evil Wiki Admin
Registered: 2016-07-02
Posts: 595

Re: Hibernate to swapfile and dm-crypt

frostschutz wrote:

no idea if the proposed solution (last post of thread with chattr) works at all or not, I don't use it myself so I can't test

The chattr command didn't help. Eventually I got tired of the F2FS issues (FS#63839 and FS#63841) and switched the root file system to XFS, so unfortunately I also can't help.

Offline

Board footer

Powered by FluxBB