From: David Dillow Date: Sun, 7 Jun 2009 21:17:48 +0000 (-0400) Subject: NFS root: add support for default root path and %s substitution X-Git-Tag: 0.1~86 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=abe9ccc89a96bc61bc2e9d3169341821393da6da;p=thirdparty%2Fdracut.git NFS root: add support for default root path and %s substitution This implements a default path of /tftpboot/%s if no path is provided, and adds host name substitution for %s, with a fall back to the IP address, as provided by the kernel's nfsroot handling. The test suite is updated to test this functionality. --- diff --git a/modules.d/95nfs/nfs-netroot.sh b/modules.d/95nfs/nfs-netroot.sh index 8d552e9e6..365d3940c 100755 --- a/modules.d/95nfs/nfs-netroot.sh +++ b/modules.d/95nfs/nfs-netroot.sh @@ -34,6 +34,7 @@ if [ "$root" = "dhcp" -o "$root" = "nfs" -o "$root" = "nfs4" ]; then if check_occurances "$new_root_path" ':' 0; then root="$nfsver::$new_root_path:" fi ;; + '') root="$nfsver:::" ;; esac fi diff --git a/modules.d/95nfs/nfsroot b/modules.d/95nfs/nfsroot index da002c53d..cd3bc7cdd 100755 --- a/modules.d/95nfs/nfsroot +++ b/modules.d/95nfs/nfsroot @@ -21,6 +21,20 @@ nfsserver=${root%%:*}; root=${root#*:} nfspath=${root%%:*} flags=${root#*:} +[ -z "$nfspath" ] && nfspath=/tftpboot/%s + +# Kernel replaces first %s with host name, and falls back to the ip address +# if it isn't set. Only the first %s is substituted. +# +if [ "${nfspath#*%s}" != "$nfspath" ]; then + ip=$(ip -o -f inet addr show $netif) + ip=${ip%%/*} + ip=${ip##* } + read node < /proc/sys/kernel/hostname + [ "$node" = "(none)" ] && node=$ip + nfspath=${nfspath%%%s*}$node${nfspath#*%s} +fi + # look through the flags and see if any are overridden by the command line # Append a , so we know we terminate flags=${flags}, diff --git a/test/TEST-20-NFS/exports b/test/TEST-20-NFS/exports index 27018771f..95619e712 100644 --- a/test/TEST-20-NFS/exports +++ b/test/TEST-20-NFS/exports @@ -1,2 +1,5 @@ /nfs 192.168.50.0/24(ro,fsid=0,insecure,no_subtree_check,no_root_squash) /nfs/client 192.168.50.0/24(ro,insecure,no_subtree_check,no_root_squash) +/nfs/nfs3-5 192.168.50.0/24(ro,insecure,no_subtree_check,no_root_squash,nohide) +/nfs/ip/192.168.50.101 192.168.50.0/24(ro,insecure,no_subtree_check,no_root_squash,nohide) +/nfs/tftpboot/nfs4-5 192.168.50.0/24(ro,insecure,no_subtree_check,no_root_squash,nohide) diff --git a/test/TEST-20-NFS/server-init b/test/TEST-20-NFS/server-init index 67af8fa9d..ed7e43ecc 100755 --- a/test/TEST-20-NFS/server-init +++ b/test/TEST-20-NFS/server-init @@ -10,6 +10,9 @@ ip addr add 192.168.50.1/24 dev eth0 ip addr add 192.168.50.2/24 dev eth0 ip addr add 192.168.50.3/24 dev eth0 ip link set eth0 up +mount --bind /nfs/client /nfs/nfs3-5 +mount --bind /nfs/client /nfs/ip/192.168.50.101 +mount --bind /nfs/client /nfs/tftpboot/nfs4-5 modprobe sunrpc mount -t rpc_pipefs sunrpc /var/lib/nfs/rpc_pipefs rpcbind diff --git a/test/TEST-20-NFS/test.sh b/test/TEST-20-NFS/test.sh index 4a997c46b..658336669 100755 --- a/test/TEST-20-NFS/test.sh +++ b/test/TEST-20-NFS/test.sh @@ -137,6 +137,15 @@ test_nfsv3() { client_test "NFSv3 root=nfs nfsroot=/nfs/client" 52:54:00:12:34:04 \ "root=nfs nfsroot=/nfs/client" 192.168.50.1 -wsize=4096 || return 1 + client_test "NFSv3 root=nfs nfsroot=/nfs/%s" 52:54:00:12:34:04 \ + "root=nfs nfsroot=/nfs/%s" 192.168.50.1 -wsize=4096 || return 1 + + client_test "NFSv3 root=nfs nfsroot=/nfs/ip/%s no host name (use IP)" \ + 52:54:00:12:34:7f \ + "root=nfs nfsroot=/nfs/ip/%s \ + ip=192.168.50.101:192.168.50.1::255.255.255.0::eth0:static" \ + 192.168.50.1 -wsize=4096 || return 1 + client_test "NFSv3 root=nfs nfsroot=/nfs/client,wsize=4096" \ 52:54:00:12:34:04 "root=nfs nfsroot=/nfs/client,wsize=4096" \ 192.168.50.1 wsize=4096 || return 1 @@ -185,6 +194,11 @@ test_nfsv4() { 52:54:00:12:34:84 "root=nfs4 nfsroot=/client,wsize=4096" \ 192.168.50.1 wsize=4096 || return 1 + # This one only works with NFSv4 in the test suite -- NFSv3 needs + # a /nfs prefix due to our server configuration + client_test "NFSv4 root=nfs4" 52:54:00:12:34:84 \ + "root=nfs4" 192.168.50.1 -wsize=4096 || return 1 + client_test "NFSv4 root=nfs4 DHCP path,options" \ 52:54:00:12:34:85 "root=nfs4" 192.168.50.1 wsize=4096 || return 1 @@ -267,6 +281,10 @@ test_setup() { ldconfig -n -r "$initdir" /lib* /usr/lib* ) + mkdir -p mnt/nfs/nfs3-5 + mkdir -p mnt/nfs/ip/192.168.50.101 + mkdir -p mnt/nfs/tftpboot/nfs4-5 + sudo umount mnt rm -fr mnt