mountcritlocal revision 290197
178344Sobrien#!/bin/sh 278344Sobrien# 398184Sgordon# $FreeBSD: head/etc/rc.d/mountcritlocal 290197 2015-10-30 15:52:10Z trasz $ 478344Sobrien# 578344Sobrien 678344Sobrien# PROVIDE: mountcritlocal 7208307Sdougb# REQUIRE: root hostid_save mdconfig 8215824Sdougb# KEYWORD: nojail shutdown 978344Sobrien 1078344Sobrien. /etc/rc.subr 1178344Sobrien 1278344Sobrienname="mountcritlocal" 1378344Sobrienstart_cmd="mountcritlocal_start" 14215824Sdougbstop_cmd=sync 1578344Sobrien 1678344Sobrienmountcritlocal_start() 1778344Sobrien{ 18290197Strasz local err holders waited 19176873Smtm 20124618Smtm # Set up the list of network filesystem types for which mounting 21124618Smtm # should be delayed until after network initialization. 22124618Smtm case ${extra_netfs_types} in 23124618Smtm [Nn][Oo]) 24124618Smtm ;; 25124618Smtm *) 26124618Smtm netfs_types="${netfs_types} ${extra_netfs_types}" 27124618Smtm ;; 28124618Smtm esac 2978344Sobrien 30124618Smtm # Mount everything except nfs filesystems. 31197947Sdougb check_startmsgs && echo -n 'Mounting local file systems:' 32124618Smtm mount_excludes='no' 33124618Smtm for i in ${netfs_types}; do 34124618Smtm fstype=${i%:*} 35124618Smtm mount_excludes="${mount_excludes}${fstype}," 36124618Smtm done 37124618Smtm mount_excludes=${mount_excludes%,} 38290197Strasz 39290197Strasz # Originally, root mount hold had to be released before mounting the root 40290197Strasz # filesystem. This delayed the boot, so it was changed to only wait if 41290197Strasz # the root device isn't readily available. This can result in this script 42290197Strasz # executing before all the devices - such as graid(8) - are available. 43290197Strasz # Thus, should the mount fail, we will wait for the root mount hold release 44290197Strasz # and retry. 45124618Smtm mount -a -t ${mount_excludes} 46176873Smtm err=$? 47290197Strasz if [ $? -ne 0 ]; then 48290197Strasz echo 49290197Strasz echo 'Mounting /etc/fstab filesystems failed,' \ 50290197Strasz 'will retry after root mount hold release' 51290197Strasz 52290197Strasz waited=0 53290197Strasz while [ ${waited} -lt ${root_hold_delay} ]; do 54290197Strasz holders="$(sysctl -n vfs.root_mount_hold)" 55290197Strasz if [ -z "${holders}" ]; then 56290197Strasz break; 57290197Strasz fi 58290197Strasz if [ ${waited} -eq 0 ]; then 59290197Strasz echo -n "Waiting ${root_hold_delay}s" \ 60290197Strasz "for the root mount holders: ${holders}" 61290197Strasz else 62290197Strasz echo -n . 63290197Strasz fi 64290197Strasz if [ ${waited} -eq ${root_hold_delay} ]; then 65290197Strasz break 2 66290197Strasz fi 67290197Strasz sleep 1 68290197Strasz waited=$(($waited + 1)) 69290197Strasz done 70290197Strasz mount -a -t ${mount_excludes} 71290197Strasz err=$? 72290197Strasz fi 73290197Strasz 74197947Sdougb check_startmsgs && echo '.' 7598184Sgordon 76176873Smtm case ${err} in 77124618Smtm 0) 7898184Sgordon ;; 79124618Smtm *) 80124618Smtm echo 'Mounting /etc/fstab filesystems failed,' \ 81290197Strasz 'startup aborted' 82169668Smtm stop_boot true 8398184Sgordon ;; 8498184Sgordon esac 8578344Sobrien} 8678344Sobrien 8778344Sobrienload_rc_config $name 8878344Sobrienrun_rc_command "$1" 89