]> git.ipfire.org Git - thirdparty/dracut.git/blob - modules.d/45ifcfg/write-ifcfg.sh
write-ifcfg.sh: add UUID=.. and save the lease files with the same uuid
[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 if [ -f /tmp/net.$netif.lease ]; then
42 strstr "$ip" '*:*:*' &&
43 echo "DHCPV6C=yes"
44 echo "BOOTPROTO=dhcp"
45 cp /tmp/net.$netif.lease /tmp/ifcfg-leases/dhclient-$uuid-$netif.lease
46 else
47 echo "BOOTPROTO=none"
48 # If we've booted with static ip= lines, the override file is there
49 [ -e /tmp/net.$netif.override ] && . /tmp/net.$netif.override
50 echo "IPADDR=$ip"
51 echo "NETMASK=$mask"
52 [ -n "$gw" ] && echo "GATEWAY=$gw"
53 fi
54 } > /tmp/ifcfg/ifcfg-$netif
55
56 # bridge needs different things written to ifcfg
57 if [ -z "$bridge" ] && [ -z "$bond" ]; then
58 # standard interface
59 {
60 echo "HWADDR=$(cat /sys/class/net/$netif/address)"
61 echo "TYPE=Ethernet"
62 echo "NAME=\"Boot Disk\""
63 } >> /tmp/ifcfg/ifcfg-$netif
64 fi
65
66 if [ -n "$bond" ] ; then
67 # bond interface
68 {
69 # This variable is an indicator of a bond interface for initscripts
70 echo "BONDING_OPTS=\"$bondoptions\""
71 echo "NAME=\"Boot Disk\""
72 } >> /tmp/ifcfg/ifcfg-$netif
73
74 for slave in $bondslaves ; do
75 # Set ONBOOT=no to prevent initscripts from trying to setup already bonded physical interface
76 # write separate ifcfg file for the raw eth interface
77 {
78 echo "# Generated by dracut initrd"
79 echo "DEVICE=$slave"
80 echo "TYPE=Ethernet"
81 echo "ONBOOT=no"
82 echo "NETBOOT=yes"
83 echo "HWADDR=$(cat /sys/class/net/$slave/address)"
84 echo "SLAVE=yes"
85 echo "MASTER=$netif"
86 echo "NAME=$slave"
87 } >> /tmp/ifcfg/ifcfg-$slave
88 done
89 fi
90
91 if [ -n "$bridge" ] ; then
92 # bridge
93 {
94 echo "TYPE=Bridge"
95 echo "NAME=\"Boot Disk\""
96 } >> /tmp/ifcfg/ifcfg-$netif
97 if [ "$ethname" = "$bondname" ] ; then
98 {
99 # Set ONBOOT=no to prevent initscripts from trying to setup already bridged bond interface
100 echo "# Generated by dracut initrd"
101 echo "DEVICE=$bondname"
102 echo "ONBOOT=no"
103 echo "NETBOOT=yes"
104 # This variable is an indicator of a bond interface for initscripts
105 echo "BONDING_OPTS=\"$bondoptions\""
106 echo "BRIDGE=$netif"
107 echo "NAME=\"$bondname\""
108 } >> /tmp/ifcfg/ifcfg-$bondname
109 for slave in $bondslaves ; do
110 # write separate ifcfg file for the raw eth interface
111 # Set ONBOOT=no to prevent initscripts from trying to setup already bridged physical interface
112 {
113 echo "# Generated by dracut initrd"
114 echo "DEVICE=$slave"
115 echo "TYPE=Ethernet"
116 echo "ONBOOT=no"
117 echo "NETBOOT=yes"
118 echo "HWADDR=$(cat /sys/class/net/$slave/address)"
119 echo "SLAVE=yes"
120 echo "MASTER=$bondname"
121 echo "NAME=$slave"
122 } >> /tmp/ifcfg/ifcfg-$slave
123 done
124 else
125 # write separate ifcfg file for the raw eth interface
126 {
127 echo "# Generated by dracut initrd"
128 echo "DEVICE=$ethname"
129 echo "TYPE=Ethernet"
130 echo "ONBOOT=no"
131 echo "NETBOOT=yes"
132 echo "HWADDR=$(cat /sys/class/net/$ethname/address)"
133 echo "BRIDGE=$netif"
134 echo "NAME=$ethname"
135 } >> /tmp/ifcfg/ifcfg-$ethname
136 fi
137 fi
138 done
139
140 # Pass network opts
141 mkdir -m 0755 -p /run/initramfs/state/etc/sysconfig/network-scripts
142 mkdir -m 0755 -p /run/initramfs/state/var/lib/dhclient
143 echo "files /etc/sysconfig/network-scripts" >> /run/initramfs/rwtab
144 echo "files /var/lib/dhclient" >> /run/initramfs/rwtab
145 {
146 cp /tmp/net.* /run/initramfs/
147 cp /tmp/net.$netif.resolv.conf /run/initramfs/state/etc/
148 cp -a -t /run/initramfs/state/etc/sysconfig/network-scripts/ /tmp/ifcfg/*
149 cp /tmp/ifcfg-leases/* /run/initramfs/state/var/lib/dhclient
150 } > /dev/null 2>&1