Skip to content

Instantly share code, notes, and snippets.

@maxux
Last active May 31, 2025 23:44
Show Gist options
  • Save maxux/af50c94c35fbae25a5339373c50545d8 to your computer and use it in GitHub Desktop.
Save maxux/af50c94c35fbae25a5339373c50545d8 to your computer and use it in GitHub Desktop.
Gentoo PXE Diskless Node (with Dracut initramfs 2024)

Since Gentoo Live now uses dracut as initramfs handler, legacy documentation about diskless PXE is irrelevant.

The live boot is supported directly by dracut from root= command line argument, but if we just pass the image.squashfs, the image won't be mounted correctly.

https://github.com/dracutdevs/dracut/blob/master/modules.d/90dmsquash-live/parse-dmsquash-live.sh#L40-L42

The special case where the squashfs image can be passed directly requires the image name to end with .img

With the latest iPXE trick, which allows specifying the filename inside the initramfs at load time, it allows to easily fix loader by suffixing .img to the squashfs file.

The boot.ipxe provided as an example uses a remote HTTP server to serve kernel, initramfs and squashfs image, which makes download way faster than syslinux http or even tftp. The initrd=magic.initrd trick is not required anymore since kernel 5.7+ (live runs 6.6.58 at the moment I write this).

There is no need to build combined initramfs anymore, etc. The provided example sets the root password to root and automatically starts sshd on boot.

The extract.sh script here mount the ISO, which avoids any dependencies to be installed (except a kernel supporting ISO mounting, obviously). If you don't want to use mount, you still can use any tools to extract files from the ISO. You need a minimal-install ISO file.

#!ipxe
kernel http://server/pxeboot/gentoo/kernel root=live:/image.squashfs.img cdroot passwd=root dosshd
initrd http://server/pxeboot/gentoo/gentoo.igz
initrd http://server/pxeboot/gentoo/image.squashfs /image.squashfs.img
boot
#!/bin/bash
set -e
isofile="$1"
targetdir="${2:-$(realpath .)}"
if [ -z $isofile ]; then
echo "Missing iso filename"
echo ""
echo " $0 <install-iso-file> [target-directory]"
echo ""
echo "Example:"
echo " $0 install-amd64-minimal-20241117T163407Z.iso"
echo " $0 install-amd64-minimal-20241117T163407Z.iso /tmp/gentoo"
exit 1
fi
workdir=$(mktemp -d --suffix .genpxe)
echo "[+] gentoo install iso : ${isofile}"
echo "[+] temporary directory: ${workdir}"
echo "[+] extracting target : ${targetdir}"
echo "[+] --------------"
if [ ! -d "${targetdir}" ]; then
echo "[+] creating target directory: ${targetdir}"
mkdir -p "${targetdir}"
fi
echo "[+] mounting image into temporary directory"
mount -o ro "${isofile}" "${workdir}"
echo "[+] extracting kernel"
cp "${workdir}/boot/gentoo" "${targetdir}/kernel"
echo "[+] extracting initramfs"
cp "${workdir}/boot/gentoo.igz" "${targetdir}/gentoo.igz"
echo "[+] extracting squashfs"
cp "${workdir}/image.squashfs" "${targetdir}/image.squashfs"
echo "[+] umounting image and cleaning up"
sync
umount "${workdir}"
rm -rf "${workdir}"
@NiKiZe
Copy link

NiKiZe commented May 31, 2025

By using isoinfo you can avoid the need for mounting.
https://github.com/NiKiZe/Gentoo-iPXE/blob/46c239ec9c76bc537f6b67ed9e5e0b3faf601056/gentoocd_unpack.sh#L42

Even better if Gentoo would publish these directly to avoid the need for extraction.

See the Gennto bug mentioned in NiKiZe/Gentoo-iPXE#2

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