]> git.ipfire.org Git - thirdparty/dracut.git/blame - modules.d/45ifcfg/write-ifcfg.sh
add mtu and macaddr to ip=
[thirdparty/dracut.git] / modules.d / 45ifcfg / write-ifcfg.sh
CommitLineData
9f73fedf 1#!/bin/sh
cc02093d
HH
2# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
3# ex: ts=8 sw=4 sts=4 et filetype=sh
9f73fedf 4
47b5c0f2
WT
5# NFS root might have reached here before /tmp/net.ifaces was written
6udevadm settle --timeout=30
9f73fedf 7# Don't write anything if we don't know our bootdev
8ecd9d01 8[ -f /tmp/net.ifaces ] || return 1
9f73fedf 9
8ecd9d01 10read IFACES < /tmp/net.ifaces
9f73fedf 11
96fb9c8d
VB
12if [ -e /tmp/bond.info ]; then
13 . /tmp/bond.info
14fi
15
16if [ -e /tmp/bridge.info ]; then
17 . /tmp/bridge.info
18fi
19
d125a470 20mkdir -m 0755 -p /tmp/ifcfg/
66666c67 21mkdir -m 0755 -p /tmp/ifcfg-leases/
96fb9c8d 22
8ecd9d01 23for netif in $IFACES ; do
beb097d9
WT
24 # bridge?
25 unset bridge
96fb9c8d 26 unset bond
66666c67 27 uuid=$(cat /proc/sys/kernel/random/uuid)
beb097d9
WT
28 if [ "$netif" = "$bridgename" ]; then
29 bridge=yes
96fb9c8d
VB
30 elif [ "$netif" = "$bondname" ]; then
31 # $netif can't be bridge and bond at the same time
32 bond=yes
beb097d9 33 fi
8ecd9d01 34 cat /sys/class/net/$netif/address > /tmp/net.$netif.hwaddr
c98bcec8 35 {
3b403b32 36 echo "# Generated by dracut initrd"
cc02093d
HH
37 echo "DEVICE=$netif"
38 echo "ONBOOT=yes"
39 echo "NETBOOT=yes"
66666c67 40 echo "UUID=$uuid"
990e945f
HH
41 [ -n "$macaddr" ] && echo "MACADDR=$macaddr"
42 [ -n "$mtu" ] && echo "MTU=$mtu"
cc02093d
HH
43 if [ -f /tmp/net.$netif.lease ]; then
44 strstr "$ip" '*:*:*' &&
3b403b32
HH
45 echo "DHCPV6C=yes"
46 echo "BOOTPROTO=dhcp"
66666c67 47 cp /tmp/net.$netif.lease /tmp/ifcfg-leases/dhclient-$uuid-$netif.lease
cc02093d 48 else
3b403b32 49 echo "BOOTPROTO=none"
8ecd9d01 50 # If we've booted with static ip= lines, the override file is there
3b403b32 51 [ -e /tmp/net.$netif.override ] && . /tmp/net.$netif.override
cc02093d
HH
52 echo "IPADDR=$ip"
53 echo "NETMASK=$mask"
54 [ -n "$gw" ] && echo "GATEWAY=$gw"
55 fi
c98bcec8 56 } > /tmp/ifcfg/ifcfg-$netif
beb097d9 57
4431431c 58 # bridge needs different things written to ifcfg
3afca618 59 if [ -z "$bridge" ] && [ -z "$bond" ]; then
beb097d9 60 # standard interface
cc02093d 61 {
c98bcec8
HH
62 echo "HWADDR=$(cat /sys/class/net/$netif/address)"
63 echo "TYPE=Ethernet"
3b403b32 64 echo "NAME=\"Boot Disk\""
990e945f 65 [ -n "$mtu" ] && echo "MTU=$mtu"
cc02093d 66 } >> /tmp/ifcfg/ifcfg-$netif
96fb9c8d
VB
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
3afca618 78 # Set ONBOOT=no to prevent initscripts from trying to setup already bonded physical interface
96fb9c8d
VB
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"
3afca618 84 echo "ONBOOT=no"
96fb9c8d
VB
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
beb097d9 95 # bridge
cc02093d
HH
96 {
97 echo "TYPE=Bridge"
3b403b32 98 echo "NAME=\"Boot Disk\""
cc02093d 99 } >> /tmp/ifcfg/ifcfg-$netif
96fb9c8d
VB
100 if [ "$ethname" = "$bondname" ] ; then
101 {
3afca618 102 # Set ONBOOT=no to prevent initscripts from trying to setup already bridged bond interface
96fb9c8d
VB
103 echo "# Generated by dracut initrd"
104 echo "DEVICE=$bondname"
3afca618 105 echo "ONBOOT=no"
96fb9c8d 106 echo "NETBOOT=yes"
3afca618 107 # This variable is an indicator of a bond interface for initscripts
96fb9c8d
VB
108 echo "BONDING_OPTS=\"$bondoptions\""
109 echo "BRIDGE=$netif"
3b403b32 110 echo "NAME=\"$bondname\""
96fb9c8d
VB
111 } >> /tmp/ifcfg/ifcfg-$bondname
112 for slave in $bondslaves ; do
113 # write separate ifcfg file for the raw eth interface
3afca618 114 # Set ONBOOT=no to prevent initscripts from trying to setup already bridged physical interface
96fb9c8d
VB
115 {
116 echo "# Generated by dracut initrd"
117 echo "DEVICE=$slave"
118 echo "TYPE=Ethernet"
3afca618 119 echo "ONBOOT=no"
96fb9c8d
VB
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"
3afca618 133 echo "ONBOOT=no"
96fb9c8d
VB
134 echo "NETBOOT=yes"
135 echo "HWADDR=$(cat /sys/class/net/$ethname/address)"
136 echo "BRIDGE=$netif"
3afca618 137 echo "NAME=$ethname"
96fb9c8d
VB
138 } >> /tmp/ifcfg/ifcfg-$ethname
139 fi
beb097d9 140 fi
8ecd9d01 141done
7a6e646c
PS
142
143# Pass network opts
d37ad6ae 144mkdir -m 0755 -p /run/initramfs/state/etc/sysconfig/network-scripts
66666c67 145mkdir -m 0755 -p /run/initramfs/state/var/lib/dhclient
d37ad6ae 146echo "files /etc/sysconfig/network-scripts" >> /run/initramfs/rwtab
66666c67 147echo "files /var/lib/dhclient" >> /run/initramfs/rwtab
d37ad6ae
WW
148{
149 cp /tmp/net.* /run/initramfs/
150 cp /tmp/net.$netif.resolv.conf /run/initramfs/state/etc/
151 cp -a -t /run/initramfs/state/etc/sysconfig/network-scripts/ /tmp/ifcfg/*
66666c67 152 cp /tmp/ifcfg-leases/* /run/initramfs/state/var/lib/dhclient
d37ad6ae 153} > /dev/null 2>&1