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 command -v getarg >/dev/null || . /lib/dracut-lib.sh
7 command -v setup_net >/dev/null || . /lib/net-lib.sh
12 # [ ! -z $2 ] means this is for manually bringing up network
13 # instead of real netroot; If It's called without $2, then there's
14 # no sense in doing something if no (net)root info is available
15 # or root is already there
16 [ -d $NEWROOT/proc ] && exit 0
17 [ -z "$netroot" ] && exit 1
19 # Set or override primary interface
21 [ -e "/tmp/net.bootdev" ] && read netif < /tmp/net.bootdev
23 # Figure out the handler for root=dhcp by recalling all netroot cmdline
24 # handlers when this is not called from manually network bringing up.
26 if [ "$netroot" = "dhcp" ] || [ "$netroot" = "dhcp6" ] ; then
27 # Unset root so we can check later
31 [ -e /tmp/dhclient.$netif.dhcpopts ] && . /tmp/dhclient.$netif.dhcpopts
33 # If we have a specific bootdev with no dhcpoptions or empty root-path,
34 # we die. Otherwise we just warn
35 if [ -z "$new_root_path" ] ; then
36 [ -n "$BOOTDEV" ] && die "No dhcp root-path received for '$BOOTDEV'"
37 warn "No dhcp root-path received for '$BOOTDEV' trying other interfaces if available"
41 # Set netroot to new_root_path, so cmdline parsers don't call
42 netroot=$new_root_path
45 for f in $hookdir/cmdline/90*.sh; do
46 [ -f "$f" ] && . "$f";
52 # Check: do we really know how to handle (net)root?
53 [ -z "$root" ] && die "No or empty root= argument"
54 [ -z "$rootok" ] && die "Don't know how to handle 'root=$root'"
56 handler=${netroot%%:*}
58 handler=$(command -v ${handler}root)
59 if [ -z "$netroot" ] || [ ! -e "$handler" ] ; then
60 die "No handler for netroot type '$netroot'"
64 # Source netroot hooks before we start the handler
65 source_hook netroot $netif
67 # Run the handler; don't store the root, it may change from device to device
68 # XXX other variables to export?
69 if $handler $netif $netroot $NEWROOT; then
70 # Network rootfs mount successful - save interface info for ifcfg etc.