Chroot: Now use a network unit for systemd-networkd

This commit is contained in:
Jeremy Gardais 2019-04-05 13:36:52 +02:00
parent 05a3de15ca
commit 521b7ea84a
Signed by: jegardai
GPG Key ID: E759BAA22501AF32
1 changed files with 16 additions and 13 deletions

29
debian/chroot.install vendored
View File

@ -201,28 +201,31 @@ sed -i 's;target;;g' /target/etc/fstab
sed -i 's;//;;g' /target/etc/fstab sed -i 's;//;;g' /target/etc/fstab
## }}} ## }}}
## Network {{{ ## Network {{{
### Get all informations from current network configuration in rescue mode
net_device=$(ip r | grep "^default" | head -1 | cut -d" " -f5) net_device=$(ip r | grep "^default" | head -1 | cut -d" " -f5)
net_address=$(ip r | grep -vE "(^default|metric)" | grep "${net_device}.*src" | head -1 | awk -F" " '{print $NF}') net_address=$(ip r | grep -vE "(^default|metric)" | grep "${net_device}.*src" | head -1 | awk -F" " '{print $NF}')
read -r net_mac_address </sys/class/net/"${net_device}"/address
net_netmask=$(ipcalc "${net_address}" | awk '/Netmask:/{print $2;}') net_netmask=$(ipcalc "${net_address}" | awk '/Netmask:/{print $2;}')
net_netmask_cidr=$(ipcalc "${net_address}" | awk '/Netmask:/{print $4;}')
net_broadcast=$(ip a s dev "${net_device}" | awk '/inet.*brd/{print $4}') net_broadcast=$(ip a s dev "${net_device}" | awk '/inet.*brd/{print $4}')
net_network=$(ip r | grep -vE "(^default|metric)" | grep "src ${net_address}" | head -1 | cut -d"/" -f1) net_network=$(ip r | grep -vE "(^default|metric)" | grep "src ${net_address}" | head -1 | cut -d"/" -f1)
net_gateway=$(ip r | grep "^default" | head -1 | cut -d" " -f3) net_gateway=$(ip r | grep "^default" | head -1 | cut -d" " -f3)
printf '%b' "auto lo ### Create a network unit for systemd-networkd
iface lo inet loopback printf '%b' "[Match]
MACAddress=${net_mac_address}
auto ${net_device} [Network]
iface ${net_device} inet static Description=network interface with default route without dhcp
address ${net_address} DHCP=no
netmask ${net_netmask} Address=${net_address}/${net_netmask_cidr}
network ${net_network} Gateway=${net_gateway}
broadcast ${net_broadcast} IPv6AcceptRA=no
gateway ${net_gateway} DNS=80.67.169.12
# FDN DNS - https://www.fdn.fr/actions/dns/ " > /target/etc/systemd/network/50-default.network
dns-nameserver 80.67.169.12
dns-nameserver 80.67.169.40
source-directory /etc/network/interfaces.d" > /target/etc/network/interfaces ### Ensure to enable systemd-networkd at startup
chroot /target systemctl enable systemd-networkd
## }}} ## }}}
## Ensure to remount device {{{ ## Ensure to remount device {{{