]> git.ipfire.org Git - thirdparty/dracut.git/commitdiff
netroot: Move writing ifcfg config files to a pre-pivot script
authorPhilippe Seewer <philippe.seewer@bfh.ch>
Tue, 16 Jun 2009 09:58:16 +0000 (11:58 +0200)
committerPhilippe Seewer <philippe.seewer@bfh.ch>
Wed, 17 Jun 2009 06:37:39 +0000 (08:37 +0200)
This is mostly about style: Doing stuff after a successful mount
should go into pre-pivot.

In addition this corrects the case where the used netif is not eth0

modules.d/40network/install
modules.d/40network/netroot
modules.d/40network/write-ifcfg.sh [new file with mode: 0755]

index 32091b4b159b073d4f6644488f591e6d11749acb..2e381e284b8d2b19000f2fbc41ba1862446b5f73 100755 (executable)
@@ -18,4 +18,9 @@ instmods ecb arc4
 inst_rules "$moddir/60-net.rules"
 inst_hook cmdline 99 "$moddir/dhcp-fallback.sh"
 inst_hook pre-pivot 10 "$moddir/kill-dhclient.sh"
+
+# TODO ifcfg config style is redhat specific, this should probably
+# go into its own module at one time
+inst_hook pre-pivot 20 "$moddir/write-ifcfg.sh"
+
 mkdir -p "${initdir}/var/run"
index 31c899b6fbc10f9a6f41ad310264cf3798ac5201..0d8f681a5790daf36ebfc08f05d53447b0337e12 100755 (executable)
@@ -52,22 +52,8 @@ if $handler $netif $netroot $NEWROOT; then
     [ -f /tmp/dhclient.$netif.lease ] &&    cp /tmp/dhclient.$netif.lease    /tmp/net.$netif.lease
     [ -f /tmp/dhclient.$netif.dhcpopts ] && cp /tmp/dhclient.$netif.dhcpopts /tmp/net.$netif.dhcpopts
     [ -f /tmp/dhclient.$netif.override ] && cp /tmp/dhclient.$netif.override /tmp/net.$netif.override
-    cat /sys/class/net/eth0/address > /tmp/net.$netif.hwaddr
-    echo "# Generated by dracut initrd" > /tmp/net.$netif.ifcfg
-    echo "DEVICE=$netif" >> /tmp/net.$netif.ifcfg
-    echo "HWADDR=$(cat /sys/class/net/eth0/address)" >> /tmp/net.$netif.ifcfg
-    echo "TYPE=Ethernet" >> /tmp/net.$netif.ifcfg
-    echo "ONBOOT=yes" >> /tmp/net.$netif.ifcfg
-    if [ -f /tmp/net.$netif.lease ]; then
-        echo "BOOTPROTO=dhcp" >> /tmp/net.$netif.ifcfg
-    else
-        echo "BOOTPROTO=none" >> /tmp/net.$netif.ifcfg
-        # Static: XXX Implement me!
-        #IPADDR=172.16.101.1
-        #NETMASK=255.255.255.0
-        #DNS1=1.2.3.4
-        #DNS2=1.2.3.5
-        #GATEWAY=172.16.101.254
-    fi
+
+    # Save used netif for later use
+    echo $netif > /tmp/net.bootdev
 fi
 exit 0
diff --git a/modules.d/40network/write-ifcfg.sh b/modules.d/40network/write-ifcfg.sh
new file mode 100755 (executable)
index 0000000..2a88b3b
--- /dev/null
@@ -0,0 +1,24 @@
+#!/bin/sh
+
+# Don't write anything if we don't know our bootdev
+[ -f /tmp/net.bootdev ] || return 1
+
+read netif < /tmp/net.bootdev
+
+cat /sys/class/net/$netif/address > /tmp/net.$netif.hwaddr
+echo "# Generated by dracut initrd" > /tmp/net.$netif.ifcfg
+echo "DEVICE=$netif" >> /tmp/net.$netif.ifcfg
+echo "HWADDR=$(cat /sys/class/net/$netif/address)" >> /tmp/net.$netif.ifcfg
+echo "TYPE=Ethernet" >> /tmp/net.$netif.ifcfg
+echo "ONBOOT=yes" >> /tmp/net.$netif.ifcfg
+if [ -f /tmp/net.$netif.lease ]; then
+    echo "BOOTPROTO=dhcp" >> /tmp/net.$netif.ifcfg
+else
+    echo "BOOTPROTO=none" >> /tmp/net.$netif.ifcfg
+    # Static: XXX Implement me!
+    #IPADDR=172.16.101.1
+    #NETMASK=255.255.255.0
+    #DNS1=1.2.3.4
+    #DNS2=1.2.3.5
+    #GATEWAY=172.16.101.254
+fi