112 lines
3.9 KiB
Bash
112 lines
3.9 KiB
Bash
# vim: set ft=sh:
|
|
run_hook() {
|
|
local line i net_mac bootif_mac bootif_dev defaultrootpath defaultserver
|
|
# These variables will be parsed from /tmp/net-*.conf generated by ipconfig
|
|
local DEVICE
|
|
local IPV4ADDR IPV4BROADCAST IPV4NETMASK IPV4GATEWAY IPV4DNS0 IPV4DNS1
|
|
local HOSTNAME DNSDOMAIN NISDOMAIN ROOTSERVER ROOTPATH
|
|
local filename
|
|
# /tmp/net-*.conf
|
|
|
|
if [ -z "${ip}" -a -n "${nfsaddrs}" ]; then
|
|
ip="${nfsaddrs}"
|
|
fi
|
|
|
|
if [ -n "${ip}" ]; then
|
|
if [ -n "${BOOTIF}" ]; then
|
|
bootif_mac=${BOOTIF#01-}
|
|
bootif_mac=${bootif_mac//-/:}
|
|
for i in /sys/class/net/*/address; do
|
|
read net_mac < ${i}
|
|
if [ "${bootif_mac}" == "${net_mac}" ]; then
|
|
bootif_dev=${i#/sys/class/net/}
|
|
bootif_dev=${bootif_dev%/address}
|
|
break
|
|
fi
|
|
done
|
|
ip="${ip}::${bootif_dev}"
|
|
fi
|
|
|
|
# setup network and save some values
|
|
ipconfig "ip=${ip}"
|
|
|
|
for conf in /tmp/net-*.conf; do
|
|
[ -f "$conf" ] && . "$conf"
|
|
done
|
|
|
|
# calculate nfs_server, nfs_path and nfs_option for later nfs mount
|
|
if [ "${root}" = "/dev/nfs" -o "${nfsroot}" != "" ]; then
|
|
# parse ROOTPATH if defined by dhcp server
|
|
if [ -n "${ROOTPATH}" ]; then
|
|
line="${ROOTPATH}"
|
|
nfs_server="${line%%:*}"
|
|
[ "${nfs_server}" = "${line}" ] && nfs_server="${ROOTSERVER}"
|
|
defaultserver="${nfs_server}"
|
|
line="${line#*:}"
|
|
nfs_path="${line}"
|
|
defaultrootpath="${nfs_path}"
|
|
else
|
|
# define a default ROOTPATH
|
|
if [ "${ROOTPATH}" = "" ]; then
|
|
defaultrootpath="/tftpboot/${IPV4ADDR}"
|
|
fi
|
|
fi
|
|
|
|
# parse nfsroot if present (overrides ROOTPATH)
|
|
if [ -n "${nfsroot}" ]; then
|
|
line="${nfsroot}"
|
|
nfs_server="${line%%:*}"
|
|
[ -z "${nfs_server}" ] && nfs_server="${defaultserver}"
|
|
line="${line#*:}"
|
|
nfs_path="${line%%,*}"
|
|
line="${line#"${nfs_path}"}"
|
|
[ -z "${nfs_path}" ] && nfs_path="${defaultrootpath}"
|
|
nfs_option="${line#","}"
|
|
fi
|
|
|
|
# ensure root and filesystem type are set proper for nfs boot
|
|
root="/dev/nfs"
|
|
rootfstype="nfs"
|
|
|
|
echo "NFS-Mount: ${nfs_server}:${nfs_path}"
|
|
|
|
# set mount handler for NFS
|
|
mount_handler="nfs_mount_handler"
|
|
fi
|
|
fi
|
|
}
|
|
|
|
nfs_mount_handler() {
|
|
if [ -z "$nfs_server" -o -z "$nfs_path" ]; then
|
|
err "Unable to mount root filesystem over NFS: wrong parameters."
|
|
echo "You are being dropped to a recovery shell"
|
|
echo " Type 'exit' to try and continue booting"
|
|
launch_interactive_shell
|
|
msg "Trying to continue (this will most likely fail) ..."
|
|
fi
|
|
|
|
# nfsmount avoids problems with lockd for v2 and v3 but does not support v4;
|
|
# to support v4 roots, examine mount options for a v4 version spec and use
|
|
# the ordinary mount program. v4 doesn't need lockd for file locking anyway.
|
|
mount_cmd=
|
|
case "${nfs_option}" in
|
|
nfsvers=4*|*,nfsvers=4*|vers=4*|*,vers=4*)
|
|
command -v mount.nfs4 >/dev/null 2>&1 && mount_cmd="mount -t nfs4"
|
|
;;
|
|
esac
|
|
|
|
# musl installations may not offer nfsmount, so fall back to mount.nfs
|
|
# when nfsmount does not exist. This probably requires a nolock mount.
|
|
if [ -z "${mount_cmd}" ]; then
|
|
if command -v nfsmount >/dev/null 2>&1; then
|
|
mount_cmd=nfsmount
|
|
else
|
|
mount_cmd="mount -t nfs"
|
|
fi
|
|
fi
|
|
|
|
${mount_cmd} ${nfs_option:+-o ${nfs_option}} "${nfs_server}:${nfs_path}" "$1"
|
|
}
|
|
|
|
# vim: set ft=sh ts=4 sw=4 et:
|