Skip to content

Flashing Modes and Multiboot

buntatoes edited this page Nov 28, 2026 · 1 revision

Flashing Modes and Multiboot

Cinderboot automatically inspects source images without mounting or extracting them and selects the optimal flashing strategy, while also allowing explicit mode overrides via CLI (--mode) or the desktop UI.


Automatic Image Detection & Mode Selection

image.Inspect (internal/image/detect.go) classifies images in the following order:

Detected Kind Detection Criteria Recommended Mode Strategy
compressed-raw File ends in .gz, .bz2, or .zip raw Transparently decompresses on the fly and streams bit-for-bit to the USB drive
windows-iso Valid UDF 1.02 or ISO9660 containing both sources/boot.wim and sources/install.wim (or sources/install.esd) windows-fat32 Formats GPT + FAT32, extracts all files, auto-splits >4 GiB .wim into .swm, injects optional autounattend.xml
hybrid-linux-iso Valid UDF/ISO9660 with a non-empty MBR partition entry (0x55AA at sector 0) or a GPT header (EFI PART at sector 1) raw Streams ISO bit-for-bit, verifies SHA-256, and relocates Backup GPT to disk tail if needed
standard-iso Valid UDF/ISO9660 with neither hybrid MBR nor GPT headers iso-fat32 Formats GPT + FAT32 and extracts all ISO files directly
raw-image Any other file (e.g., .img, .raw, .bin) raw Streams bit-for-bit with optional SHA-256 read-back verification

When 2 or more images are supplied (or --mode multiboot is selected explicitly), flash.Execute enters Multi-Distro Linux UEFI Multiboot mode (ModeMultiboot).


Raw Direct Stream Engine (ModeRaw)

Implemented in internal/flash/raw.go, Raw mode is used for hybrid Linux ISOs, raw disk images, and .gz/.bz2/.zip compressed images.

Step-by-Step Pipeline

  1. Pre-Write Wipe (fs.WipePartitionTables): Zeroes up to 1 MiB at both the beginning and physical end of the target USB drive so leftover MBR/GPT metadata cannot conflict with the new image.
  2. Capacity Check: Rejects images whose known size (or decompressed stream size) exceeds the target drive's reported capacity.
  3. 2 MiB Aligned Streaming + Live SHA-256:
    • Reads and writes in 2 MiB chunks (rawChunkSize), keeping throughput high while remaining responsive to user cancellation.
    • Hashes exact logical image bytes before padding any final partial block with zeroes to the device's sector boundary (sectorSize, default 512 bytes).
    • Calls Sync() every 16 MiB (rawSyncInterval) to prevent kernel dirty-page writeback stalls on slow USB controllers.
  4. Transient USB I/O Recovery:
    • Both writes (writeWithRecovery) and verification reads (readWithRecovery) automatically retry transient errors up to 3 times (maxRetryAttempt = 3) with linear backoff (250 ms, 500 ms, 750 ms), seeking back to the exact byte offset and emitting a recovering progress event.
    • Immediately aborts without retrying on fatal errors: context.Canceled, context.DeadlineExceeded, ENOSPC, EROFS, EACCES, EPERM, ENODEV (or io.EOF during verify).
  5. Final Flush & SHA-256 Read-Back Verification (enabled by default, --verify=true):
    • Syncs and closes the write descriptor, reopens read-only (device.OpenRawRead), drops the Linux block device page cache via BLKFLSBUF (device.FlushReadCache) so bytes are verified from physical flash rather than RAM, reads back the exact written byte count, and compares the read-back SHA-256 digest against the streamed write digest.
  6. Post-Flash Backup GPT Relocation (fs.RelocateBackupGPT):
    • Many modern hybrid Linux ISOs (such as Ubuntu 22.04/24.04+) embed a GPT table sized to the ISO file rather than the larger USB stick, placing the Backup GPT in the middle of the disk.
    • Strict UEFI firmwares may reject such a GPT table and fail to see the EFI System Partition.
    • After SHA-256 verification completes, Cinderboot checks for a valid Primary GPT whose AlternateLBA != totalSectors - 1, relocates the Backup Partition Array and Backup GPT Header to the physical end of the USB drive, updates AlternateLBA, LastUsableLBA, CRC32s, and the Protective MBR sector count, and zeroes the stray mid-disk backup header.
  7. Partition Table Rescan: Calls device.RereadPartitionTablePath (BLKRRPART on Linux, IOCTL_DISK_UPDATE_PROPERTIES on Windows) so the host OS recognizes the new partitions.

Multi-Distro Linux UEFI Multiboot (ModeMultiboot)

Implemented in internal/flash/multiboot.go, internal/image/efi.go, and internal/image/distro.go, Cinderboot creates multi-distro UEFI bootable USB drives without bundling any third-party bootloader binaries and without hitting FAT32's 4 GiB file size limit.

Disk Layout

flowchart LR
    PMBR["LBA 0: Protective MBR"]
    PGPT["LBA 1..33: Primary GPT"]
    P1["Partition 1: 64 MiB FAT32 ESP (CINDERBOOT_ESP) - Extracted GRUB2 + Menu + Chainload EFIs"]
    P2["Partition 2: Raw ISO #1 (1 MiB aligned, Unique PARTUUID)"]
    P3["Partition 3: Raw ISO #2 (1 MiB aligned, Unique PARTUUID)"]
    PN["Partition N+1: Raw ISO #N (1 MiB aligned, Unique PARTUUID)"]
    BGPT["Tail 33 Sectors: Backup GPT"]

    PMBR --> PGPT --> P1 --> P2 --> P3 --> PN --> BGPT
Loading

