From 9f73fedfd147b328423c4dcda8588799a4bc47bf Mon Sep 17 00:00:00 2001 From: Philippe Seewer Date: Tue, 16 Jun 2009 11:58:16 +0200 Subject: [PATCH] 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 --- modules.d/40network/install | 5 +++++ modules.d/40network/netroot | 20 +++----------------- modules.d/40network/write-ifcfg.sh | 24 ++++++++++++++++++++++++ 3 files changed, 32 insertions(+), 17 deletions(-) create mode 100755 modules.d/40network/write-ifcfg.sh diff --git a/modules.d/40network/install b/modules.d/40network/install index 32091b4b..2e381e28 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 31c899b6..0d8f681a 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 00000000..2a88b3be --- /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