1eda14cbcSMatt Macy#!@DEFAULT_INIT_SHELL@ 2e92ffd9bSMartin Matuska# shellcheck disable=SC2154 3eda14cbcSMatt Macy# 4eda14cbcSMatt Macy# zfs-mount This script will mount/umount the zfs filesystems. 5eda14cbcSMatt Macy# 6eda14cbcSMatt Macy# chkconfig: 2345 06 99 7eda14cbcSMatt Macy# description: This script will mount/umount the zfs filesystems during 8eda14cbcSMatt Macy# system boot/shutdown. Configuration of which filesystems 9eda14cbcSMatt Macy# should be mounted is handled by the zfs 'mountpoint' and 10eda14cbcSMatt Macy# 'canmount' properties. See the zfs(8) man page for details. 11eda14cbcSMatt Macy# It is also responsible for all userspace zfs services. 12eda14cbcSMatt Macy# probe: true 13eda14cbcSMatt Macy# 14eda14cbcSMatt Macy### BEGIN INIT INFO 15eda14cbcSMatt Macy# Provides: zfs-mount 16*be181ee2SMartin Matuska# Required-Start: zfs-import 17eda14cbcSMatt Macy# Required-Stop: $local_fs zfs-import 18*be181ee2SMartin Matuska# Default-Start: S 19eda14cbcSMatt Macy# Default-Stop: 0 1 6 20*be181ee2SMartin Matuska# X-Start-Before: mountall 21eda14cbcSMatt Macy# X-Stop-After: zfs-zed 22eda14cbcSMatt Macy# Short-Description: Mount ZFS filesystems and volumes 23eda14cbcSMatt Macy# Description: Run the `zfs mount -a` or `zfs umount -a` commands. 24eda14cbcSMatt Macy### END INIT INFO 25eda14cbcSMatt Macy# 26eda14cbcSMatt Macy# Released under the 2-clause BSD license. 27eda14cbcSMatt Macy# 2816038816SMartin Matuska# This script is based on debian/zfsutils.zfs.init from the 2916038816SMartin Matuska# Debian GNU/kFreeBSD zfsutils 8.1-3 package, written by Aurelien Jarno. 30eda14cbcSMatt Macy 31eda14cbcSMatt Macy# Source the common init script 32eda14cbcSMatt Macy. @sysconfdir@/zfs/zfs-functions 33eda14cbcSMatt Macy 34eda14cbcSMatt Macy# ---------------------------------------------------- 35eda14cbcSMatt Macy 36eda14cbcSMatt Macychkroot() { 3716038816SMartin Matuska while read -r _ mp _; do 3816038816SMartin Matuska if [ "$mp" = "/" ]; then 39eda14cbcSMatt Macy return 0 40eda14cbcSMatt Macy fi 41eda14cbcSMatt Macy done < /proc/self/mounts 42eda14cbcSMatt Macy 43eda14cbcSMatt Macy return 1 44eda14cbcSMatt Macy} 45eda14cbcSMatt Macy 46eda14cbcSMatt Macydo_depend() 47eda14cbcSMatt Macy{ 48eda14cbcSMatt Macy # Try to allow people to mix and match fstab with ZFS in a way that makes sense. 49eda14cbcSMatt Macy if [ "$(mountinfo -s /)" = 'zfs' ] 50eda14cbcSMatt Macy then 51eda14cbcSMatt Macy before localmount 52eda14cbcSMatt Macy else 53eda14cbcSMatt Macy after localmount 54eda14cbcSMatt Macy fi 55eda14cbcSMatt Macy 56eda14cbcSMatt Macy # bootmisc will log to /var which may be a different zfs than root. 57eda14cbcSMatt Macy before bootmisc logger 58eda14cbcSMatt Macy 59eda14cbcSMatt Macy after zfs-import sysfs 60eda14cbcSMatt Macy use mtab 61eda14cbcSMatt Macy keyword -lxc -openvz -prefix -vserver 62eda14cbcSMatt Macy} 63eda14cbcSMatt Macy 64eda14cbcSMatt Macy# Mount all datasets/filesystems 65eda14cbcSMatt Macydo_mount() 66eda14cbcSMatt Macy{ 67716fd348SMartin Matuska local verbose overlay 68eda14cbcSMatt Macy 69eda14cbcSMatt Macy check_boolean "$VERBOSE_MOUNT" && verbose=v 70eda14cbcSMatt Macy check_boolean "$DO_OVERLAY_MOUNTS" && overlay=O 71eda14cbcSMatt Macy 72eda14cbcSMatt Macy zfs_action "Mounting ZFS filesystem(s)" \ 73e92ffd9bSMartin Matuska "$ZFS" mount "-a$verbose$overlay" "$MOUNT_EXTRA_OPTIONS" 74eda14cbcSMatt Macy 75eda14cbcSMatt Macy return 0 76eda14cbcSMatt Macy} 77eda14cbcSMatt Macy 78eda14cbcSMatt Macy# Unmount all filesystems 79eda14cbcSMatt Macydo_unmount() 80eda14cbcSMatt Macy{ 81eda14cbcSMatt Macy # This shouldn't really be necessary, as long as one can get 82eda14cbcSMatt Macy # zfs-import to run sufficiently late in the shutdown/reboot process 83eda14cbcSMatt Macy # - after unmounting local filesystems. This is just here in case/if 84eda14cbcSMatt Macy # this isn't possible. 85eda14cbcSMatt Macy zfs_action "Unmounting ZFS filesystems" "$ZFS" unmount -a 86eda14cbcSMatt Macy 87eda14cbcSMatt Macy return 0 88eda14cbcSMatt Macy} 89eda14cbcSMatt Macy 90eda14cbcSMatt Macydo_start() 91eda14cbcSMatt Macy{ 92eda14cbcSMatt Macy check_boolean "$ZFS_MOUNT" || exit 0 93eda14cbcSMatt Macy 94eda14cbcSMatt Macy check_module_loaded "zfs" || exit 0 95eda14cbcSMatt Macy 96eda14cbcSMatt Macy # Ensure / exists in /proc/self/mounts. 97eda14cbcSMatt Macy # This should be handled by rc.sysinit but lets be paranoid. 98eda14cbcSMatt Macy if ! chkroot 99eda14cbcSMatt Macy then 100eda14cbcSMatt Macy mount -f / 101eda14cbcSMatt Macy fi 102eda14cbcSMatt Macy 103eda14cbcSMatt Macy do_mount 104eda14cbcSMatt Macy} 105eda14cbcSMatt Macy 106eda14cbcSMatt Macydo_stop() 107eda14cbcSMatt Macy{ 108eda14cbcSMatt Macy check_boolean "$ZFS_UNMOUNT" || exit 0 109eda14cbcSMatt Macy 110eda14cbcSMatt Macy check_module_loaded "zfs" || exit 0 111eda14cbcSMatt Macy 112eda14cbcSMatt Macy do_unmount 113eda14cbcSMatt Macy} 114eda14cbcSMatt Macy 115eda14cbcSMatt Macy# ---------------------------------------------------- 116eda14cbcSMatt Macy 117eda14cbcSMatt Macyif [ ! -e /sbin/openrc-run ] 118eda14cbcSMatt Macythen 119eda14cbcSMatt Macy case "$1" in 120eda14cbcSMatt Macy start) 121eda14cbcSMatt Macy do_start 122eda14cbcSMatt Macy ;; 123eda14cbcSMatt Macy stop) 124eda14cbcSMatt Macy do_stop 125eda14cbcSMatt Macy ;; 126eda14cbcSMatt Macy force-reload|condrestart|reload|restart|status) 127eda14cbcSMatt Macy # no-op 128eda14cbcSMatt Macy ;; 129eda14cbcSMatt Macy *) 130eda14cbcSMatt Macy [ -n "$1" ] && echo "Error: Unknown command $1." 131eda14cbcSMatt Macy echo "Usage: $0 {start|stop}" 132eda14cbcSMatt Macy exit 3 133eda14cbcSMatt Macy ;; 134eda14cbcSMatt Macy esac 135eda14cbcSMatt Macy 136eda14cbcSMatt Macy exit $? 137eda14cbcSMatt Macyelse 138eda14cbcSMatt Macy # Create wrapper functions since Gentoo don't use the case part. 139eda14cbcSMatt Macy depend() { do_depend; } 140eda14cbcSMatt Macy start() { do_start; } 141eda14cbcSMatt Macy stop() { do_stop; } 142eda14cbcSMatt Macyfi 143