Skip to content

Instantly share code, notes, and snippets.

@rikka0w0
Last active October 5, 2025 13:32
Show Gist options
  • Save rikka0w0/05224f8bfcdce6f780abd2d653aefd59 to your computer and use it in GitHub Desktop.
Save rikka0w0/05224f8bfcdce6f780abd2d653aefd59 to your computer and use it in GitHub Desktop.

Background

Kubuntu 24.04 can boot from iPxE using the following script:

#!ipxe

# Set NFS strings
set nfs-server          ${next-server}
set nfs-mountpt         /srv/nfs
set nfs-linux-live      nfs://${nfs-server}${nfs-mountpt}
set nfs-linux-boot      ${nfs-server}:${nfs-mountpt}

# Some menu defaults
set menu-timeout 10000
set submenu-timeout ${menu-timeout}
set menu-default kubuntu2404_live_common

:start
menu iPXE boot menu
item --gap --                   ---------------------------- Installers ----------------------------------
item                    kubuntu2404_live        Live Kubuntu 24.04
item --gap --                   ------------------------- Advanced options -------------------------------
item --key s    shell                   Drop to iPXE shell
item            reboot                  Reboot
item
item --key x    exit                    Exit iPXE and continue BIOS boot
choose --timeout ${menu-timeout} --default ${menu-default} selected || goto cancel
set menu-timeout 0
goto ${selected}

:cancel
echo You cancelled the menu, dropping you to a shell

:shell
echo Type 'exit' to get the back to the menu
shell
set menu-timeout 0
set submenu-timeout 0
goto start

:reboot
reboot

:exit
exit

:kubuntu2404_live
set dist-root ${nfs-linux-live}/kubuntu/24.04/iso
kernel ${dist-root}/casper/vmlinuz
initrd ${dist-root}/casper/initrd
imgargs vmlinuz initrd=initrd nfsroot=${nfs-linux-boot}/kubuntu/24.04/iso netboot=nfs boot=casper ip=dhcp mitigations=off utc=no fsck.mode=skip ignore_uuid nomodeset
boot
goto start

where nfs-linux-boot is the path of the nfs-shared folder (e.g. NFS.SERVER.IP:/PATH/TO/NFS/ROOT), and nfs-linux-live is similar, but in a different format(e.g. nfs://NFS.SERVER.IP/PATH/TO/NFS/ROOT).

You can enter the live desktop without any issue, but you will soon notice two problems:

  1. You cannot ping any domain name, DNS does not work.
  2. If you click on the network icon on the taskbar, there will be two "Networks", namely eth0 and netplan-eth0.
  3. As soon as you run sudo nmcli connection reload, the system freezes.

Root cause

When a Ubuntu-based live system boots, it starts from the Casper initramfs. To mount the NFS over network, it must configure the network first by launching a DHCP client (dhcpcd). After the live system switch into the real root filesystem, Kubuntu uses netplan+NetworkManager to manage the network configuration.

By default, the boot script attempts to migrate some of the network "state" from initramfs to the live system. But for some reason, it does not set the DNS server correctly. If you run resolvectl in the live system, you can see that there is no name server configured. This explains the first problem.

The problem 2 is simple. In /run/NetworkManager/system-connections, there are eth0.nmconnection and netplan-eth0.nmconnection. When NetworkManager starts, if there is /run/net-eth0.conf, it will parse it into eth0.nmconnection.

After the live system boots, the default network profile is on eth0.nmconnection. Once you run sudo nmcli connection reload, NetworkManager will start to use netplan-eth0.nmconnection and start another round of DHCP handshake. The IP address will change. This breaks the NFS connection (as shown in the kernel log). Although in some case the NFS connection can recover (once recovered, Internet access is restored), it usually takes more than 5 min, which is not acceptable.

I noticed that Casper initramfs uses dhcpcd as the DHCP client, whereas the Kubuntu live system uses NetworkManager. By default, the former uses IAID+DUID-LL (DUID-LL is a 1-1 map of the hardware MAC) in the DHCP client-id option(61), the latter uses the MAC address only. Since different client IDs are used, the DHCP server may treat them as different machines and issue different IP addresses, causing existing connections to stall.

Solution

The solution is to unify the way of generating client ID. Here I will demonstrate how to change the client ID used by dhcpcd to the hardware MAC.

  1. Unpack the initramfs
sudo apt install initramfs-tools-core
mkdir /tmp/unpack
unmkinitramfs /srv/nfs/kubuntu/24.04/iso/casper/initrd /tmp/unpack/
  1. Check the initrd format
$ file /srv/nfs/kubuntu/24.04/iso/casper/initrd
/srv/nfs/kubuntu/24.04/iso/casper/initrd: ASCII cpio archive (SVR4 with no CRC)
  1. Edit /tmp/unpack/main/scripts/functions:

In function configure_networking:

- dhcpcd -1KLd -t $ROUNDTTT -4 ${DEVICE:+"${DEVICE}"}
+ dhcpcd -I '' -1KLd -t $ROUNDTTT -4 ${DEVICE:+"${DEVICE}"}

The key is-I '', see -I, --clientid clientid

if the clientid is an empty string then dhcpcd sends a default clientid of the hardware family and the hardware address.

In this way, dhcpcd will use MAC as the client ID just like the NetworkManager.

  1. Repack

Run the following script:

OUT=/tmp/initrd
> "$OUT"

# 1) Inject earlyX, no compression
for ed in /tmp/unpack/early*; do
  [ -d "$ed" ] || continue
  ( cd "$ed" && find . -print0 | cpio --null -o -H newc --quiet ) >> "$OUT"
done

# 2) Append main (compressing or not depends on the stock initrd)
cd /tmp/unpack/main
COMPRESS=gzip   # Better to align with the stock initrd
if [ "$COMPRESS" = "none" ]; then
  find . -print0 | cpio --null -o -H newc --quiet >> "$OUT"
else
  find . -print0 | cpio --null -o -H newc --quiet | $COMPRESS -9 >> "$OUT"
fi
  1. Boot into the live system and run:
sudo rm /run/net-eth0.conf
sudo nmcli connection up netplan-eth0

or (not recommended):

sudo rm /run/NetworkManager/system-connections/eth0.nmconnection
sudo nmcli connection reload

Now, you should be able to ping domain names. Furthermore, DHCP client will be running in the background and it will renew the IP when the lease expires.

Warning: DO NOT run sudo netplan apply, it will break the NFS connection anyway...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment