Skip to content

Architecture and Pure Go Design

buntatoes edited this page Nov 28, 2026 · 1 revision

Architecture and Pure-Go Design

Cinderboot is architected as a zero-dependency Go monolith (go 1.24, CGO_ENABLED=0) composed of 10 packages (32 Go files, 9,345 LOC) plus one embedded single-file web UI (internal/ui/web/index.html, 665 lines). Every storage, filesystem, optical image, WIM archive, XML, elevation, and UI subsystem is implemented directly on top of the Go standard library and OS syscalls/IOCTLs.


High-Level System Architecture

flowchart TD
    User["User (Desktop UI or CLI)"]
    CLI["cmd/cinderboot (CLI & --install)"]
    UI["internal/ui (Loopback HTTP + SSE Server)"]
    Elev["internal/elevate (pkexec/sudo or UAC runas)"]
    Worker["cinderboot worker (Privileged Process)"]
    Flash["internal/flash (Job Orchestrator)"]

    Raw["Raw Stream & Verify Engine"]
    ISO["ISO -> GPT + FAT32 Engine"]
    Multi["Multi-Distro UEFI Multiboot Engine"]

    Device["internal/device (sysfs / Win32 IOCTLs + Write Guards)"]
    Image["internal/image (UDF 1.02, ISO9660, Distro, EFI, Streams)"]
    FS["internal/fs (GPT, FAT32 Writer, FAT12/16/32 Reader)"]
    WIM["internal/wim (Lossless .wim -> .swm Splitter)"]
    Unattend["internal/unattend (autounattend.xml Generator)"]
    USB["Removable USB Block Device"]

    User --> CLI
    User --> UI
    CLI --> Elev
    UI --> Elev
    Elev --> Worker
    Worker --> Flash

    Flash --> Raw
    Flash --> ISO
    Flash --> Multi

    Raw --> Image
    Raw --> FS
    Raw --> Device

    ISO --> Image
    ISO --> FS
    ISO --> WIM
    ISO --> Unattend
    ISO --> Device

    Multi --> Image
    Multi --> FS
    Multi --> Device

    Device --> USB
Loading

Package Map

Package Source Files Test Files Responsibility
cmd/cinderboot main.go (+ embedded icon.svg, icon.png, rsrc_windows_amd64.syso) — Entrypoint, CLI command dispatch, interactive ERASE guard, privileged worker runner, Linux --install/--uninstall
internal/version version.go — Build-time injectable version string (Version, overridden via -ldflags)
internal/device types.go, linux.go, windows.go device_test.go Removable USB enumeration, OS/protected-mount blocking, unmounting/volume locking, raw read/write handles, cache flush & partition rescan
internal/elevate elevate.go, elevate_linux.go, elevate_windows.go — Privilege-separated worker launch (pkexec/sudo on Linux, UAC ShellExecuteExW on Windows), JSONL progress streaming, and cross-privilege cancel sentinel IPC
internal/image detect.go, udf.go, iso9660.go, stream.go, efi.go, distro.go image_test.go Image classification, OSTA UDF 1.02 parser, ISO9660 + Rock Ridge + Joliet + El Torito parser, compressed stream decoding, UEFI bundle extraction, Linux distro boot profiling
internal/fs gpt.go, fat32.go, fatread.go fs_test.go Protective MBR + Primary/Backup GPT writer/parser/wiper/relocator, streaming FAT32 formatter & writer with VFAT LFN, read-only FAT12/16/32 reader
internal/wim split.go split_test.go Pure-Go lossless Microsoft WIM header/lookup-table parser and streaming .wim → .swm splitter
internal/unattend unattend.go unattend_test.go Validated Microsoft Windows Setup autounattend.xml generator with username sanitization
internal/flash job.go, raw.go, iso_fat32.go, multiboot.go flash_test.go Flash job orchestration, raw streaming with transient I/O recovery & SHA-256 verification, GPT+FAT32 ISO flashing, Multi-Distro Linux UEFI creation
internal/ui server.go, platform_linux.go, platform_windows.go, web/index.html — Loopback HTTP/SSE UI server (127.0.0.1), cryptographic session auth, native browser --app launcher, native file picker dialogs

Pure-Go Storage & Filesystem Stack (internal/fs)

Cinderboot avoids external tools like parted, gdisk, mkfs.vfat, mtools, or diskpart by writing exact on-disk structures directly to any io.ReadWriteSeeker.

GPT Engine (internal/fs/gpt.go)

  • Protective MBR + Primary & Backup GPT (WriteGPT / WriteSinglePartitionGPT):
    • Writes a Protective MBR (0xEE partition starting at LBA 1) at LBA 0.
    • Builds a 128-entry × 128-byte (16 KiB) partition entry array with IEEE CRC32 checksums, random RFC 4122 v4 mixed-endian GUIDs (NewRandomGUID), and UTF-16LE partition names (up to 36 code units).
    • Writes Primary GPT header at LBA 1, Primary Partition Array at LBA 2..33, Backup Partition Array at the disk tail, and Backup GPT header at the final sector (totalSectors - 1).
    • Aligns partitions to 1 MiB boundaries and exports standard mixed-endian GUIDs GPTTypeBasicData (EBD0A0A2-B9E5-4433-87C0-68B6B72699C7) and GPTTypeEFI (C12A7328-F81F-11D2-BA4B-00A0C93EC93B).
  • Partition Table Wiping (WipePartitionTables): Zeroes up to 1 MiB at both the start and physical end of the disk so stale MBR, Primary GPT, or tail Backup GPT structures cannot confuse firmware or OS probes.
  • Backup GPT Relocation (RelocateBackupGPT): After raw-flashing a hybrid GPT ISO smaller than the USB drive, validates the Primary GPT header and partition entry CRC32s, copies the Backup Partition Array and updated Backup GPT header to the physical end of the disk, updates AlternateLBA, LastUsableLBA, and Protective MBR sector count, and clears the old mid-disk backup header.
  • GPT Parser (ParseGPTPartitions): Reads GPT entries from hybrid ISOs or virtual disks to locate appended EFI System Partitions (GPTTypeEFI).

