3 # modified from upstream fai example
4 error
=0; trap 'error=$(($?>$error?$?:$error))' ERR
# save maximum error code
7 # network configuration using ubuntu's netplan.io
10 echo "Generating netplan configuration for $IFNAME ($METHOD)" >&2
11 echo "# generated by FAI"
14 echo " renderer: $RENDERER"
24 echo " addresses: [$CIDR]"
25 echo " gateway4: $GATEWAYS_1"
27 echo " search: [$DOMAIN]"
28 echo " addresses: [${DNSSRVS// /, }]"
35 # classic network configuration using /etc/network/interfaces
38 echo "Generating interface configuration for $IFNAME ($METHOD)" >&2
39 echo "# generated by FAI"
41 echo "iface $IFNAME inet $METHOD"
44 echo " address $IPADDR"
45 echo " netmask $NETMASK"
46 echo " broadcast $BROADCAST"
47 echo " gateway $GATEWAYS"
54 # determine predictable network names only for stretch and above
56 [ $do_init_tasks -eq 0 ] && return
57 [ -z "$NIC1" ] && return
58 ver
=$
($ROOTCMD dpkg-query
--showformat='${Version}' --show udev
)
59 if dpkg
--compare-versions $ver lt
220-7; then
64 fields
="ID_NET_NAME_FROM_DATABASE ID_NET_NAME_ONBOARD ID_NET_NAME_SLOT ID_NET_NAME_PATH"
65 for field
in $fields; do
66 name
=$
(udevadm info
/sys
/class
/net
/$NIC1 |
sed -rn "s/^E: $field=(.+)/\1/p")
72 # This condition is only needed because the nfsroot I use
73 # is based on Jessie, which has an old udev which can't
74 # figure out the persistent interface name used in stretch.
75 if ifclass VM
; then NIC1
=ens3
; return; fi
76 if [[ ! $name ]]; then
77 echo "$0: error: could not find systemd predictable network name. Using $NIC1."
81 if [ -z "$NIC1" ]; then
82 echo "WARNING: \$NIC1 is not defined. Cannot add ethernet to /etc/network/interfaces."
84 CIDR
=$
(ip
-o -f inet addr show
$NIC1 |
awk '{print $4}')
89 ifclass DHCPC
&& METHOD
=dhcp || METHOD
=static
90 ifclass XORG
&& RENDERER
=NetworkManager || RENDERER
=networkd
92 if [ -d $target/etc
/netplan
]; then
93 # Ubuntu >= 17.10 with netplan.io
94 if [ -n "$NIC1" ]; then
95 netplan_yaml
$NIC1 $METHOD > $target/etc
/netplan
/01-${NIC1}.yaml
97 elif [ -d $target/etc
/network
/interfaces.d
]; then
98 # ifupdown >= 0.7.41 (Debian >= 8, Ubuntu >= 14.04)
101 # note, this condition would apply to the elif below too,
102 # but I don't specify a static ip in fai, so not bothering
103 cat > $target/etc
/network
/interfaces
<<-EOF
106 iface lo inet loopback
107 iface $NIC1 inet dhcp
110 cat > $target/etc
/network
/interfaces
<<-EOF
113 iface lo inet loopback
114 iface $NIC1 inet manual
115 # make a bridge by default so we can have bridged vms.
116 # Some example I read had stp on, but i don't need stp,
117 # and it causes a vm to fail pxe boot, presumably unless
118 # you add some delay.
119 # http://wiki.libvirt.org/page/PXE_boot_%28or_dhcp%29_on_guest_failed
128 iface_stanza lo loopback
129 iface_stanza
$NIC1 $METHOD
130 ) > $target/etc
/network
/interfaces
133 if ! ifclass DHCPC
; then
134 [ -n "$NETWORK" ] && echo "localnet $NETWORK" > $target/etc
/networks
135 if [ ! -L $target/etc
/resolv.conf
-a -e /etc
/resolv.conf
]; then
136 cp -p /etc
/resolv.conf
$target/etc
142 # here fcopy is mostly used, when installing a client for running in a
143 # different subnet than during the installation
144 fcopy
-iM /etc
/resolv.conf
145 fcopy
-iM /etc
/network
/interfaces
/etc
/networks