]> git.ipfire.org Git - thirdparty/dracut.git/blob - modules.d/45ifcfg/write-ifcfg.sh
ifcfg: write DNS1=... for nameserver= args (RHBZ#815369)
[thirdparty/dracut.git] / modules.d / 45ifcfg / write-ifcfg.sh
1 #!/bin/sh
2 # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
3 # ex: ts=8 sw=4 sts=4 et filetype=sh
4
5 # NFS root might have reached here before /tmp/net.ifaces was written
6 udevadm settle --timeout=30
7 # Don't write anything if we don't know our bootdev
8 [ -f /tmp/net.ifaces ] || return 1
9
10 read IFACES < /tmp/net.ifaces
11
12 if [ -e /tmp/bond.info ]; then
13 . /tmp/bond.info
14 fi
15
16 if [ -e /tmp/bridge.info ]; then
17 . /tmp/bridge.info
18 fi
19
20 mkdir -m 0755 -p /tmp/ifcfg/
21 mkdir -m 0755 -p /tmp/ifcfg-leases/
22
23 for netif in $IFACES ; do
24 # bridge?
25 unset bridge
26 unset bond
27 uuid=$(cat /proc/sys/kernel/random/uuid)
28 if [ "$netif" = "$bridgename" ]; then
29 bridge=yes
30 elif [ "$netif" = "$bondname" ]; then
31 # $netif can't be bridge and bond at the same time
32 bond=yes
33 fi
34 cat /sys/class/net/$netif/address > /tmp/net.$netif.hwaddr
35 {
36 echo "# Generated by dracut initrd"
37 echo "DEVICE=$netif"
38 echo "ONBOOT=yes"
39 echo "NETBOOT=yes"
40 echo "UUID=$uuid"
41 [ -n "$macaddr" ] && echo "MACADDR=$macaddr"
42 [ -n "$mtu" ] && echo "MTU=$mtu"
43 if [ -f /tmp/net.$netif.lease ]; then
44 strstr "$ip" '*:*:*' &&
45 echo "DHCPV6C=yes"
46 echo "BOOTPROTO=dhcp"
47 cp /tmp/net.$netif.lease /tmp/ifcfg-leases/dhclient-$uuid-$netif.lease
48 else
49 echo "BOOTPROTO=none"
50 # If we've booted with static ip= lines, the override file is there
51 [ -e /tmp/net.$netif.override ] && . /tmp/net.$netif.override
52 echo "IPADDR=$ip"
53 echo "NETMASK=$mask"
54 [ -n "$gw" ] && echo "GATEWAY=$gw"
55 fi
56 } > /tmp/ifcfg/ifcfg-$netif
57
58 # bridge needs different things written to ifcfg
59 if [ -z "$bridge" ] && [ -z "$bond" ]; then
60 # standard interface
61 {
62 echo "HWADDR=$(cat /sys/class/net/$netif/address)"
63 echo "TYPE=Ethernet"
64 echo "NAME=\"Boot Disk\""
65 [ -n "$mtu" ] && echo "MTU=$mtu"
66 } >> /tmp/ifcfg/ifcfg-$netif
67 fi
68
69 if [ -n "$bond" ] ; then
70 # bond interface
71 {
72 # This variable is an indicator of a bond interface for initscripts
73 echo "BONDING_OPTS=\"$bondoptions\""
74 echo "NAME=\"Boot Disk\""
75 } >> /tmp/ifcfg/ifcfg-$netif
76
77 for slave in $bondslaves ; do
78 # Set ONBOOT=no to prevent initscripts from trying to setup already bonded physical interface
79 # write separate ifcfg file for the raw eth interface
80 {
81 echo "# Generated by dracut initrd"
82 echo "DEVICE=$slave"
83 echo "TYPE=Ethernet"
84 echo "ONBOOT=no"
85 echo "NETBOOT=yes"
86 echo "HWADDR=$(cat /sys/class/net/$slave/address)"
87 echo "SLAVE=yes"
88 echo "MASTER=$netif"
89 echo "NAME=$slave"
90 } >> /tmp/ifcfg/ifcfg-$slave
91 done
92 fi
93
94 if [ -n "$bridge" ] ; then
95 # bridge
96 {
97 echo "TYPE=Bridge"
98 echo "NAME=\"Boot Disk\""
99 } >> /tmp/ifcfg/ifcfg-$netif
100 if [ "$ethname" = "$bondname" ] ; then
101 {
102 # Set ONBOOT=no to prevent initscripts from trying to setup already bridged bond interface
103 echo "# Generated by dracut initrd"
104 echo "DEVICE=$bondname"
105 echo "ONBOOT=no"
106 echo "NETBOOT=yes"
107 # This variable is an indicator of a bond interface for initscripts
108 echo "BONDING_OPTS=\"$bondoptions\""
109 echo "BRIDGE=$netif"
110 echo "NAME=\"$bondname\""
111 } >> /tmp/ifcfg/ifcfg-$bondname
112 for slave in $bondslaves ; do
113 # write separate ifcfg file for the raw eth interface
114 # Set ONBOOT=no to prevent initscripts from trying to setup already bridged physical interface
115 {
116 echo "# Generated by dracut initrd"
117 echo "DEVICE=$slave"
118 echo "TYPE=Ethernet"
119 echo "ONBOOT=no"
120 echo "NETBOOT=yes"
121 echo "HWADDR=$(cat /sys/class/net/$slave/address)"
122 echo "SLAVE=yes"
123 echo "MASTER=$bondname"
124 echo "NAME=$slave"
125 } >> /tmp/ifcfg/ifcfg-$slave
126 done
127 else
128 # write separate ifcfg file for the raw eth interface
129 {
130 echo "# Generated by dracut initrd"
131 echo "DEVICE=$ethname"
132 echo "TYPE=Ethernet"
133 echo "ONBOOT=no"
134 echo "NETBOOT=yes"
135 echo "HWADDR=$(cat /sys/class/net/$ethname/address)"
136 echo "BRIDGE=$netif"
137 echo "NAME=$ethname"
138 } >> /tmp/ifcfg/ifcfg-$ethname
139 fi
140 fi
141 i=1
142 for ns in $(getargs nameserver); do
143 echo "DNS${i}=${ns}" >> /tmp/ifcfg/ifcfg-$netif
144 i=$((i+1))
145 done
146 done
147
148 # Pass network opts
149 mkdir -m 0755 -p /run/initramfs/state/etc/sysconfig/network-scripts
150 mkdir -m 0755 -p /run/initramfs/state/var/lib/dhclient
151 echo "files /etc/sysconfig/network-scripts" >> /run/initramfs/rwtab
152 echo "files /var/lib/dhclient" >> /run/initramfs/rwtab
153 {
154 cp /tmp/net.* /run/initramfs/
155 cp /tmp/net.$netif.resolv.conf /run/initramfs/state/etc/
156 cp -a -t /run/initramfs/state/etc/sysconfig/network-scripts/ /tmp/ifcfg/*
157 cp /tmp/ifcfg-leases/* /run/initramfs/state/var/lib/dhclient
158 } > /dev/null 2>&1