Blame 0057-nfs-Add-ip-.-and-root-nfs.-parameters-to-internal-dr.patch

Harald Hoyer b94732
From 206345ce9b5eda660d82ce552620edc12db4b2e3 Mon Sep 17 00:00:00 2001
Harald Hoyer b94732
From: Thomas Renninger <trenn@suse.de>
Harald Hoyer b94732
Date: Thu, 11 Dec 2014 15:46:18 +0100
Harald Hoyer b94732
Subject: [PATCH] nfs: Add ip=... and root=nfs... parameters to internal dracut
Harald Hoyer b94732
Harald Hoyer b94732
 cmdline
Harald Hoyer b94732
Harald Hoyer b94732
If the rootfs is an nfs mount, also know as nfsroot, add the correct
Harald Hoyer b94732
parameter to the dracut cmdline.
Harald Hoyer b94732
Harald Hoyer b94732
Signed-off-by: Thomas Renninger <trenn@suse.de>
Harald Hoyer b94732
---
Harald Hoyer b94732
 modules.d/95nfs/module-setup.sh | 44 +++++++++++++++++++++++++++++++++++++++--
Harald Hoyer b94732
 1 file changed, 42 insertions(+), 2 deletions(-)
Harald Hoyer b94732
Harald Hoyer b94732
diff --git a/modules.d/95nfs/module-setup.sh b/modules.d/95nfs/module-setup.sh
Harald Hoyer b94732
index e1340b3..8eb542c 100755
Harald Hoyer b94732
--- a/modules.d/95nfs/module-setup.sh
Harald Hoyer b94732
+++ b/modules.d/95nfs/module-setup.sh
Harald Hoyer b94732
@@ -14,7 +14,6 @@ check() {
Harald Hoyer b94732
         done
Harald Hoyer b94732
         return 255
Harald Hoyer b94732
     }
Harald Hoyer b94732
-
Harald Hoyer b94732
     return 0
Harald Hoyer b94732
 }
Harald Hoyer b94732
 
Harald Hoyer b94732
@@ -29,6 +28,43 @@ installkernel() {
Harald Hoyer b94732
     instmods nfs sunrpc ipv6 nfsv2 nfsv3 nfsv4 nfs_acl nfs_layout_nfsv41_files
Harald Hoyer b94732
 }
Harald Hoyer b94732
 
Harald Hoyer b94732
+cmdline() {
Harald Hoyer b94732
+    local nfs_device
Harald Hoyer b94732
+    local nfs_options
Harald Hoyer b94732
+    local nfs_root
Harald Hoyer b94732
+    local nfs_address
Harald Hoyer b94732
+    local lookup
Harald Hoyer b94732
+    local ifname
Harald Hoyer b94732
+
Harald Hoyer b94732
+    ### nfsroot= ###
Harald Hoyer b94732
+    nfs_device=$(findmnt -t nfs4 -n -o SOURCE /)
Harald Hoyer b94732
+    if [ -n "$nfs_device" ];then
Harald Hoyer b94732
+        nfs_root="root=nfs4:$nfs_device"
Harald Hoyer b94732
+    else
Harald Hoyer b94732
+        nfs_device=$(findmnt -t nfs -n -o SOURCE /)
Harald Hoyer b94732
+        [ -z "$nfs_device" ] && return
Harald Hoyer b94732
+        nfs_root="root=nfs:$nfs_device"
Harald Hoyer b94732
+    fi
Harald Hoyer b94732
+    nfs_options=$(findmnt -t nfs4,nfs -n -o OPTIONS /)
Harald Hoyer b94732
+    [ -n "$nfs_options" ] && nfs_root="$nfs_root:$nfs_options"
Harald Hoyer b94732
+    echo "$nfs_root"
Harald Hoyer b94732
+
Harald Hoyer b94732
+    ### ip= ###
Harald Hoyer b94732
+    if [[ $nfs_device = [0-9]*\.[0-9]*\.[0-9]*.[0-9]* ]] || [[ $nfs_device = \[.*\] ]]; then
Harald Hoyer b94732
+        nfs_address="$nfs_device"
Harald Hoyer b94732
+    else
Harald Hoyer b94732
+        lookup=$(host $(echo ${nfs_device%%:*})| head -n1)
Harald Hoyer b94732
+        nfs_address=${lookup##* }
Harald Hoyer b94732
+    fi
Harald Hoyer b94732
+    ifname=$(ip -o route get to $nfs_address | sed -n 's/.*dev \([^ ]*\).*/\1/p')
Harald Hoyer b94732
+    if [ -e /sys/class/net/$ifname/address ] ; then
Harald Hoyer b94732
+        ifmac=$(cat /sys/class/net/$ifname/address)
Harald Hoyer b94732
+        printf 'ifname=%s:%s ' ${ifname} ${ifmac}
Harald Hoyer b94732
+    fi
Harald Hoyer b94732
+
Harald Hoyer b94732
+    printf 'ip=%s:static\n' ${ifname}
Harald Hoyer b94732
+}
Harald Hoyer b94732
+
Harald Hoyer b94732
 # called by dracut
Harald Hoyer b94732
 install() {
Harald Hoyer b94732
     local _i
Harald Hoyer b94732
@@ -37,6 +73,11 @@ install() {
Harald Hoyer b94732
         mount.nfs4 umount rpc.idmapd sed /etc/netconfig
Harald Hoyer b94732
     inst_multiple /etc/services /etc/nsswitch.conf /etc/rpc /etc/protocols /etc/idmapd.conf
Harald Hoyer b94732
 
Harald Hoyer b94732
+    if [[ $hostonly_cmdline == "yes" ]]; then
Harald Hoyer b94732
+        local _netconf="$(cmdline)"
Harald Hoyer b94732
+        [[ $_netconf ]] && printf "%s\n" "$_netconf" >> "${initdir}/etc/cmdline.d/95nfs.conf"
Harald Hoyer b94732
+    fi
Harald Hoyer b94732
+
Harald Hoyer b94732
     if [ -f /lib/modprobe.d/nfs.conf ]; then
Harald Hoyer b94732
         inst_multiple /lib/modprobe.d/nfs.conf
Harald Hoyer b94732
     else
Harald Hoyer b94732
@@ -75,4 +116,3 @@ install() {
Harald Hoyer b94732
         && chown rpc.rpc "$initdir/var/lib/rpcbind"
Harald Hoyer b94732
     dracut_need_initqueue
Harald Hoyer b94732
 }
Harald Hoyer b94732
-