Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Proper order of unmount for zfs partition / dmcrypt
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo
View previous topic :: View next topic  
Author Message
uint
n00b
n00b


Joined: 02 Dec 2024
Posts: 3

PostPosted: Wed Dec 18, 2024 7:35 am    Post subject: Proper order of unmount for zfs partition / dmcrypt Reply with quote

Hi! I have a setup with two disk partitions encrypted with dmcrypt (LUKS), and over them there's a zfs mirrored pool. I also have OpenRC.

At the system boot, the startup order is correct: first I get prompted for the passphrases of the encrypted partitions, then dmcrypt unlocks them, then zfs imports the pool and mounts the partition to the file system.

However, at shutdown it seems that zfs does not unmount its partition, either in time, or at all. This leads to the shutdown log having dmcrypt complaining that encrypted devices cannot be unmounted (as they are busy). I don't have the log at hand, as this normally happens after the syslog-ng shutdown.

This does not seem to do much harm, but still looks messy, and I'd like to set up the correct shutdown order, where:
- zfs partition is unmounted from the fs
- zfs stops the pool (however it calls this operation)
- dmcrypt stops the underlying encrypted partitions

But I'm not sure how to do that, and specifically what controls the order in which OpenRC stops services.
I tried to set
Code:

rc_need="dmcrypt"
ZFS_UNMOUNT='yes'

in the /etc/conf.d/zfs, and indeed zfs tries to unmount the pool, but looks like it fails because it tries to unmount the pool before the mount point in the file system itself is unmounted. Or something like that happens - I am not 100% sure, and cannot check the logs as there are no logs (only terminal output at shutdown)

Can you suggest the proper way to control the unmount order here?
Back to top
View user's profile Send private message
Hu
Administrator
Administrator


Joined: 06 Mar 2007
Posts: 22841

PostPosted: Wed Dec 18, 2024 12:24 pm    Post subject: Reply with quote

Welcome to the forums.

Could you provide a bit more information about the environment? Specifically, is the affected ZFS for critical filesystems like /, for non-critical filesystems like /home, or both? Is the passphrase prompt at boot handled by the initramfs or by the Gentoo dmcrypt initscript? Can you show us /etc/fstab and the output of grep '^[^#]' /etc/conf.d/dmcrypt (non-blank non-comment lines, since there are a lot of stock comments we don't need here)? Mask out any serial numbers or similar if you like. I only want to see how many devices are in use, and their device-mapper names once unlocked.
Back to top
View user's profile Send private message
uint
n00b
n00b


Joined: 02 Dec 2024
Posts: 3

PostPosted: Wed Dec 18, 2024 2:32 pm    Post subject: Reply with quote

Thank you! ZFS is used for /home and some other non-critical data, so not / . Passphrase is handled by the dmcrypt initscript, not initramfs.

/etc/fstab does not mention the ZFS partition (or underlying partitions) at all - it is mounted by the zfs initscripts. It has some generic partitions like / , /boot , etc. Removing entries for devices that are not attached by default, fstab is like this:
Code:

UUID=b07d822d-fc2a-4041-95bf-a510e680d154       /               ext4    noatime         0 1
UUID=f5196daa-6c85-445d-a94a-55765d2fb6a8       /boot           ext4    noatime,noauto  1 2
UUID=87EE-8BF2                                  /boot/efipart   vfat    noatime,noauto  0 0
UUID=87826c0f-237f-4dd1-8c27-50fd80b4ef77       none            swap    sw,pri=1        0 0
UUID=32a77271-ed0e-427e-9a97-eb2633229ab3       /mnt/extra      ext4    noatime         0 2


/etc/conf.d/dmcrypt is like this:
Code:

dmcrypt_key_timeout=1
dmcrypt_retries=5
target=data-vol1
source='/dev/disk/by-id/wwn-0x5002538f3430a793-part5'
target=data-vol2
source='/dev/disk/by-id/wwn-0x500a0751e6e1d210-part1'
Back to top
View user's profile Send private message
Hu
Administrator
Administrator


Joined: 06 Mar 2007
Posts: 22841

PostPosted: Wed Dec 18, 2024 4:01 pm    Post subject: Reply with quote

I am not familiar with ZFS or its unusual non-fstab-based unmounting here. Can you manually transcribe the error when the unmount fails?
Back to top
View user's profile Send private message
uint
n00b
n00b


Joined: 02 Dec 2024
Posts: 3

PostPosted: Wed Dec 18, 2024 4:49 pm    Post subject: Reply with quote

The shutdown terminal output is like this:
Code:

Unmounting ZFS filesystems ...
   Cannot unmount '/mnt/data': pool or dataset is busy          <this is the mountpoint for the zfs partition>
[...]
Unmounting filesystems
   Unmounting /mnt/data ...
   Unmounting /mnt/extra ...
[...]
Removing dm-crypt mappings
   data-vol1 ...
Device-mapper: remove ioctl on data-vol1 failed: Device or resource busy        <multiple lines of this>
Device data-vol1 is still being used
   data-vol2 ...
Device-mapper: remove ioctl on data-vol2 failed: Device or resource busy        <multiple lines of this>
Device data-vol2 is still being used
[...]
<shutdown>


So the picture seems more or less clear - ZFS tries to "turn off" its volume before it's unmounted from the fs, and cannot do that. Unless I'm misinterpreting things.

Apparently zfs partitions can be mounted in a "legacy mode" with fstab entries instead of specifying mountpoint as a partition property for zfs initscripts to use. I tried to do that in hope that if this partition is mounted by whoever reads fstab, it will be unmounted properly, but it did not help. In this way, Unmounting ZFS filesystems ... does not appear in the shutdown output at all, otherwise dm-crypt still cannot remove its mappings.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum