network: don't use "ifup -m"
[dracut.git] / modules.d / 95nfs / parse-nfsroot.sh
blob2200cadd575548fc1d6fa96b163a79db567c5ff9
1 #!/bin/sh
3 # Preferred format:
4 # root=nfs[4]:[server:]path[:options]
6 # This syntax can come from DHCP root-path as well.
8 # Legacy format:
9 # root=/dev/nfs nfsroot=[server:]path[,options]
11 # In Legacy root=/dev/nfs mode, if the 'nfsroot' parameter is not given
12 # on the command line or is empty, the dhcp root-path is used as
13 # [server:]path[:options] or the default "/tftpboot/%s" will be used.
15 # If server is unspecified it will be pulled from one of the following
16 # sources, in order:
17 # static ip= option on kernel command line
18 # DHCP next-server option
19 # DHCP server-id option
20 # DHCP root-path option
22 # NFSv4 is only used if explicitly requested with nfs4: prefix, otherwise
23 # NFSv3 is used.
26 type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh
28 # This script is sourced, so root should be set. But let's be paranoid
29 [ -z "$root" ] && root=$(getarg root=)
30 [ -z "$nfsroot" ] && nfsroot=$(getarg nfsroot=)
32 [ -n "$netroot" ] && oldnetroot="$netroot"
34 # netroot= cmdline argument must be ignored, but must be used if
35 # we're inside netroot to parse dhcp root-path
36 if [ -n "$netroot" ] ; then
37 for n in $(getargs netroot=); do
38 [ "$n" = "$netroot" ] && break
39 done
40 if [ "$n" = "$netroot" ]; then
41 warn "Ignoring netroot argument for NFS"
42 netroot=$root
44 else
45 netroot=$root;
48 # LEGACY: nfsroot= is valid only if root=/dev/nfs
49 if [ -n "$nfsroot" ] ; then
50 # @deprecated
51 warn "Argument nfsroot is deprecated and might be removed in a future release. See 'man dracut.kernel' for more information."
52 if [ "$(getarg root=)" != "/dev/nfs" ]; then
53 die "Argument nfsroot only accepted for legacy root=/dev/nfs"
55 netroot=nfs:$nfsroot;
58 case "$netroot" in
59 /dev/nfs) netroot=nfs;;
60 /dev/*)
61 if [ -n "$oldnetroot" ]; then
62 netroot="$oldnetroot"
63 else
64 unset netroot
66 return
68 # LEGACY: root=<server-ip>:/<path
69 [0-9]*:/*|[0-9]*\.[0-9]*\.[0-9]*[!:]|/*)
70 netroot=nfs:$netroot;;
71 esac
73 # Continue if nfs
74 case "${netroot%%:*}" in
75 nfs|nfs4|/dev/nfs);;
77 if [ -n "$oldnetroot" ]; then
78 netroot="$oldnetroot"
79 else
80 unset netroot
82 return
84 esac
86 # Check required arguments
88 if nfsdomain=$(getarg rd.nfs.domain -d rd_NFS_DOMAIN); then
89 if [ -f /etc/idmapd.conf ]; then
90 sed -i -e \
91 "s/^[[:space:]#]*Domain[[:space:]]*=.*/Domain = $nfsdomain/g" \
92 /etc/idmapd.conf
94 # and even again after the sed, in case it was not yet specified
95 echo "Domain = $nfsdomain" >> /etc/idmapd.conf
98 nfsroot_to_var $netroot
99 [ "$path" = "error" ] && die "Argument nfsroot must contain a valid path!"
101 # Set fstype, might help somewhere
102 fstype=${nfs#/dev/}
104 # Rewrite root so we don't have to parse this uglyness later on again
105 netroot="$fstype:$server:$path:$options"
107 # If we don't have a server, we need dhcp
108 if [ -z "$server" ] ; then
109 DHCPORSERVER="1"
112 # Done, all good!
113 rootok=1
115 # Shut up init error check or make sure that block parser wont get
116 # confused by having /dev/nfs[4]
117 root="$fstype"
119 echo '[ -e $NEWROOT/proc ]' > $hookdir/initqueue/finished/nfsroot.sh