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