💾 Archived View for complete.org › managing-zfs-zvol-permissions-with-udev captured on 2024-08-24 at 23:44:48. Gemini links have been rewritten to link to archived content
-=-=-=-=-=-=-
There is something of a FAQ on how to make the permissions of a ZFS on Linux[1] volume (zvol) stick. In particular, the user and group (uid and gid) of the owner. When using ZFS on Linux, we can make this work by using udev.
udev puts out less information about these than about most others, but we can figure it out anyhow. There is a file /lib/udev/rules.d/60-zvol.rules that forms the basis for what we'll do.
First, create a udev rule, say /etc/udev/rules.d/99-local-zvol.rules:
KERNEL=="zd*" SUBSYSTEM=="block" ACTION=="add|change" PROGRAM="/lib/udev/zvol_id /dev/%k" RESULT=="tank/vm/debian" OWNER="jgoerzen"
Note carefully the number of equals signs in a row at different places.
The RESULT parameter holds the dataset path in zfs form (no leading slash).
If you have multiple zvols you wish to control, add them all here.
You can set, for instance:
OWNER="jgoerzen" GROUP="disk" MODE="0750"
or however you like.
To apply, run `udevadm control --reload`. The permission change will take effect on the next import of the zpool.
If you use LVM on your host, and your zvols contain LVM images, you might also want to add this to lvm.conf so that zvol LVM images are not presented on the host:
filter = [ "r|/dev/zvol|", "r,/dev/zd.*,", "a/.*/" ]
--------------------------------------------------------------------------------
This is about running ZFS[3] on Linux[4] and Debian[5].
(c) 2022-2024 John Goerzen