3 # modified from upstream fai example
4 error
=0; trap 'error=$(($?>$error?$?:$error))' ERR
# save maximum error code
8 # determine predictable network names only for stretch and above
10 [ $do_init_tasks -eq 0 ] && return
12 ver
=$
($ROOTCMD dpkg-query
--showformat='${Version}' --show udev
)
13 if dpkg
--compare-versions $ver lt
220-7; then
17 [ -z $NIC1 ] && return
19 fields
="ID_NET_NAME_FROM_DATABASE ID_NET_NAME_ONBOARD ID_NET_NAME_SLOT ID_NET_NAME_PATH"
20 for field
in $fields; do
21 name
=$
(udevadm info
/sys
/class
/net
/$NIC1 |
sed -rn "s/^E: $field=(.+)/\1/p")
27 # This condition is only needed because the nfsroot I use
28 # is based on Jessie, which has an old udev which can't
29 # figure out the persistent interface name used in stretch.
30 if ifclass VM
; then NIC1
=ens3
; return; fi
31 if [[ ! $name ]]; then
32 echo "$0: error: could not find systemd predictable network name. Using $NIC1."
37 CIDR
=$
(ip
-o -f inet addr show
$NIC1 |
awk '{print $4}')
38 if ifclass DHCPC
&& [ $FAI_ACTION = "install" -o $FAI_ACTION = "dirinstall" ]; then
41 # note, this condition would apply to the elif below too,
42 # but I don't specify a static ip in fai, so not bothering
43 cat > $target/etc
/network
/interfaces
<<-EOF
46 iface lo inet loopback
50 cat > $target/etc
/network
/interfaces
<<-EOF
53 iface lo inet loopback
54 iface $NIC1 inet manual
55 # make a bridge by default so we can have bridged vms.
56 # Some example I read had stp on, but i don't need stp,
57 # and it causes a vm to fail pxe boot, presumably unless
59 # http://wiki.libvirt.org/page/PXE_boot_%28or_dhcp%29_on_guest_failed
66 elif [ $FAI_ACTION = "install" -o $FAI_ACTION = "dirinstall" ]; then
67 [ -n "$CIDR" ] && cat > $target/etc
/network
/interfaces
<<-EOF
70 iface lo inet loopback
71 iface $NIC1 inet static
75 [ -n "$NETWORK" ] && echo "localnet $NETWORK" > $target/etc
/networks
76 if [ ! -L $target/etc
/resolv.conf
-a -e /etc
/resolv.conf
]; then
77 cp -p /etc
/resolv.conf
$target/etc
81 # here fcopy is mostly used, when installing a client for running in a
82 # different subnet than during the installation
83 fcopy
-iM /etc
/resolv.conf
84 fcopy
-iM /etc
/network
/interfaces
/etc
/networks