File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -105,5 +105,48 @@ mountroot() {
105105 rm -f " ${rootmnt} /etc/machine-id" 2> /dev/null || true
106106 : > " ${rootmnt} /etc/machine-id"
107107
108+ # Parse kernel ip= parameters and write systemd-networkd configs.
109+ # Format: ip=<client-ip>:<server>:<gw-ip>:<netmask>:<hostname>:<device>:<autoconf>
110+ for x in $( cat /proc/cmdline) ; do
111+ case $x in
112+ ip=* )
113+ IFS=: read -r cip _ gw mask _ dev _ << EOF
114+ ${x# ip=}
115+ EOF
116+ if [ -n " $cip " ] && [ -n " $dev " ]; then
117+ # Convert dotted netmask to prefix length.
118+ prefix=0
119+ IFS=. read -r a b c d << EOF2
120+ $mask
121+ EOF2
122+ for octet in $a $b $c $d ; do
123+ case $octet in
124+ 255) prefix=$(( prefix + 8 )) ;;
125+ 254) prefix=$(( prefix + 7 )) ;;
126+ 252) prefix=$(( prefix + 6 )) ;;
127+ 248) prefix=$(( prefix + 5 )) ;;
128+ 240) prefix=$(( prefix + 4 )) ;;
129+ 224) prefix=$(( prefix + 3 )) ;;
130+ 192) prefix=$(( prefix + 2 )) ;;
131+ 128) prefix=$(( prefix + 1 )) ;;
132+ esac
133+ done
134+
135+ mkdir -p " ${rootmnt} /etc/systemd/network"
136+ cat > " ${rootmnt} /etc/systemd/network/10-${dev} .network" << NETEOF
137+ [Match]
138+ Name=${dev}
139+
140+ [Network]
141+ Address=${cip} /${prefix}
142+ Gateway=${gw}
143+ DNS=8.8.8.8
144+ DNS=8.8.4.4
145+ NETEOF
146+ fi
147+ ;;
148+ esac
149+ done
150+
108151 log_success_msg " Cocoon: stealth overlay rootfs ready"
109152}
You can’t perform that action at this time.
0 commit comments