2 # shellcheck disable=SC2154
4 # zfs-load-key This script will load/unload the zfs filesystems keys.
6 # chkconfig: 2345 06 99
7 # description: This script will load or unload the zfs filesystems keys during
8 # system boot/shutdown. Only filesystems with key path set
9 # in keylocation property. See the zfs(8) man page for details.
13 # Provides: zfs-load-key
14 # Required-Start: $local_fs zfs-import
15 # Required-Stop: $local_fs zfs-import
16 # Default-Start: 2 3 4 5
18 # X-Start-Before: zfs-mount
19 # X-Stop-After: zfs-zed
20 # Short-Description: Load ZFS keys for filesystems and volumes
21 # Description: Run the `zfs load-key` or `zfs unload-key` commands.
24 # Released under the 2-clause BSD license.
26 # This script is based on debian/zfsutils.zfs.init from the
27 # Debian GNU/kFreeBSD zfsutils 8.1-3 package, written by Aurelien Jarno.
29 # Source the common init script
30 . @sysconfdir@/zfs/zfs-functions
32 # ----------------------------------------------------
36 # bootmisc will log to /var which may be a different zfs than root.
37 before bootmisc logger zfs-mount
39 after zfs-import sysfs
40 keyword -lxc -openvz -prefix -vserver
43 # Load keys for all datasets/filesystems
46 zfs_log_begin_msg "Load ZFS filesystem(s) keys"
48 "$ZFS" list -Ho name,encryptionroot,keystatus,keylocation |
49 while IFS=" " read -r name encryptionroot keystatus keylocation; do
50 if [ "$encryptionroot" != "-" ] &&
51 [ "$name" = "$encryptionroot" ] &&
52 [ "$keystatus" = "unavailable" ] &&
53 [ "$keylocation" != "prompt" ] &&
54 [ "$keylocation" != "none" ]
56 zfs_action "Load key for $encryptionroot" \
57 "$ZFS" load-key "$encryptionroot"
66 # Unload keys for all datasets/filesystems
69 zfs_log_begin_msg "Unload ZFS filesystem(s) key"
71 "$ZFS" list -Ho name,encryptionroot,keystatus | sed '1!G;h;$!d' |
72 while IFS=" " read -r name encryptionroot keystatus; do
73 if [ "$encryptionroot" != "-" ] &&
74 [ "$name" = "$encryptionroot" ] &&
75 [ "$keystatus" = "available" ]
77 zfs_action "Unload key for $encryptionroot" \
78 "$ZFS" unload-key "$encryptionroot"
89 check_boolean "$ZFS_LOAD_KEY" || exit 0
91 check_module_loaded "zfs" || exit 0
98 check_boolean "$ZFS_UNLOAD_KEY" || exit 0
100 check_module_loaded "zfs" || exit 0
105 # ----------------------------------------------------
116 force-reload|condrestart|reload|restart|status)
120 [ -n "$1" ] && echo "Error: Unknown command $1."
121 echo "Usage: $0 {start|stop}"
128 # Create wrapper functions since Gentoo don't use the case part.
129 depend() { do_depend; }
130 start() { do_start; }