]>
git.ipfire.org Git - thirdparty/dracut.git/blob - modules.d/40network/netroot.sh
2 # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
3 # ex: ts=8 sw=4 sts=4 et filetype=sh
5 PATH
=/usr
/sbin
:/usr
/bin
:/sbin
:/bin
6 type getarg
>/dev
/null
2>&1 || .
/lib
/dracut-lib.sh
11 # Huh? No interface config?
12 [ ! -e /tmp
/net.
$1.up
] && exit 1
14 # [ ! -z $2 ] means this is for manually bringing up network
15 # instead of real netroot; If It's called without $2, then there's
16 # no sense in doing something if no (net)root info is available
17 # or root is already there
18 [ -e /tmp
/root.info
] ||
exit 1
21 [ -d $NEWROOT/proc
] && exit 0
22 [ -z "$netroot" ] && exit 1
25 # Let's see if we have to wait for other interfaces
26 # Note: exit works just fine, since the last interface to be
27 # online'd should see all files
28 [ -e "/tmp/net.ifaces" ] && read IFACES
< /tmp
/net.ifaces
29 for iface
in $IFACES ; do
30 [ -e /tmp
/net.
$iface.up
] ||
exit 1
33 # Set or override primary interface
35 [ -e "/tmp/net.bootdev" ] && read netif
< /tmp
/net.bootdev
37 if [ -e /tmp
/net.
$netif.manualup
]; then
38 rm -f /tmp
/net.
$netif.manualup
41 # Figure out the handler for root=dhcp by recalling all netroot cmdline
42 # handlers when this is not called from manually network bringing up.
44 if [ "$netroot" = "dhcp" ] ||
[ "$netroot" = "dhcp6" ] ; then
45 # Unset root so we can check later
49 [ -e /tmp
/dhclient.
$netif.dhcpopts
] && .
/tmp
/dhclient.
$netif.dhcpopts
51 # If we have a specific bootdev with no dhcpoptions or empty root-path,
52 # we die. Otherwise we just warn
53 if [ -z "$new_root_path" ] ; then
54 [ -n "$BOOTDEV" ] && die
"No dhcp root-path received for '$BOOTDEV'"
55 warn
"No dhcp root-path received for '$BOOTDEV' trying other interfaces if available"
59 # Set netroot to new_root_path, so cmdline parsers don't call
60 netroot
=$new_root_path
63 for f
in $hookdir/cmdline
/90*.sh
; do
64 [ -f "$f" ] && .
"$f";
70 # Check: do we really know how to handle (net)root?
71 [ -z "$root" ] && die
"No or empty root= argument"
72 [ -z "$rootok" ] && die
"Don't know how to handle 'root=$root'"
74 handler
=${netroot%%:*}
76 handler
=$
(command -v ${handler}root
)
77 if [ -z "$netroot" ] ||
[ ! -e "$handler" ] ; then
78 die
"No handler for netroot type '$netroot'"
82 # We're here, so we can assume that upping interfaces is now ok
83 [ -z "$IFACES" ] && IFACES
="$netif"
84 for iface
in $IFACES ; do
88 [ -e /tmp
/net.
$netif.gw
] && .
/tmp
/net.
$netif.gw
89 [ -e /tmp
/net.
$netif.hostname
] && .
/tmp
/net.
$netif.hostname
90 [ -e /tmp
/net.
$netif.resolv.conf
] && cp -f /tmp
/net.
$netif.resolv.conf
/etc
/resolv.conf
92 # Load interface options
93 [ -e /tmp
/net.
$netif.override
] && .
/tmp
/net.
$netif.override
94 [ -e /tmp
/dhclient.
$netif.dhcpopts
] && .
/tmp
/dhclient.
$netif.dhcpopts
96 # Handle STP Timeout: arping the default router if root server is
97 # unknown or not local, or if not available the root server.
98 # Note: This assumes that if no router is present the
99 # root server is on the same subnet.
101 # TODO There's some netroot variants that don't (yet) have their
104 # Get router IP if set
105 [ -n "$new_routers" ] && gw_ip
=${new_routers%%,*}
106 [ -n "$gw" ] && gw_ip
=$gw
107 # Get root server IP if set
108 if [ -n "$netroot" ]; then
112 [0-9]*\.
[0-9]*\.
[0-9]*\.
[0-9]*) netroot_ip
=$dummy;;
115 # Default arping dest to router
117 # Change to arping root server if appropriate
118 if [ -n "$netroot_ip" ]; then
119 if [ -z "$dest" ]; then
120 # no gateway so check root server
123 r
=$
(ip route get
"$netroot_ip")
124 if ! strstr
"$r" ' via ' ; then
125 # local root server, so don't arping gateway
130 if [ -n "$dest" ] && ! arping
-q -f -w 60 -I $netif $dest ; then
131 dinfo
"Resolving $dest via ARP on $netif failed"
134 # exit in case manually bring up network
135 [ -n "$2" ] && exit 0
137 # Source netroot hooks before we start the handler
138 source_all
$hookdir/netroot
140 # Run the handler; don't store the root, it may change from device to device
141 # XXX other variables to export?
142 if $handler $netif $netroot $NEWROOT; then
143 # Network rootfs mount successful
144 for iface
in $IFACES ; do
145 [ -f /tmp
/dhclient.
$iface.lease
] && cp /tmp
/dhclient.
$iface.lease
/tmp
/net.
$iface.lease
146 [ -f /tmp
/dhclient.
$iface.dhcpopts
] && cp /tmp
/dhclient.
$iface.dhcpopts
/tmp
/net.
$iface.dhcpopts
149 # Save used netif for later use
150 [ ! -f /tmp
/net.ifaces
] && echo $netif > /tmp
/net.ifaces
152 warn
"Mounting root via '$netif' failed"
153 # If we're trying with multiple interfaces, put that one down.
154 # ip down/flush ensures that routeing info goes away as well
155 if [ -z "$BOOTDEV" ] ; then
156 ip link
set $netif down
157 ip addr flush dev
$netif
158 echo "#empty" > /etc
/resolv.conf