From: Philippe Seewer Date: Tue, 16 Jun 2009 09:58:16 +0000 (+0200) Subject: netroot: Move writing ifcfg config files to a pre-pivot script X-Git-Tag: 0.1~48 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=9f73fedfd147b328423c4dcda8588799a4bc47bf;p=thirdparty%2Fdracut.git netroot: Move writing ifcfg config files to a pre-pivot script 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 --- diff --git a/modules.d/40network/install b/modules.d/40network/install index 32091b4b1..2e381e284 100755 --- a/modules.d/40network/install +++ b/modules.d/40network/install @@ -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" diff --git a/modules.d/40network/netroot b/modules.d/40network/netroot index 31c899b6f..0d8f681a5 100755 --- a/modules.d/40network/netroot +++ b/modules.d/40network/netroot @@ -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 index 000000000..2a88b3bea --- /dev/null +++ b/modules.d/40network/write-ifcfg.sh @@ -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