debian: package removed dependencies in initscripts-config

Since initscripts was removed /etc/network/if-up.d/mountnfs doesn't
exist anymore. Need to update logic here, copy from initscripts here.
Add the service from Debian initscripts.
Add the /lib/init/mount-functions.sh file.
Let mountnfs service be installed by debhelper.
Also change the buffer are to /usr/share/starlingx/initscripts, to
avoid possible conflicts.
Add sysvinv-utils dependency for /lib/init/vars.sh file.

Tests on AIO-SX:
PASS: build-pkgs && build-image
PASS: unlocked enabled available
PASS: mountnfs service is started at initial boot, same as on CentOS
PASS: stop & start mountnfs service
This work assumes advanced nfs tests were run when initscripts
mountnfs was chosen in the first place.

Depends-On: https://review.opendev.org/c/starlingx/tools/+/843853
Depends-On: https://review.opendev.org/c/starlingx/config-files/+/843854
Story: 2009101
Task: 44776
Signed-off-by: Dan Voiculeasa <dan.voiculeasa@windriver.com>
Change-Id: I9291345f869b0ad9ee35ddce8cba6125729dfd5a
This commit is contained in:
Dan Voiculeasa 2022-06-08 14:03:52 +03:00
parent 2b02e96b04
commit 33cc0f3740
9 changed files with 926 additions and 114 deletions

View File

@ -8,6 +8,7 @@ Homepage: https://www.starlingx.io
Package: initscripts-config
Architecture: all
Depends: ${misc:Depends}, systemd, procps
Depends: ${misc:Depends}, systemd, procps, sysvinit-utils
Breaks: initscripts
Description: StarlingX initscripts configuration file
Initialize zeroconf and mountnfs.service and customize sysctl.conf

View File

@ -0,0 +1,2 @@
/lib/init
/usr/share/starlingx

View File

@ -1,4 +1,4 @@
sysctl.conf /usr/share/starlingx
nsswitch.conf /usr/share/starlingx
mountnfs.sh /usr/share/starlingx
mountnfs.service /usr/share/starlingx
sysctl.conf /usr/share/starlingx/initscripts
nsswitch.conf /usr/share/starlingx/initscripts
mountnfs /usr/share/starlingx/initscripts
mount-functions /usr/share/starlingx/initscripts

View File

@ -6,8 +6,8 @@ Before=uexportfs.service
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/etc/network/if-up.d/mountnfs start
ExecStop=/etc/network/if-up.d/mountnfs stop
ExecStart=/etc/init.d/mountnfs start
ExecStop=/etc/init.d/mountnfs stop
[Install]
WantedBy=multi-user.target

View File

@ -2,15 +2,13 @@
set -e
cp /usr/share/starlingx/sysctl.conf /etc/sysctl.conf
cp /usr/share/starlingx/initscripts/sysctl.conf /etc/sysctl.conf
chmod 644 /etc/sysctl.conf
cp /usr/share/starlingx/mountnfs.sh /etc/init.d/mountnfs.sh
chmod 644 /etc/init.d/mountnfs.sh
cp /usr/share/starlingx/nsswitch.conf /etc/nsswitch.conf
cp /usr/share/starlingx/initscripts/mountnfs /etc/init.d/mountnfs
chmod 755 /etc/init.d/mountnfs
cp /usr/share/starlingx/initscripts/nsswitch.conf /etc/nsswitch.conf
chmod 644 /etc/nsswitch.conf
systemctl unmask mountnfs.service
cp /usr/share/starlingx/mountnfs.service /etc/systemd/system/mountnfs.service
systemctl enable mountnfs.service > /dev/null 2>&1 || :
cp /usr/share/starlingx/initscripts/mount-functions /lib/init/mount-functions.sh
chmod 644 /lib/init/mount-functions.sh
#DEBHELPER#

View File

@ -2,3 +2,6 @@
#export DH_VERBOSE = 1
%:
dh $@
override_dh_installsystemd:
dh_installsystemd --name=mountnfs mountnfs.service

View File

