11#! /bin/sh
2- # Filename: cocoon-boot .sh
3- # Target path: /etc/initramfs-tools/scripts/cocoon
2+ # Filename: overlay .sh
3+ # Target path: /etc/initramfs-tools/scripts/cocoon-overlay
44
55. /scripts/functions
66
@@ -105,51 +105,5 @@ mountroot() {
105105 rm -f " ${rootmnt} /etc/machine-id" 2> /dev/null || true
106106 : > " ${rootmnt} /etc/machine-id"
107107
108- # Convert initramfs network config (/run/net-*.conf) to systemd-networkd.
109- # The kernel ip= parameter is already parsed by initramfs configure_networking
110- # into /run/net-{device}.conf files. We source them and generate .network files
111- # so systemd-networkd picks up the config after switch_root.
112- for conf_file in /run/net-* .conf; do
113- [ -f " $conf_file " ] || continue
114- # Each file defines: DEVICE, IPV4ADDR, IPV4NETMASK, IPV4GATEWAY, HOSTNAME, etc.
115- unset DEVICE IPV4ADDR IPV4NETMASK IPV4GATEWAY IPV4DNS0 IPV4DNS1 HOSTNAME
116- . " $conf_file "
117- [ -z " $DEVICE " ] || [ -z " $IPV4ADDR " ] && continue
118-
119- # Convert dotted netmask to prefix length.
120- prefix=0
121- IFS=. read -r a b c d << EOF
122- ${IPV4NETMASK}
123- EOF
124- for octet in $a $b $c $d ; do
125- case $octet in
126- 255) prefix=$(( prefix + 8 )) ;;
127- 254) prefix=$(( prefix + 7 )) ;;
128- 252) prefix=$(( prefix + 6 )) ;;
129- 248) prefix=$(( prefix + 5 )) ;;
130- 240) prefix=$(( prefix + 4 )) ;;
131- 224) prefix=$(( prefix + 3 )) ;;
132- 192) prefix=$(( prefix + 2 )) ;;
133- 128) prefix=$(( prefix + 1 )) ;;
134- esac
135- done
136-
137- mkdir -p " ${rootmnt} /etc/systemd/network"
138- {
139- printf " [Match]\nName=%s\n\n[Network]\nAddress=%s/%d\n" " $DEVICE " " $IPV4ADDR " " $prefix "
140- [ -n " $IPV4GATEWAY " ] && printf " Gateway=%s\n" " $IPV4GATEWAY "
141- [ -n " $IPV4DNS0 " ] && printf " DNS=%s\n" " $IPV4DNS0 "
142- [ -n " $IPV4DNS1 " ] && printf " DNS=%s\n" " $IPV4DNS1 "
143- # Fallback DNS if none provided by kernel ip= parameter.
144- [ -z " $IPV4DNS0 " ] && printf " DNS=8.8.8.8\nDNS=8.8.4.4\n"
145- } > " ${rootmnt} /etc/systemd/network/10-${DEVICE} .network"
146-
147- # Set hostname from the first interface that provides one.
148- if [ -n " $HOSTNAME " ] && [ ! -f " ${rootmnt} /etc/cocoon-hostname-set" ]; then
149- echo " $HOSTNAME " > " ${rootmnt} /etc/hostname"
150- : > " ${rootmnt} /etc/cocoon-hostname-set"
151- fi
152- done
153-
154108 log_success_msg " Cocoon: stealth overlay rootfs ready"
155109}
0 commit comments