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
master
Philippe Seewer 2009-06-16 11:58:16 +02:00
parent a55d10c05c
commit 9f73fedfd1
3 changed files with 32 additions and 17 deletions

View File

@ -18,4 +18,9 @@ instmods ecb arc4
inst_rules "$moddir/60-net.rules" inst_rules "$moddir/60-net.rules"
inst_hook cmdline 99 "$moddir/dhcp-fallback.sh" inst_hook cmdline 99 "$moddir/dhcp-fallback.sh"
inst_hook pre-pivot 10 "$moddir/kill-dhclient.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" mkdir -p "${initdir}/var/run"

View File

@ -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.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.dhcpopts ] && cp /tmp/dhclient.$netif.dhcpopts /tmp/net.$netif.dhcpopts
[ -f /tmp/dhclient.$netif.override ] && cp /tmp/dhclient.$netif.override /tmp/net.$netif.override [ -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 # Save used netif for later use
echo "DEVICE=$netif" >> /tmp/net.$netif.ifcfg echo $netif > /tmp/net.bootdev
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
fi fi
exit 0 exit 0

View File

@ -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