@ -0,0 +1,722 @@
#
# Functions used by several mount* scripts in initscripts package
#
# Sourcer must source /lib/lsb/init-functions.sh
# List available fstab files, including any files in /etc/fstab.d.
# This looks ugly, but we can't use find and it's safer than globbing.
fstab_files()
{
echo /etc/fstab
if [ -d /etc/fstab.d ]; then
ls -1 /etc/fstab.d | grep '\.fstab$' | sed -e 's;^;/etc/fstab.d/;'
fi
}
# $1: directory
is_empty_dir() {
for FILE in $1/* $1/.*
do
case "$FILE" in
"$1/.*") return 0 ;;
"$1/*"|"$1/."|"$1/..") continue ;;
*) return 1 ;;
esac
done
return 0
}
selinux_enabled () {
which selinuxenabled >/dev/null 2>&1 && selinuxenabled
}
# Read /etc/fstab, looking for:
# 1) The root filesystem, resolving LABEL=*|UUID=* entries to the
# device node,
# 2) Swap that is on a md device or a file that may be on a md
# device,
_read_fstab () {
echo "fstabroot=/dev/root"
echo "rootdev=none"
echo "roottype=none"
echo "rootopts=defaults"
echo "rootmode=rw"
echo "rootcheck=no"
echo "swap_on_lv=no"
echo "swap_on_file=no"
fstab_files | while read file; do
if [ -f "$file" ]; then
while read DEV MTPT FSTYPE OPTS DUMP PASS JUNK; do
case "$DEV" in
""|\#*)
continue
;;
/dev/mapper/*)
[ "$FSTYPE" = "swap" ] && echo swap_on_lv=yes
;;
/dev/*)
;;
LABEL=*|UUID=*)
if [ "$MTPT" = "/" ] && [ -x /sbin/findfs ]
then
DEV="$(findfs "$DEV")"
fi
;;
/*)
[ "$FSTYPE" = "swap" ] && echo swap_on_file=yes
;;
*)
;;
esac
[ "$MTPT" != "/" ] && continue
echo rootdev=\"$DEV\"
echo fstabroot=\"$DEV\"
echo rootopts=\"$OPTS\"
echo roottype=\"$FSTYPE\"
( [ "$PASS" != 0 ] && [ "$PASS" != "" ] ) && echo rootcheck=yes
( [ "$FSTYPE" = "nfs" ] || [ "$FSTYPE" = "nfs4" ] ) && echo rootcheck=no
case "$OPTS" in
ro|ro,*|*,ro|*,ro,*)
echo rootmode=ro
;;
esac
done < "$file"
fi
done
}
# Read /etc/fstab, looking for:
# 1) The root filesystem, resolving LABEL=*|UUID=* entries to the
# device node,
# 2) Swap that is on a md device or a file that may be on a md
# device,
read_fstab () {
eval "$(_read_fstab)"
}
# Find a specific fstab entry
# $1=mountpoint
# $2=fstype (optional)
_read_fstab_entry () {
# Not found by default.
echo "MNT_FSNAME="
echo "MNT_DIR="
echo "MNT_TYPE="
echo "MNT_OPTS="
echo "MNT_FREQ="
echo "MNT_PASS="
fstab_files | while read file; do
if [ -f "$file" ]; then
while read MNT_FSNAME MNT_DIR MNT_TYPE MNT_OPTS MNT_FREQ MNT_PASS MNT_JUNK; do
case "$MNT_FSNAME" in
""|\#*)
continue;
;;
esac
if [ "$MNT_DIR" = "$1" ]; then
if [ -n "$2" ]; then
[ "$MNT_TYPE" = "$2" ] || continue;
fi
echo "MNT_FSNAME=$MNT_FSNAME"
echo "MNT_DIR=$MNT_DIR"
echo "MNT_TYPE=$MNT_TYPE"
echo "MNT_OPTS=$MNT_OPTS"
echo "MNT_FREQ=$MNT_FREQ"
echo "MNT_PASS=$MNT_PASS"
break 2
fi
MNT_DIR=""
done < "$file"
fi
done
}
# Find a specific fstab entry
# $1=mountpoint
# $2=fstype (optional)
# returns 0 on success, 1 on failure (not found or no fstab)
read_fstab_entry () {
eval "$(_read_fstab_entry "$1" "$2")"
# Not found by default.
found=1
if [ "$1" = "$MNT_DIR" ]; then
found=0
fi
return $found
}
# Mount kernel and device file systems.
# $1: mount mode (mount, remount)
# $2: file system type
# $3: alternative file system type (or empty string if none)
# $4: mount point
# $5: mount device name
# $6... : extra mount program options
domount () {
MOUNTMODE="$1"
PRIFSTYPE="$2"
ALTFSTYPE="$3"
MTPT="$4"
DEVNAME="$5"
CALLER_OPTS="$6"
KERNEL="$(uname -s)"
# Figure out filesystem type from primary and alternative type
FSTYPE=
# Filesystem-specific mount options
FS_OPTS=
# Mount options from fstab
FSTAB_OPTS=
if [ "$MOUNTMODE" = remount ] ; then
case "$KERNEL" in
*FreeBSD)
case "$PRIFSTYPE" in
proc|tmpfs|sysfs)
# can't be remounted
return 0
;;
esac
;;
esac
fi
if [ "$PRIFSTYPE" = proc ]; then
case "$KERNEL" in
Linux) FSTYPE=proc ;;
GNU) FSTYPE=proc; FS_OPTS="-ocompatible" ;;
*FreeBSD) FSTYPE=linprocfs ;;
*) FSTYPE=procfs ;;
esac
elif [ "$PRIFSTYPE" = bind ]; then
case "$KERNEL" in
Linux) FSTYPE="$DEVNAME"; FS_OPTS="-obind" ;;
*FreeBSD) FSTYPE=nullfs ;;
GNU) FSTYPE=firmlink ;;
*) FSTYPE=none ;;
esac
elif [ "$PRIFSTYPE" = tmpfs ]; then
# always accept tmpfs, to mount /run before /proc
case "$KERNEL" in
*) FSTYPE=$PRIFSTYPE ;;
esac
elif grep -E -qs "$PRIFSTYPE\$" /proc/filesystems; then
FSTYPE=$PRIFSTYPE
elif grep -E -qs "$ALTFSTYPE\$" /proc/filesystems; then
FSTYPE=$ALTFSTYPE
fi
# Filesystem not supported by kernel
if [ ! "$FSTYPE" ]; then
if [ "$ALTFSTYPE" ]; then
log_warning_msg "Filesystem types '$PRIFSTYPE' and '$ALTFSTYPE' are not supported. Skipping mount."
else
log_warning_msg "Filesystem type '$PRIFSTYPE' is not supported. Skipping mount."
fi
return
fi
# We give file system type as device name if not specified as
# an argument
if [ -z "$DEVNAME" ] ; then
DEVNAME=$FSTYPE
fi
# Get the mount options from /etc/fstab
if read_fstab_entry "$MTPT" "$FSTYPE"; then
case "$MNT_OPTS" in
noauto|*,noauto|noauto,*|*,noauto,*)
return
;;
?*)
FSTAB_OPTS="-o$MNT_OPTS"
;;
esac
fi
if [ ! -d "$MTPT" ]
then
log_warning_msg "Mount point '$MTPT' does not exist. Skipping mount."
return
fi
if [ "$MOUNTMODE" = "mount_noupdate" ]; then
MOUNTFLAGS="-n"
MOUNTMODE=mount
fi
if [ "$MOUNTMODE" = "remount_noupdate" ]; then
MOUNTFLAGS="-n"
MOUNTMODE=remount
fi
case "$MOUNTMODE" in
mount)
if mountpoint -q "$MTPT"; then
# Already mounted, probably moved from the
# initramfs, so remount with the
# user-specified mount options later on.
:
else
if [ "$VERBOSE" != "no" ]; then
is_empty_dir "$MTPT" >/dev/null 2>&1 || log_warning_msg "Files under mount point '$MTPT' will be hidden."
fi
mount $MOUNTFLAGS -t $FSTYPE $CALLER_OPTS $FSTAB_OPTS $FS_OPTS $DEVNAME $MTPT
if [ "$FSTYPE" = "tmpfs" -a -x /sbin/restorecon ]; then
/sbin/restorecon $MTPT
fi
fi
;;
remount)
if mountpoint -q "$MTPT"; then
# Remount with user-specified mount options
mount $MOUNTFLAGS -oremount $CALLER_OPTS $FSTAB_OPTS $MTPT
fi
;;
esac
}
#
# Preserve /var/run and /var/lock mountpoints
#
pre_mountall ()
{
:
}
# If the device/inode are the same, a bind mount already exists or the
# transition is complete, so set up is not required. Otherwise bind
# mount $SRC on $DEST.
bind_mount ()
{
SRC=$1
DEST=$2
FSTYPE=""
OPTS=""
ssrc="$(/usr/bin/stat -L --format="%d %i" "$SRC" 2>/dev/null || :)"
sdest="$(/usr/bin/stat -L --format="%d %i" "$DEST" 2>/dev/null || :)"
case "$(uname -s)" in
Linux) FSTYPE=$SRC; OPTS="-orw -obind" ;;
*FreeBSD) FSTYPE=nullfs; OPTS="-orw" ;;
GNU) FSTYPE=firmlink ;;
*) FSTYPE=none ;;
esac
# Bind mount $SRC on $DEST
if [ -n "$ssrc" ] && [ "$ssrc" != "$sdest" ]; then
[ -d "$DEST" ] || mkdir "$DEST"
[ -x /sbin/restorecon ] && /sbin/restorecon "$DEST"
if mount -t $FSTYPE "$SRC" "$DEST" $OPTS ; then
echo "Please reboot to complete migration to tmpfs-based /run" > "${DEST}/.run-transition"
return 0
fi
return 1
fi
return 0
}
#
# Migrate a directory to /run and create compatibility symlink or bind
# mount.
#
run_migrate ()
{
OLD=$1
RUN=$2
KERNEL="$(uname -s)"
OPTS=""
case "$KERNEL" in
Linux) FSTYPE=none OPTS="-orw -obind";;
*FreeBSD) FSTYPE=nullfs OPTS="-orw" ;;
GNU) FSTYPE=firmlink ;;
*) FSTYPE=none ;;
esac
# Create absolute symlink if not already present. This is to
# upgrade from older versions which created relative links,
# which are not permitted in policy between top-level
# directories.
if [ -L "$OLD" ] && [ "$(readlink "$OLD")" != "$RUN" ]; then
rm -f "$OLD"
ln -fs "$RUN" "$OLD"
[ -x /sbin/restorecon ] && /sbin/restorecon "$OLD"
fi
# If both directories are the same, we don't need to do
# anything further.
sold="$(/usr/bin/stat -L --format="%d %i" "$OLD" 2>/dev/null || :)"
srun="$(/usr/bin/stat -L --format="%d %i" "$RUN" 2>/dev/null || :)"
if [ -n "$sold" ] && [ "$sold" = "$srun" ]; then
return 0
fi
# Try to remove if a directory. Note this is safe because the
# system is not yet fully up, and nothing is allowed to use
# them yet. If the user explicitly mounted a filesystem here,
# it will be cleaned out, but this would happen later on when
# bootclean runs in any case.
if [ ! -L "$OLD" ] && [ -d "$OLD" ] ; then
rm -fr "$OLD" 2>/dev/null || true
fi
# If removal failed (directory still exists), set up bind mount.
if [ ! -L "$OLD" ] && [ -d "$OLD" ] ; then
if [ "$OLD" != "/tmp" ]; then
log_warning_msg "Filesystem mounted on $OLD; setting up compatibility bind mount."
log_warning_msg "Please remove this mount from /etc/fstab; it is no longer needed, and it is preventing completion of the transition to $RUN."
fi
mount -t $FSTYPE "$RUN" "$OLD" $OPTS
else
# Create symlink if not already present.
if [ -L "$OLD" ] && [ "$(readlink "$OLD")" = "$RUN" ]; then
:
else
rm -f "$OLD"
ln -fs "$RUN" "$OLD"
[ -x /sbin/restorecon ] && /sbin/restorecon "$OLD"
fi
fi
return 0
}
#
# Migrate /etc/mtab to a compatibility symlink
#
mtab_migrate ()
{
# Don't symlink if /proc/mounts does not exist.
if [ ! -r "/proc/mounts" ]; then
return 1
fi
# Create symlink if not already present.
if [ -L "/etc/mtab" ] && [ "$(readlink "/etc/mtab")" = "/proc/mounts" ]; then
:
else
log_warning_msg "Creating compatibility symlink from /etc/mtab to /proc/mounts."
rm -f "/etc/mtab" || return 1
ln -fs "/proc/mounts" "/etc/mtab" || return 1
[ -x /sbin/restorecon ] && /sbin/restorecon "/etc/mtab"
fi
return 0
}
#
# For compatibility, create /var/run and /var/lock symlinks to /run
# and /run/lock, respectively.
#
post_mountall ()
{
# /var/run and /var/lock are now /run and /run/lock,
# respectively. Cope with filesystems being deliberately
# mounted on /var/run and /var/lock. We will create bind
# mounts from /run and /run/lock to /var/run and /var/lock if
# we can't remove the /var/run and /var/lock directories, or
# else simply create symlinks. For example, in the case that
# the user has explicitly mounted filesystems on /var/run or
# /var/lock, we bind mount over the top of them. Where no
# filesystems are mounted, we replace the directory with a
# symlink where possible.
# Cater for systems which have a symlink from /run to /var/run
# for whatever reason. Remove the symlink and replace with a
# directory. The migration logic will then take care of the
# rest. Note that it will take a second boot to fully
# migrate; it should only ever be needed on broken systems.
RAMSHM_ON_DEV_SHM="yes"
if read_fstab_entry "/dev/shm"; then
RAMSHM_ON_DEV_SHM="yes"
fi
if read_fstab_entry "/run/shm"; then
RAMSHM_ON_DEV_SHM="no"
fi
if [ -L /run ]; then
if [ "$(readlink /run)" = "/var/run" ]; then
rm -f /run
mkdir /run
fi
if bind_mount /var/run /run; then
bind_mount /var/lock /run/lock
if [ yes = "$RAMSHM_ON_DEV_SHM" ]; then
run_migrate /run/shm /dev/shm
else
run_migrate /dev/shm /run/shm
fi
fi
else
run_migrate /var/run /run
run_migrate /var/lock /run/lock
if [ yes = "$RAMSHM_ON_DEV_SHM" ]; then
run_migrate /run/shm /dev/shm
else
run_migrate /dev/shm /run/shm
fi
fi
}
# Mount /run
mount_run ()
{
MNTMODE="$1"
KERNEL="$(uname -s)"
if [ "$MNTMODE" = remount ] ; then
case "$KERNEL" in
*FreeBSD)
# tmpfs can't be remounted
return 0
;;
esac
fi
# Needed to determine if root is being mounted read-only.
read_fstab
#
# Get some writable area available before the root is checked
# and remounted. Note that /run may be handed over from the
# initramfs.
#
# If /run/shm is separately mounted, /run can be safely mounted noexec.
RUNEXEC=
if [ yes = "$RAMSHM" ] || read_fstab_entry /run/shm tmpfs; then
RUNEXEC=',noexec'
fi
# TODO: Add -onodev once checkroot no longer creates a device node.
domount "$MNTMODE" tmpfs shmfs /run tmpfs "-onosuid$RUNEXEC$RUN_OPT"
[ -x /sbin/restorecon ] && /sbin/restorecon -r /run
# Make pidfile omit directory for sendsigs
[ -d /run/sendsigs.omit.d ] || mkdir --mode=755 /run/sendsigs.omit.d/
# Make sure we don't get cleaned
touch /run/.tmpfs
}
# Mount /run/lock
mount_lock ()
{
MNTMODE="$1"
KERNEL="$(uname -s)"
if [ "$MNTMODE" = remount ] ; then
case "$KERNEL" in
*FreeBSD)
# tmpfs can't be remounted
return 0
;;
esac
fi
# Make lock directory as the replacement for /var/lock
[ -d /run/lock ] || mkdir --mode=755 /run/lock
[ -x /sbin/restorecon ] && /sbin/restorecon /run/lock
# Now check if there's an entry in /etc/fstab. If there is,
# it overrides the existing RAMLOCK setting.
if read_fstab_entry /run/lock; then
if [ "$MNT_TYPE" = "tmpfs" ] ; then
RAMLOCK="yes"
else
RAMLOCK="no"
fi
fi
NODEV="nodev,"
case "$KERNEL" in
*FreeBSD|GNU) NODEV="" ;;
esac
# Mount /run/lock as tmpfs if enabled. This prevents user DoS
# of /run by filling /run/lock at the expense of using an
# additional tmpfs.
if [ yes = "$RAMLOCK" ]; then
domount "$MNTMODE" tmpfs shmfs /run/lock tmpfs "-o${NODEV}noexec,nosuid$LOCK_OPT"
# Make sure we don't get cleaned
touch /run/lock/.tmpfs
else
chmod "$LOCK_MODE" /run/lock
fi
}
# Mount /run/shm
mount_shm ()
{
MNTMODE="$1"
RAMSHM_ON_DEV_SHM="yes"
SHMDIR="/dev/shm"
if read_fstab_entry "/dev/shm"; then
if [ "$MNTMODE" = "mount_noupdate" ]; then
log_warning_msg "Warning: fstab entry for /dev/shm; should probably be for /run/shm unless working around a bug in the Oracle database"
fi
SHMDIR="/dev/shm"
RAMSHM_ON_DEV_SHM="yes"
fi
if read_fstab_entry "/run/shm"; then
if [ "$MNTMODE" = "mount_noupdate" ] && [ "$RAMSHM_ON_DEV_SHM" = "yes" ]; then
log_warning_msg "Warning: fstab entries for both /dev/shm and /run/shm found; only /run/shm will be used"
fi
SHMDIR="/run/shm"
RAMSHM_ON_DEV_SHM="no"
fi
if [ ! -d "$SHMDIR" ]
then
# Remove possible previous reverse symlink.
if [ -h "$SHMDIR" ] ; then
rm -f "$SHMDIR"
fi
mkdir --mode=755 "$SHMDIR"
[ -x /sbin/restorecon ] && /sbin/restorecon "$SHMDIR"
fi
# Now check if there's an entry in /etc/fstab. If there is,
# it overrides the existing RAMSHM setting.
if read_fstab_entry "$SHMDIR"; then
if [ "$MNT_TYPE" = "tmpfs" ] ; then
RAMSHM="yes"
else
RAMSHM="no"
fi
fi
KERNEL="$(uname -s)"
NODEV="nodev,"
case "$KERNEL" in
*FreeBSD|GNU) NODEV="" ;;
esac
if [ yes = "$RAMSHM" ]; then
domount "$MNTMODE" tmpfs shmfs "$SHMDIR" tmpfs "-onosuid,${NODEV}noexec$SHM_OPT"
# Make sure we don't get cleaned
touch "$SHMDIR"/.tmpfs
else
chmod "$SHM_MODE" "$SHMDIR"
fi
# Migrate early, so /dev/shm is available from the start
if [ "$MNTMODE" = mount_noupdate ] || [ "$MNTMODE" = mount ]; then
if [ yes = "$RAMSHM_ON_DEV_SHM" ]; then
run_migrate /run/shm /dev/shm
else
run_migrate /dev/shm /run/shm
fi
fi
}
#
# Mount /tmp
#
mount_tmp ()
{
MNTMODE="$1"
# If /tmp is a symlink, make sure the linked-to directory exists.
if [ -L /tmp ] && [ ! -d /tmp ]; then
TMPPATH="$(readlink /tmp)"
mkdir -p --mode="${TMP_MODE}" "$TMPPATH"
[ -x /sbin/restorecon ] && /sbin/restorecon "$TMPPATH"
fi
# Disable RAMTMP if there's 64MiB RAM or less. May be
# re-enabled by overflow or read only root, below.
RAM_SIZE="$(ram_size)"
if [ -n "$RAM_SIZE" ] && [ "$RAM_SIZE" -le 65536 ]; then
RAMTMP=no
fi
# If root is read only, default to mounting a tmpfs on /tmp,
# unless one is due to be mounted from fstab.
if [ "$RAMTMP" != "yes" ] && [ rw != "$rootmode" ]; then
# If there's an entry in fstab for /tmp (any
# filesystem type, not just tmpfs), then we don't need
# a tmpfs on /tmp by default.
if read_fstab_entry /tmp ; then
:
else
log_warning_msg "Root filesystem is read-only; mounting tmpfs on /tmp"
RAMTMP="yes"
fi
fi
if [ "$RAMTMP" != "yes" ] && need_overflow_tmp; then
# If there's an entry in fstab for /tmp (any
# filesystem type, not just tmpfs), then we don't need
# a tmpfs on /tmp by default.
if read_fstab_entry /tmp ; then
:
else
log_warning_msg "Root filesystem has insufficient free space; mounting tmpfs on /tmp"
RAMTMP="yes"
fi
fi
# Now check if there's an entry in /etc/fstab. If there is,
# it overrides all the above settings.
if read_fstab_entry /tmp; then
if [ "$MNT_TYPE" = "tmpfs" ] ; then
RAMTMP="yes"
else
RAMTMP="no"
fi
fi
KERNEL="$(uname -s)"
NODEV="nodev,"
case "$KERNEL" in
*FreeBSD|GNU) NODEV="" ;;
esac
# Mount /tmp as tmpfs if enabled.
if [ yes = "$RAMTMP" ]; then
domount "$MNTMODE" tmpfs shmfs /tmp tmpfs "-o${NODEV}nosuid$TMP_OPT"
# Make sure we don't get cleaned
touch /tmp/.tmpfs
else
# When root is still read only, this will fail.
if [ mount_noupdate != "$MNTMODE" ] && [ rw = "$rootmode" ]; then
chmod "$TMP_MODE" /tmp
fi
fi
}
is_fastboot_active() {
if [ -f /fastboot ] ; then
return 0
fi
for cmd in $(cat /proc/cmdline) ; do
case "$cmd" in
fastboot)
return 0
;;
esac
done
return 1
}
# This function does not actually belong here; it is duct-tape solution
# for #901289.
logsave_best_effort () {
if [ -x /sbin/logsave ] ; then
logsave -s "${FSCK_LOGFILE}" "$@"
else
"$@"
fi
}

View File

@ -0,0 +1,185 @@
#! /bin/sh
# Description: Now that TCP/IP is configured, mount the NFS file
# systems in /etc/fstab if needed. If possible,
# start the portmapper before mounting (this is needed for
# Linux 2.1.x and up).
#
# Also mounts SMB filesystems now, so the name of
# this script is getting increasingly inaccurate.
# Skip the mountnfs hook when being triggered by the networking SysV init
# script and instead use the systemd built-in mechanisms to mount remote
# file systems.
# This avoids a deadlock caused by the rpcbind SysV init script depending
# on $network and the $network LSB facility being provided by the networking
# SysV init script.
if [ -d /run/systemd/system ]; then
systemctl list-jobs | grep -q network.target && exit 0
fi
PATH=/sbin:/bin
. /lib/init/vars.sh
. /lib/lsb/init-functions
. /lib/init/mount-functions.sh
set_env() {
# Read through fstab line by line. If it is NFS, set the flag
# for mounting NFS file systems. If any NFS partition is found
# and it not mounted with the nolock option, we start the
# portmapper.
#
# If any sec={krb5,krb5i,krb5p} option is given, or any of the
# file systems are nfs4, we'll need to start rpc.gssd and/or
# rpc.idmapd too; we'll leave that to nfs-common.
start_nfs=no
NETFS=""
NETDEV=""
for file in $(fstab_files); do
if [ -f "$file" ]; then
while read DEV MTPT FSTYPE OPTS REST; do
case "$DEV" in
""|\#*)
continue
;;
esac
case "$OPTS" in
noauto|*,noauto|noauto,*|*,noauto,*)
continue
;;
_netdev|*,_netdev|_netdev,*|*,_netdev,*)
NETDEV=yes
;;
esac
case "$FSTYPE" in
nfs)
# NFS filesystems normally
# require statd and
# portmap. However, if nolock
# is set, portmap and statd
# are not required for this
# file system.
case "$OPTS" in
nolock|*,nolock|nolock,*|*,nolock,*)
# no action
;;
*)
start_nfs=yes
;;
esac
# However, Kerberos requires
# gssd, so start nfs-common
# anyway.
case "$OPTS" in
sec=krb5|*,sec=krb5|sec=krb5,*|*,sec=krb5,*|sec=krb5i|*,sec=krb5i|sec=krb5i,*|*,sec=krb5i,*|sec=krb5p|*,sec=krb5p|sec=krb5p,*|*,sec=krb5p,*)
start_nfs=yes
;;
esac
;;
nfs4)
# NFSv4 requires idmapd, so
# start nfs-common no matter
# what the options are.
start_nfs=yes
;;
smbfs|cifs|coda|ncp|ncpfs|ceph)
;;
*)
FSTYPE=
;;
esac
if [ "$FSTYPE" ]; then
case "$NETFS" in
$FSTYPE|*,$FSTYPE|$FSTYPE,*|*,$FSTYPE,*)
;;
*)
NETFS="$NETFS${NETFS:+,}$FSTYPE"
;;
esac
fi
done < "$file"
fi
done
}
do_start() {
#
# Initialize nfs-common (which starts rpc.statd, rpc.gssd
# and/or rpc.idmapd, and loads the right kernel modules if
# applicable) if we use Kerberos and/or NFSv4 mounts.
#
if [ "$start_nfs" = yes ] && [ -x /etc/init.d/nfs-common ]
then
[ -x /etc/init.d/portmap ] && /etc/init.d/portmap start
[ -x /etc/init.d/rpcbind ] && /etc/init.d/rpcbind start
/etc/init.d/nfs-common start
fi
pre_mountall
if [ "$NETFS" ]
then
mount -a -t$NETFS
fi
if [ "$NETDEV" ]; then
mount -a -O _netdev
fi
post_mountall
}
exit_unless_last_interface() {
ifaces="$(ifquery --list)"
for i in $ifaces ; do
if [ "$i" = "lo" ]; then
continue
fi
if ! ifquery --state $i >/dev/null ; then
msg="if-up.d/mountnfs[$IFACE]: waiting for interface $i before doing NFS mounts"
log_warning_msg "$msg"
exit 0
fi
done
}
# Using 'no !=' instead of 'yes =' to make sure async nfs mounting is
# the default even without a value in /etc/default/rcS
set_env
# Exit immediately and do not claim to wait for the last interface if
# no network file systems are listed in /etc/fstab.
if [ "$start_nfs" = "no" ] && [ ! "$NETFS" ] && [ ! "$NETDEV" ]; then
exit 0
fi
if [ no != "$ASYNCMOUNTNFS" ]; then
# Not for loopback!
[ "$IFACE" != "lo" ] || exit 0
[ "$ADDRFAM" = "inet" ] || [ "$ADDRFAM" = "inet6" ] || exit 0
# Lock around this otherwise insanity may occur
mkdir /var/run/network 2>/dev/null || true
# Wait until all auto interfaces are up before attempting to mount
# network file systems.
exit_unless_last_interface
if mkdir /var/run/network/mountnfs 2>/dev/null ; then
:
else
msg="if-up.d/mountnfs[$IFACE]: lock /var/run/network/mountnfs exist, not mounting"
log_failure_msg "$msg"
# Log if /usr/ is mounted
[ -x /usr/bin/logger ] && /usr/bin/logger -t "if-up.d/mountnfs[$IFACE]" "$msg"
exit 0
fi
on_exit() {
# Clean up lock when script exits, even if it is interrupted
rmdir /var/run/network/mountnfs 2>/dev/null || exit 0
}
trap on_exit EXIT # Enable emergency handler
do_start
elif [ yes = "$FROMINITD" ] ; then
do_start
fi

View File

@ -1,99 +0,0 @@
#!/bin/sh
### BEGIN INIT INFO
# Provides: mountnfs
# Required-Start: $local_fs $network $rpcbind
# Required-Stop:
# Default-Start: S
# Default-Stop:
### END INIT INFO
# . /etc/default/rcS
if [ "$1" = "stop" ]; then
# Avoid mounting if we're shutting down
exit 0
fi
#
# Run in a subshell because of I/O redirection.
#
test -f /etc/fstab && (
#
# Read through fstab line by line. If it is NFS, set the flag
# for mounting NFS filesystems. If any NFS partition is found and it
# not mounted with the nolock option, we start the rpcbind.
#
rpcbind=no
mount_nfs=no
mount_smb=no
mount_ncp=no
mount_cifs=no
while read device mountpt fstype options; do
case "$device" in
""|\#*)
continue
;;
esac
case "$options" in
*noauto*)
continue
;;
esac
if test "$fstype" = nfs
then
mount_nfs=yes
case "$options" in
*nolock*)
;;
*)
rpcbind=yes
;;
esac
fi
if test "$fstype" = smbfs
then
mount_smb=yes
fi
if test "$fstype" = ncpfs
then
mount_ncp=yes
fi
if test "$fstype" = cifs
then
mount_cifs=yes
fi
done
exec 0>&1
if test "$rpcbind" = yes; then
# WRL: Centos precheck: Dont start rpcbind in this init script.
# It is started by a systemd service file.
if test "/etc/centos-release" = no
then
if test -x /usr/sbin/rpcbind
then
service rpcbind status > /dev/null
if [ $? != 0 ]; then
echo -n "Starting rpcbind..."
start-stop-daemon --start --quiet --exec /usr/sbin/rpcbind
sleep 2
fi
fi
fi
fi
if test "$mount_nfs" = yes || test "$mount_smb" = yes || test "$mount_ncp" = yes || test "$mount_cifs" = yes; then
echo "Mounting remote filesystems..."
test "$mount_nfs" = yes && mount -a -t nfs
test "$mount_smb" = yes && mount -a -t smbfs
test "$mount_ncp" = yes && mount -a -t ncpfs
test "$mount_cifs" = yes && mount -a -t cifs
fi
) < /etc/fstab
: exit 0