BootISOGrub2

Boots an ISO via GRUB using a rdinit= wrapper approach. DDs the ISO to a dedicated partition (partition 2) on the target disk, then creates a tiny cpio overlay containing a wrapper init script. The kernel’s rdinit= parameter runs the wrapper before the real /init. The wrapper patches /init in the live tmpfs (initramfs) to accept a netsetup.isodev= kernel parameter, then exec’s /init. This avoids extracting/decompressing the installer’s initrd at build-time — the kernel handles all zstd/cpio decompression. The wrapper modifies the decompressed /init in writable tmpfs. Replaces BootISOGrub which required extracting the initrd in Void Linux musl (failed due to zstd decompression producing empty output).

public static class BootISOGrub2

1. Methods

1.1. CopyBootFilesToSystem(ISystemHost, AbsolutePath, string, string, SubPath, SubPath)

Copies the installer’s kernel and initrd from the ISO partition to the SYSTEM partition, and creates the cpio overlay with init wrapper scripts as a separate file. All three files on SYSTEM = GRUB loads everything via bare paths with search --label SYSTEM. GRUB handles multi-file initrd concatenation with proper alignment — avoids the kernel panic caused by raw C# byte-concatenation of zstd-compressed initrd + uncompressed cpio overlay.

public static (AbsolutePath KernelPath, AbsolutePath InitrdPath, AbsolutePath OverlayPath) CopyBootFilesToSystem(ISystemHost host, AbsolutePath systemRoot, string osName, string isoPartDevice, SubPath kernelIsoPath, SubPath initrdIsoPath)
Table 1. Parameters
Name Type Description

host

ISystemHost

systemRoot

AbsolutePath

osName

string

isoPartDevice

string

kernelIsoPath

SubPath

initrdIsoPath

SubPath

Returns: (AbsolutePath KernelPath, AbsolutePath InitrdPath, AbsolutePath OverlayPath)

1.2. CreateInitWrapper(ISystemHost, AbsolutePath, string)

Creates a cpio overlay containing a wrapper init script and an OS-specific check script. The wrapper (/netsetup-init) is run by the kernel via rdinit=/netsetup-init. It patches /init in the live tmpfs (initramfs) using sed to inject the check script, then exec’s /init. This avoids extracting/decompressing the installer’s initrd.

public static AbsolutePath CreateInitWrapper(ISystemHost host, AbsolutePath systemRoot, string osName)
Table 2. Parameters
Name Type Description

host

ISystemHost

systemRoot

AbsolutePath

osName

string

Returns: AbsolutePath

1.3. EnsureIsoOnPartition(ISystemHost, AbsolutePath, string, string)

Ensures the ISO is written to partition 2 on the target disk. Checks if partition 2 already contains a valid ISO; if not, creates the partition and dd’s the ISO. Drops page caches before dd to avoid OOM in the Void Linux live environment.

public static void EnsureIsoOnPartition(ISystemHost host, AbsolutePath iso, string diskDevice, string part2Device)
Table 3. Parameters
Name Type Description

host

ISystemHost

iso

AbsolutePath

diskDevice

string

part2Device

string

1.4. FindDiskAndIsoPartition(ISystemHost, AbsolutePath)

Finds the parent disk device from the SYSTEM partition and derives the partition 2 device name. Handles NVMe/eMMC/loop naming conventions (nvme0n1 → nvme0n1p2, mmcblk0 → mmcblk0p2, sda → sda2).

public static (string DiskDevice, string Part2Device) FindDiskAndIsoPartition(ISystemHost host, AbsolutePath systemRoot)
Table 4. Parameters
Name Type Description

host

ISystemHost

systemRoot

AbsolutePath

Returns: (string DiskDevice, string Part2Device)

1.5. FindUsbDevice(ISystemHost, string)

Finds a USB device (a disk that is NOT the SYSTEM partition’s parent disk). Returns null if no other disk is found (single-disk system).

public static string FindUsbDevice(ISystemHost host, string systemDiskDevice)
Table 5. Parameters
Name Type Description

host

ISystemHost

systemDiskDevice

string

Returns: string

1.6. PrepareUsbIsoPartition(ISystemHost, string, long)

Prepares the USB device for the ISO by shrinking the last NTFS partition and creating a new ISO partition in the freed space. Returns the device path of the new ISO partition.

public static string PrepareUsbIsoPartition(ISystemHost host, string usbDevice, long isoSizeMb)
Table 6. Parameters
Name Type Description

host

ISystemHost

usbDevice

string

isoSizeMb

long

Returns: string

1.7. RemountSystemPartitionReadWrite(ISystemHost, AbsolutePath)

Remounts the SYSTEM partition read-write so we can write files and modify grub.cfg.

public static void RemountSystemPartitionReadWrite(ISystemHost host, AbsolutePath systemRoot)
Table 7. Parameters
Name Type Description

host

ISystemHost

systemRoot

AbsolutePath

1.8. SyncFilesystem(ISystemHost)

Syncs all filesystems to ensure writes are flushed to disk. Critical before reboot — without this, files in the page cache may be lost.

public static void SyncFilesystem(ISystemHost host)
Table 8. Parameters
Name Type Description

host

ISystemHost

1.9. WriteGrubInstallerEntry(ISystemHost, AbsolutePath, string, string, string, AbsolutePath, AbsolutePath, AbsolutePath)

Writes a GRUB menu entry for booting the installer. Both kernel and initrd are loaded from the SYSTEM partition using bare paths (GRUB’s default $root) — no search commands, no variables, no cross-partition references. This matches how Void Linux boots: same partition, same mechanism. See docs/pve-plan-a.md.

public static void WriteGrubInstallerEntry(ISystemHost host, AbsolutePath systemRoot, string osName, string kernelParameters, string isoPartDevice, AbsolutePath kernelOnSystemPath, AbsolutePath initrdOnSystemPath, AbsolutePath overlayOnSystemPath)
Table 9. Parameters
Name Type Description

host

ISystemHost

systemRoot

AbsolutePath

osName

string

kernelParameters

string

isoPartDevice

string

kernelOnSystemPath

AbsolutePath

initrdOnSystemPath

AbsolutePath

overlayOnSystemPath

AbsolutePath