Pure-Go FAT32 Writer (internal/fs/fat32.go)

FAT32Writer formats and populates Microsoft-specification-compliant FAT32 partitions directly on raw block devices:

  • Cluster Geometry: Selects sectors-per-cluster automatically by partition size (512 B for ≤260 MiB, 4 KiB for ≤8 GiB, 8 KiB for ≤16 GiB, 16 KiB for ≤32 GiB, 32 KiB for >32 GiB), stepping down if needed to maintain FAT32's mandatory minimum of 65,525 clusters (>= 66,600 sectors / ~34 MiB minimum partition).
  • Layout: 32 reserved sectors (Boot Sector at sector 0, FSInfo at sector 1, Backup Boot Sector at sector 6, Backup FSInfo at sector 7), 2 FAT tables (FAT1 and FAT2), root directory starting at cluster 2 with a random 32-bit volume serial number (VolumeSerialString() formats as XXXX-XXXX for GRUB2 --fs-uuid).
  • VFAT Long File Names (LFN): Generates unique 8.3 Short File Names (~N collision suffixes when needed), computes the 8-bit SFN checksum, and emits reverse-ordered UTF-16LE LFN directory entries alongside standard 32-byte short entries.
  • Fast Sequential Writes: Allocates contiguous cluster chains and streams file data in 1 MiB cluster-aligned chunks with context cancellation checks (WriteFileCtx), flushing directory clusters, FAT1/FAT2, FSInfo, and boot sectors atomically on Close().

Pure-Go FAT12/FAT16/FAT32 Reader (internal/fs/fatread.go)

FATReader parses FAT12 (<4,085 clusters), FAT16 (<65,525 clusters), and FAT32 (>=65,525 clusters) filesystems read-only (including VFAT LFNs and cluster-chain loop protection up to 65,536 steps and directory depth cap 32). Cinderboot uses it to extract UEFI bootloaders and loader/entries/*.conf directly from Linux ISO EFI partitions and El Torito EFI boot images without mounting anything.


Pure-Go Image & Archive Parsers (internal/image)

All optical image parsers implement the unified ImageFS interface (Format(), VolumeLabel(), Walk(), Open(), OpenReaderAt()):

OSTA UDF 1.02 Reader (internal/image/udf.go)

Designed specifically to read official Microsoft Windows 10/11 ISOs created by oscdimg (where filenames and >4 GiB install.wim files reside in UDF rather than ISO9660):

  • Reads the Anchor Volume Descriptor Pointer (AVDP, Tag 2) at sector 256, then scans the Main Volume Descriptor Sequence for the Partition Descriptor (Tag 5), Logical Volume Descriptor (Tag 6), and Terminating Descriptor (Tag 8).
  • Follows the File Set Descriptor (Tag 256) to the Root Directory ICB and walks File Identifier Descriptors (Tag 257) and File Entries / Extended File Entries (Tags 261 and 266).
  • Supports inline data (adType == 3), Short Allocation Descriptors (adType == 0), Long Allocation Descriptors (adType == 1), chained Allocation Extent Descriptors (Tag 258, recursion capped at 64), and OSTA CS0 compressed Unicode strings (tag 8 Latin-1 and tag 16 UTF-16BE).
  • Provides both sequential io.ReadCloser (extentReader) and random-access io.ReaderAt (extentReaderAt) so the WIM splitter can read install.wim lookup tables directly out of the ISO with zero extraction.

ISO9660 + Rock Ridge + Joliet + El Torito Reader (internal/image/iso9660.go)

  • Scans volume descriptors starting at LBA 16 for Primary Volume Descriptor (Type 1), Joliet Supplementary Volume Descriptor (Type 2, UTF-16BE escape sequences %/@, %/C, %/E), and El Torito Boot Record (Type 0, "EL TORITO SPECIFICATION" catalog LBA).
  • Detects Rock Ridge (SUSP/RRIP) (SP, NM, RR, PX, plus CE continuation areas up to depth 4) and prefers PVD + Rock Ridge over Joliet when present so full POSIX filenames match GRUB2 and the Linux kernel (essential for distros like Pop!_OS with long casper_* directory names).
  • Handles multi-extent ISO9660 files (>4 GiB split across consecutive directory records) and extracts GRUB2-compatible ISO9660 timestamp UUIDs (YYYY-MM-DD-HH-MM-SS-CC), preferring modification timestamp over creation timestamp to match grub_iso9660_uuid and blkid.

Transparent Compressed Streams (internal/image/stream.go)

OpenRawStream provides zero-temp-disk streaming decompression using Go stdlib packages:

Extension Go Stdlib Decoder Expected Size
.iso, .img, .raw (default) Raw *os.File Exact file size
.gz compress/gzip Streaming (-1)
.bz2 compress/bzip2 Streaming (-1)
.zip archive/zip Exact uncompressed size of first .iso/.img/.raw entry (or largest file)

Note

Every Go source file in Cinderboot carries // SPDX-License-Identifier: GPL-3.0-only and compiles with zero third-party require directives in go.mod.

Clone this wiki locally