See commit messages for rationale. (follow-up of https://www.redhat.com/archives/anaconda-devel-list/2012-June/msg00438.html)
Default ifcfg files used to be written in loader. We need to write them before systemd runs NM so that we control which devices are brought up. NM activates default connections for devices with missing ifcfg files. This should also fix newui traceback caused by missing ifcfg files because Network class is not instantiated in some cases. --- dracut/anaconda-write-default-ifcfg.sh | 20 ++++++++++++++++++++ dracut/module-setup.sh | 1 + pyanaconda/network.py | 27 +++------------------------ 3 files changed, 24 insertions(+), 24 deletions(-) create mode 100755 dracut/anaconda-write-default-ifcfg.sh
diff --git a/dracut/anaconda-write-default-ifcfg.sh b/dracut/anaconda-write-default-ifcfg.sh new file mode 100755 index 0000000..e51de25 --- /dev/null +++ b/dracut/anaconda-write-default-ifcfg.sh @@ -0,0 +1,20 @@ +#!/bin/sh +# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- +# ex: ts=8 sw=4 sts=4 et filetype=sh + +for interface in /sys/class/net/*; do + + ifname=${interface##*/} + + if [ ! -e /run/initramfs/state/etc/sysconfig/network-scripts/ifcfg-$ifname ]; then + { + echo "# Generated by anconda dracut initrd module" + echo "DEVICE=$ifname" + echo "BOOTPROTO=dhcp" + echo "ONBOOT=no" + echo "HWADDR=$(cat /sys/class/net/$ifname/address)" + echo "UUID=$(cat /proc/sys/kernel/random/uuid)" + } > /run/initramfs/state/etc/sysconfig/network-scripts/ifcfg-$ifname + fi + +done diff --git a/dracut/module-setup.sh b/dracut/module-setup.sh index 39ecc58..227b3de 100755 --- a/dracut/module-setup.sh +++ b/dracut/module-setup.sh @@ -28,6 +28,7 @@ install() { inst_hook pre-trigger 40 "$moddir/anaconda-udevprop.sh" inst_hook initqueue/online 80 "$moddir/anaconda-netroot.sh" inst "$moddir/anaconda-diskroot" "/sbin/anaconda-diskroot" + inst_hook pre-pivot 90 "$moddir/anaconda-write-default-ifcfg.sh" inst_hook pre-pivot 99 "$moddir/anaconda-copy-ks.sh" # kickstart parsing, WOOOO inst_hook initqueue/online 10 "$moddir/fetch-kickstart-net.sh" diff --git a/pyanaconda/network.py b/pyanaconda/network.py index 103816e..984663b 100644 --- a/pyanaconda/network.py +++ b/pyanaconda/network.py @@ -242,29 +242,6 @@ class NetworkDevice(IfcfgFile):
return s
- # anaconda doesn't actually need this configuration, but if we don't write - # it to the installed system then 'ifup' doesn't work after install. - # FIXME: make 'ifup' use its own defaults! - def setDefaultConfig(self): - ifcfglog.debug("NetworkDevice %s: setDefaultConfig()" % self.iface) - self.set(("DEVICE", self.iface), - ("BOOTPROTO", "dhcp"), - ("ONBOOT", "no")) # for "security", or something - - try: - mac = open("/sys/class/net/%s/address" % self.iface).read().strip() - self.set(("HWADDR", mac.upper())) - except IOError as e: - ifcfglog.warning("HWADDR: %s" % str(e)) - - try: - uuid = open("/proc/sys/kernel/random/uuid").read().strip() - self.set(("UUID", uuid)) - except IOError as e: - ifcfglog.warning("UUID: %s" % str(e)) - - self.writeIfcfgFile() - def loadIfcfgFile(self): ifcfglog.debug("%s:\n%s" % (self.path, self.fileContent())) ifcfglog.debug("NetworkDevice %s:\n%s" % (self.iface, self.__str__())) @@ -440,7 +417,9 @@ class Network: if os.access(device.path, os.R_OK): device.loadIfcfgFile() else: - device.setDefaultConfig() + log.info("Network.update(): %s file not found" % + device.path) + continue
# TODORV - the last iface in loop wins, might be ok, # not worthy of special juggling
dracut/anaconda-write-default-ifcfg.sh | 20 ++++++++++++++++++++ dracut/module-setup.sh | 1 + pyanaconda/network.py | 27 +++------------------------ 3 files changed, 24 insertions(+), 24 deletions(-) create mode 100755 dracut/anaconda-write-default-ifcfg.sh
Make sure to also add your new file to dracut/Makefile.am or it won't get included.
diff --git a/dracut/anaconda-write-default-ifcfg.sh b/dracut/anaconda-write-default-ifcfg.sh new file mode 100755 index 0000000..e51de25 --- /dev/null +++ b/dracut/anaconda-write-default-ifcfg.sh @@ -0,0 +1,20 @@ +#!/bin/sh +# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- +# ex: ts=8 sw=4 sts=4 et filetype=sh
I think all files should have the typical copyright statement on them. At least, I make sure that's the case with all my stuff and the dracut stuff really should have followed suit.
- Chris
On 07/11/2012 04:14 PM, Chris Lumens wrote:
dracut/anaconda-write-default-ifcfg.sh | 20 ++++++++++++++++++++ dracut/module-setup.sh | 1 + pyanaconda/network.py | 27 +++------------------------ 3 files changed, 24 insertions(+), 24 deletions(-) create mode 100755 dracut/anaconda-write-default-ifcfg.sh
Make sure to also add your new file to dracut/Makefile.am or it won't get included.
Done, thanks.
diff --git a/dracut/anaconda-write-default-ifcfg.sh b/dracut/anaconda-write-default-ifcfg.sh new file mode 100755 index 0000000..e51de25 --- /dev/null +++ b/dracut/anaconda-write-default-ifcfg.sh @@ -0,0 +1,20 @@ +#!/bin/sh +# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- +# ex: ts=8 sw=4 sts=4 et filetype=sh
I think all files should have the typical copyright statement on them. At least, I make sure that's the case with all my stuff and the dracut stuff really should have followed suit.
Hm, interesting point. Neither our anaconda dracut modules nor dracut modules have it. I think we should clear this up and then fix it for all in one shot?
Radek
Hm, interesting point. Neither our anaconda dracut modules nor dracut modules have it. I think we should clear this up and then fix it for all in one shot?
That would be fine with me, just so long as it gets done.
- Chris
We used to do it in loader, and we'll need to write out TYPE= --- dracut/anaconda-write-default-ifcfg.sh | 6 ++++++ 1 files changed, 6 insertions(+), 0 deletions(-)
diff --git a/dracut/anaconda-write-default-ifcfg.sh b/dracut/anaconda-write-default-ifcfg.sh index e51de25..98018e8 100755 --- a/dracut/anaconda-write-default-ifcfg.sh +++ b/dracut/anaconda-write-default-ifcfg.sh @@ -6,6 +6,12 @@ for interface in /sys/class/net/*; do
ifname=${interface##*/}
+ case $(cat /sys/class/net/$ifname/type) in + # ARPHRD_ETHER, ARPHRD_INFINIBAND, ARPHRD_SLIP + 1|32|256) ;; + *) continue ;; + esac + if [ ! -e /run/initramfs/state/etc/sysconfig/network-scripts/ifcfg-$ifname ]; then { echo "# Generated by anconda dracut initrd module"
We'll probably need to update dracut with TYPE=InfiniBand so that we keep ipoib support added in rhel 6. --- dracut/anaconda-write-default-ifcfg.sh | 6 +++++- 1 files changed, 5 insertions(+), 1 deletions(-)
diff --git a/dracut/anaconda-write-default-ifcfg.sh b/dracut/anaconda-write-default-ifcfg.sh index 98018e8..c6476cb 100755 --- a/dracut/anaconda-write-default-ifcfg.sh +++ b/dracut/anaconda-write-default-ifcfg.sh @@ -6,9 +6,12 @@ for interface in /sys/class/net/*; do
ifname=${interface##*/}
+ iftype="" case $(cat /sys/class/net/$ifname/type) in # ARPHRD_ETHER, ARPHRD_INFINIBAND, ARPHRD_SLIP - 1|32|256) ;; + 1) iftype="Ethernet" ;; + 32) iftype="InfiniBand" ;; + 256) ;; *) continue ;; esac
@@ -20,6 +23,7 @@ for interface in /sys/class/net/*; do echo "ONBOOT=no" echo "HWADDR=$(cat /sys/class/net/$ifname/address)" echo "UUID=$(cat /proc/sys/kernel/random/uuid)" + [ -n "$iftype" ] && echo "TYPE=$iftype" } > /run/initramfs/state/etc/sysconfig/network-scripts/ifcfg-$ifname fi
anaconda-patches@lists.fedorahosted.org