mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2024-12-26 19:19:32 +03:00
c3ef9f7528
This checks every file it checked (and a few more), but explicitly instead of "if it works it works" best-effort (which wasn't that good anyway) Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Signed-off-by: Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz> Closes #10512 Closes #12101
225 lines
5.2 KiB
Plaintext
Executable File
225 lines
5.2 KiB
Plaintext
Executable File
#!@DEFAULT_INIT_SHELL@
|
|
#
|
|
# 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: $local_fs zfs-import
|
|
# Required-Stop: $local_fs zfs-import
|
|
# Default-Start: 2 3 4 5
|
|
# Default-Stop: 0 1 6
|
|
# X-Stop-After: zfs-zed
|
|
# 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.
|
|
|
|
# Source the common init script
|
|
. @sysconfdir@/zfs/zfs-functions
|
|
|
|
# ----------------------------------------------------
|
|
|
|
chkroot() {
|
|
while read -r _ mp _; do
|
|
if [ "$mp" = "/" ]; then
|
|
return 0
|
|
fi
|
|
done < /proc/self/mounts
|
|
|
|
return 1
|
|
}
|
|
|
|
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
|
|
use mtab
|
|
keyword -lxc -openvz -prefix -vserver
|
|
}
|
|
|
|
# Mount all datasets/filesystems
|
|
do_mount()
|
|
{
|
|
local verbose overlay i mntpt
|
|
|
|
check_boolean "$VERBOSE_MOUNT" && verbose=v
|
|
check_boolean "$DO_OVERLAY_MOUNTS" && overlay=O
|
|
|
|
zfs_action "Mounting ZFS filesystem(s)" \
|
|
"$ZFS" mount -a$verbose$overlay "$MOUNT_EXTRA_OPTIONS"
|
|
|
|
# Require each volume/filesystem to have 'noauto' and no fsck
|
|
# option. This shouldn't really be necessary, as long as one
|
|
# can get zfs-import to run sufficiently early on in the boot
|
|
# process - before local mounts. This is just here in case/if
|
|
# this isn't possible.
|
|
check_boolean "$VERBOSE_MOUNT" && \
|
|
zfs_log_begin_msg "Mounting volumes and filesystems registered in fstab"
|
|
|
|
read_mtab "^/dev/(zd|zvol)"
|
|
read_fstab "^/dev/(zd|zvol)"
|
|
i=0; var="FSTAB_0"
|
|
while [ -n "$(eval echo "\$$var")" ]
|
|
do
|
|
mntpt=$(eval echo "\$$var")
|
|
dev=$(eval echo "\$FSTAB_dev_$i")
|
|
if ! in_mtab "$mntpt" && ! is_mounted "$mntpt" && [ -e "$dev" ]
|
|
then
|
|
check_boolean "$VERBOSE_MOUNT" && \
|
|
zfs_log_progress_msg "$mntpt "
|
|
fsck "$dev" && mount "$mntpt"
|
|
fi
|
|
|
|
i=$((i + 1))
|
|
var=$(eval echo "FSTAB_$i")
|
|
done
|
|
|
|
read_mtab "[[:space:]]zfs[[:space:]]"
|
|
read_fstab "[[:space:]]zfs[[:space:]]"
|
|
i=0; var=$(eval echo "FSTAB_$i")
|
|
while [ -n "$(eval echo "\$$var")" ]
|
|
do
|
|
mntpt=$(eval echo "\$$var")
|
|
if ! in_mtab "$mntpt" && ! is_mounted "$mntpt"
|
|
then
|
|
check_boolean "$VERBOSE_MOUNT" && \
|
|
zfs_log_progress_msg "$mntpt "
|
|
mount "$mntpt"
|
|
fi
|
|
|
|
i=$((i + 1))
|
|
var=$(eval echo "FSTAB_$i")
|
|
done
|
|
check_boolean "$VERBOSE_MOUNT" && zfs_log_end_msg 0
|
|
|
|
return 0
|
|
}
|
|
|
|
# Unmount all filesystems
|
|
do_unmount()
|
|
{
|
|
local i var mntpt
|
|
|
|
# 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
|
|
|
|
check_boolean "$VERBOSE_MOUNT" && \
|
|
zfs_log_begin_msg "Unmounting volumes and filesystems registered in fstab"
|
|
|
|
read_mtab "^/dev/(zd|zvol)"
|
|
read_fstab "^/dev/(zd|zvol)"
|
|
i=0; var="FSTAB_0"
|
|
while [ -n "$(eval echo "\$$var")" ]
|
|
do
|
|
mntpt=$(eval echo "\$$var")
|
|
dev=$(eval echo "\$FSTAB_dev_$i")
|
|
if in_mtab "$mntpt"
|
|
then
|
|
check_boolean "$VERBOSE_MOUNT" && \
|
|
zfs_log_progress_msg "$mntpt "
|
|
umount "$mntpt"
|
|
fi
|
|
|
|
i=$((i + 1))
|
|
var=$(eval echo "FSTAB_$i")
|
|
done
|
|
|
|
read_mtab "[[:space:]]zfs[[:space:]]"
|
|
read_fstab "[[:space:]]zfs[[:space:]]"
|
|
i=0; var="FSTAB_0"
|
|
while [ -n "$(eval echo "\$$var")" ]
|
|
do
|
|
mntpt=$(eval echo "\$$var")
|
|
if in_mtab "$mntpt"; then
|
|
check_boolean "$VERBOSE_MOUNT" && \
|
|
zfs_log_progress_msg "$mntpt "
|
|
umount "$mntpt"
|
|
fi
|
|
|
|
i=$((i + 1))
|
|
var=$(eval echo "FSTAB_$i")
|
|
done
|
|
check_boolean "$VERBOSE_MOUNT" && zfs_log_end_msg 0
|
|
|
|
return 0
|
|
}
|
|
|
|
do_start()
|
|
{
|
|
check_boolean "$ZFS_MOUNT" || exit 0
|
|
|
|
check_module_loaded "zfs" || exit 0
|
|
|
|
# Ensure / exists in /proc/self/mounts.
|
|
# This should be handled by rc.sysinit but lets be paranoid.
|
|
if ! chkroot
|
|
then
|
|
mount -f /
|
|
fi
|
|
|
|
do_mount
|
|
}
|
|
|
|
do_stop()
|
|
{
|
|
check_boolean "$ZFS_UNMOUNT" || exit 0
|
|
|
|
check_module_loaded "zfs" || exit 0
|
|
|
|
do_unmount
|
|
}
|
|
|
|
# ----------------------------------------------------
|
|
|
|
if [ ! -e /sbin/openrc-run ]
|
|
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
|