Because each Linux ISO is written raw into its own 1 MiB-aligned GPT partition (GPTTypeBasicData):

  • ISOs larger than 4 GiB work natively with no splitting or repacking.
  • Every distro preserves its exact native ISO9660 filesystem, volume label, and modification UUID.
  • Every distro receives a cryptographically random, unique GPT PARTUUID, preventing initramfs collisions when multiple live distros exist on the same USB stick.

1. Pure-Go UEFI Bootloader Extraction (ExtractISOEFIBundle)

Cinderboot extracts signed UEFI bootloaders (BOOTX64.EFI, grubx64.efi, shimx64.efi, mmx64.efi, plus loader/ and boot/grub/ configs) directly from each selected ISO using a 4-stage fallback cascade:

  1. GPT EFI System Partition (GPTTypeEFI) — modern Ubuntu 20.10+, Fedora, Debian 12+, Mint, openSUSE, EndeavourOS, Pop!_OS.
  2. MBR 0xEF EFI Partition — Arch, Manjaro, and older hybrid ISOs.
  3. El Torito EFI Boot Catalog Entry (0x90/0x91 header + 0xEF platform ID + 0x88 bootable entry) — handles xorriso/mkisofs deferred sector counts (secCnt <= 1).
  4. ISO9660 /EFI Tree Fallback — scans /EFI/BOOT/* and *.efi files directly (capped at 16 MiB per file).

To host the primary multiboot menu on Partition 1, Cinderboot prefers an ISO providing both Shim and GRUB2 (HasShim && HasGRUB), falling back to any ISO with GRUB2. It also writes vendor-specific GRUB stub configs in:

  • EFI/BOOT/grub.cfg
  • EFI/ubuntu/grub.cfg
  • EFI/pop/grub.cfg
  • EFI/fedora/grub.cfg
  • EFI/debian/grub.cfg
  • EFI/opensuse/grub.cfg
  • plus a .disk/info marker on Partition 1 so Ubuntu's signed grubx64.efi binds to Partition 1 first instead of jumping straight to Partition 2.

2. Automatic Distro Profiling & Config Parsing (DetectLinuxBootWithEFI)

For each ISO, Cinderboot parses authentic boot configuration files in priority order to preserve distro-specific kernel flags (such as NVIDIA modules_load=nvidia or custom live-media-path):

  1. GRUB2 Configs: boot/grub/grub.cfg, boot/grub2/grub.cfg, efi/boot/grub.cfg, boot/grub/loopback.cfg (checked in both ISO9660 and extracted ESP).
  2. systemd-boot Loader Entries: loader/entries/*.conf from both ISO9660 and appended FAT ESP (prioritizing pop/live/current entries ahead of recovery/fallback/memtest).
  3. ISOLINUX / SYSLINUX Configs: isolinux/isolinux.cfg, isolinux/live.cfg, isolinux/txt.cfg, syslinux/syslinux.cfg, boot/syslinux/syslinux.cfg (following include directives recursively up to depth 4).

Parsed kernel/initrd paths are validated against the ISO9660 tree (resolving ESP-relative paths back to exact ISO9660 paths such as /casper_pop-os_.../vmlinuz.efi).

3. Supported Linux Distro Families & PARTUUID Pinning

Family Typical Distros Live Root Pinning Injected by BuildKernelArgs
pop-os Pop!_OS (Intel / NVIDIA) boot=casper, live-media-path=/<casper_dir>, live-media=/dev/disk/by-partuuid/<PARTUUID> (inserted before ---)
ubuntu Ubuntu, Linux Mint, Zorin, Elementary boot=casper, live-media-path (if non-standard), live-media=/dev/disk/by-partuuid/<PARTUUID>
fedora Fedora, Rocky, Alma, Nobara, Bazzite root=live:PARTUUID=<PARTUUID> (replaces root=live:CDLABEL=...)
void Void Linux root=live:PARTUUID=<PARTUUID> with Void live kernel flags
arch Arch Linux, EndeavourOS, CachyOS, Garuda Strips archisolabel/archisosearchuuid, sets archisodevice=/dev/disk/by-partuuid/<PARTUUID> (loads Intel/AMD microcode initrds when present)
manjaro Manjaro misobasedir=manjaro, misolabel=<VolumeLabel> (loads intel_ucode.img/amd_ucode.img when present)
debian Debian, Kali, Parrot, Tails, MX Linux boot=live, live-media=/dev/disk/by-partuuid/<PARTUUID>
opensuse openSUSE root=live:PARTUUID=<PARTUUID>
generic Other dracut / GRUB2 Linux ISOs Replaces root=live:CDLABEL= / root=live:LABEL= with root=live:PARTUUID=<PARTUUID>, or falls back to configfile / UEFI chainloader

4. Generated Boot Menu & Native UEFI Chainload Fallback

Partition 1's /boot/grub/grub.cfg locates each distro partition using search --no-floppy --fs-uuid --set=root <ISO9660-UUID> (falling back to --label, --file, or (hd0,gptN)), and automatically generates:

  • One top-level menuentry per selected Linux ISO.
  • A Native UEFI Chainload (Secure Boot / Fallback) submenu containing each distro's own extracted EFI binaries stored under /EFI/cinderboot/d<N>/, useful when mixing distros signed by different Secure Boot vendor keys.
  • UEFI Firmware Settings (fwsetup) and Reboot (reboot) utility entries.

Note

Multiboot mode requires uncompressed ISO9660 Linux ISOs and rejects Windows ISOs or compressed .gz/.bz2/.zip archives with a clear error message. Windows ISOs should be flashed individually in windows-fat32 mode.

Clone this wiki locally