Files
mirror_zfs/etc/init.d/zfs-mount.in
T

144 lines
3.1 KiB
Plaintext
Raw Normal View History

2020-07-11 19:35:58 -04:00
#!@DEFAULT_INIT_SHELL@
2025-01-04 12:14:31 +11:00
# SPDX-License-Identifier: BSD-2-Clause
2022-01-06 23:36:04 +01:00
# shellcheck disable=SC2154
2015-04-23 20:35:45 +02:00
#
# zfs-mount This script will mount/umount the zfs filesystems.
#
# chkconfig: 2345 06 99
# description: This script will mount/umount the zfs filesystems during
# system boot/shutdown. Configuration of which filesystems
# should be mounted is handled by the zfs 'mountpoint' and
# 'canmount' properties. See the zfs(8) man page for details.
# It is also responsible for all userspace zfs services.
# probe: true
#
### BEGIN INIT INFO
# Provides: zfs-mount
# Required-Start: zfs-import
2015-04-23 20:35:45 +02:00
# Required-Stop: $local_fs zfs-import
# Default-Start: S
2015-04-23 20:35:45 +02:00
# Default-Stop: 0 1 6
# X-Start-Before: mountall
# X-Stop-After: zfs-zed
2015-04-23 20:35:45 +02:00
# Short-Description: Mount ZFS filesystems and volumes
# Description: Run the `zfs mount -a` or `zfs umount -a` commands.
### END INIT INFO
#
# Released under the 2-clause BSD license.
#
# This script is based on debian/zfsutils.zfs.init from the
# Debian GNU/kFreeBSD zfsutils 8.1-3 package, written by Aurelien Jarno.
2015-04-23 20:35:45 +02:00
# Source the common init script
. @sysconfdir@/zfs/zfs-functions
# ----------------------------------------------------
2015-06-02 16:02:31 +02:00
chkroot() {
while read -r _ mp _; do
if [ "$mp" = "/" ]; then
2015-06-02 16:02:31 +02:00
return 0
fi
2016-09-20 13:07:58 -04:00
done < /proc/self/mounts
2015-06-02 16:02:31 +02:00
return 1
}
2015-04-23 20:35:45 +02:00
do_depend()
{
# Try to allow people to mix and match fstab with ZFS in a way that makes sense.
if [ "$(mountinfo -s /)" = 'zfs' ]
then
before localmount
else
after localmount
fi
# bootmisc will log to /var which may be a different zfs than root.
before bootmisc logger
after zfs-import sysfs
2015-04-23 20:35:45 +02:00
use mtab
keyword -lxc -openvz -prefix -vserver
}
# Mount all datasets/filesystems
do_mount()
{
local verbose overlay
2015-04-23 20:35:45 +02:00
2015-09-22 09:56:28 +02:00
check_boolean "$VERBOSE_MOUNT" && verbose=v
check_boolean "$DO_OVERLAY_MOUNTS" && overlay=O
2015-04-23 20:35:45 +02:00
zfs_action "Mounting ZFS filesystem(s)" \
2022-01-06 23:36:04 +01:00
"$ZFS" mount "-a$verbose$overlay" "$MOUNT_EXTRA_OPTIONS"
2015-04-23 20:35:45 +02:00
return 0
}
# Unmount all filesystems
do_unmount()
{
# This shouldn't really be necessary, as long as one can get
# zfs-import to run sufficiently late in the shutdown/reboot process
# - after unmounting local filesystems. This is just here in case/if
# this isn't possible.
zfs_action "Unmounting ZFS filesystems" "$ZFS" unmount -a
return 0
}
do_start()
{
2015-09-22 09:56:28 +02:00
check_boolean "$ZFS_MOUNT" || exit 0
2015-04-23 20:35:45 +02:00
2015-09-22 09:56:28 +02:00
check_module_loaded "zfs" || exit 0
2015-04-23 20:35:45 +02:00
2016-09-20 13:07:58 -04:00
# Ensure / exists in /proc/self/mounts.
2015-04-23 20:35:45 +02:00
# This should be handled by rc.sysinit but lets be paranoid.
2015-06-02 16:02:31 +02:00
if ! chkroot
2015-04-23 20:35:45 +02:00
then
mount -f /
fi
do_mount
}
do_stop()
{
2015-09-22 09:56:28 +02:00
check_boolean "$ZFS_UNMOUNT" || exit 0
2015-04-23 20:35:45 +02:00
check_module_loaded "zfs" || exit 0
2015-04-23 20:35:45 +02:00
do_unmount
}
# ----------------------------------------------------
if @IS_SYSV_RC@
2015-04-23 20:35:45 +02:00
then
case "$1" in
start)
do_start
;;
stop)
do_stop
;;
force-reload|condrestart|reload|restart|status)
# no-op
;;
*)
[ -n "$1" ] && echo "Error: Unknown command $1."
echo "Usage: $0 {start|stop}"
exit 3
;;
esac
exit $?
else
# Create wrapper functions since Gentoo don't use the case part.
depend() { do_depend; }
start() { do_start; }
stop() { do_stop; }
fi