Iso building

From Mintarc Forge

ISO Building

When you get ready to compile the ISO ensure you pay attention to these things

Install and confifgure the rootfs

You need to prep the rootfs so that you can compile it this means you wan to configure it and install software that you will use in the ISO.

sudo mount --bind /dev /paths to your/chroot_folder/dev 
sudo mount --bind /proc /paths to your/chroot_folder/proc 
sudo mount --bind /sys /paths to your/chroot_folder/sys 
sudo mount -t devpts devpts /paths to your/chroot_folder/dev/pts

When building an ISO from a chroot folder, you need to bind certain system directories (/dev, /proc, /sys, and /dev/pts) to the chroot environment before installing software. This is because these directories provide essential system-level interfaces that allow the chroot environment to function as if it were a complete operating system. Here's why each mount is necessary:

  1. /dev: This directory contains device files that represent hardware devices (e.g., disks, terminals). Binding /dev ensures that the chroot environment has access to these device files, which are often required during package installation or configuration processes.
  2. /proc: The /proc directory is a virtual filesystem that provides information about system processes and hardware. Many installation scripts and tools rely on data from /proc for system configuration.
  3. /sys: Similar to /proc, /sys is a virtual filesystem that provides information about the kernel and hardware devices. Binding /sys allows software inside the chroot to interact with the kernel as needed.
  4. /dev/pts: This is required for pseudo-terminal devices (used by terminal emulators). Without binding this directory, terminal-based tools may fail to work properly inside the chroot environment.

These bindings ensure that the chroot environment behaves like a regular system, allowing software installations and configurations to proceed smoothly. Once these directories are mounted, you can install packages or make other modifications within the chroot environment as part of your ISO-building process

Once those mounts are in place then go into the rootfs and install al the software you need and make all the configurations you prefer.

Setting up ISOLinux boot loader

ISOLINUX is a specialized bootloader from the Syslinux suite designed for booting Linux systems from ISO 9660 filesystems (CDs/DVDs) and El Torito-compliant media.

  • ISO 9660/El Torito Support: Boots directly from CDs/DVDs without requiring floppy emulation in "no emulation" mode, ensuring compatibility with modern BIOS/UEFI systems.
  • Hybrid ISO Capability:Generates ISOs that can be written to both CDs and USB drives (via embedded MBR), simplifying cross-media booting.
  • Lightweight Design: Minimalist footprint, ideal for live CDs and installation media (e.g., Ubuntu/Debian installers).
  • Customizable Boot Menus: Configurable via isolinux.cfg with options for text/graphical menus, kernel parameters, and multi-boot entries.

The reason we use this is because of legacy hardware, it is not meant for UEFI booting, we include it in Peppermint a as a bootloader primarily for BIOS-based booting of optical media (CDs/DVDs) and legacy compatibility

Files used for our configs are

Core Bootloader Files:

  • isolinux.bin Bootloader binary for BIOS systems. Required for El Torito bootable CDs.
  • isolinux.cfg Configuration file defining boot menu entries, kernel paths, and parameters.
  • boot.cat Boot catalog file generated by mkisofs to list bootable images.

Menu System Files

  • vesamenu.c32 Graphical menu module for VESA-compatible splash screens.
  • menu.cfg Menu configuration (often included by isolinux.cfg for modularity).
  • stdmenu.cfg Standard menu template (optional).
  • recovery.cfg Menu entries for recovery/rescue modes.
  • live.cfg Configuration for live session boot options.
  • utilities.cfg Tools menu (e.g., memory tests, hardware diagnostics).

Compatibility Modules:

  • libcom32.c32 Core library for COM32 modules (required for advanced features).
  • libmenu.c32 Menu-handling library.
  • libutil.c32 Utility functions (e.g., file parsing).
  • ldlinux.c32 Loader for SYSLINUX extensions.

Hardware Utilities:

  • hdt.c32 Hardware Detection Tool (lists CPU, RAM, PCI devices).
  • pci.ids Database of PCI hardware identifiers used by hdt.c32.

Boot Process Flow

  1. BIOS Loads isolinux.bin: The El Torito boot sector points to isolinux.bin, which initializes the bootloader.
  2. Read isolinux.cfg: Defines boot entries (e.g., "Live Session" or "Install") and kernel parameters.
  3. Load Modules:
    1. vesamenu.c32 renders graphical menus.
    2. hdt.c32 provides hardware diagnostics.
  4. Launch Kernel:Specified by KERNEL directives in isolinux.cfg (e.g., /boot/vmlinuz).

Example isolinux.cfg Structure

DEFAULT vesamenu.c32
PROMPT 0
TIMEOUT 300

MENU TITLE Boot Menu
MENU INCLUDE stdmenu.cfg

LABEL live
  MENU LABEL ^Start Live Session
  KERNEL /boot/vmlinuz
  APPEND initrd=/boot/initrd.img root=/dev/sr0

LABEL recovery
  MENU LABEL ^Recovery Mode
  KERNEL /boot/vmlinuz
  APPEND initrd=/boot/initrd.img single

MENU INCLUDE utilities.cfg

Configure Grub

GRUB is required for UEFI systems because it provides native UEFI compatibility, which ISOLINUX lacks. Peppermit also needs to include the grub configurations

boot/grub/ Directory (GRUB Configuration)

  • grub.cfg Main GRUB configuration for UEFI/BIOS booting. Contains boot menu entries and kernel parameters.
  • config.cfg Custom configuration (likely sourced by grub.cfg). Used to modularize settings (e.g., variables, device detection).
  • install.cfg Installer-specific configuration (e.g., kernel paths for Debian/Ubuntu installations).
  • install_start.cfg Pre-installation boot logic (e.g., hardware checks or initramfs setup).
  • loopback.cfg Loopback boot configuration for ISO-based installations (e.g., loopback loop /cdrom/image.iso).
  • theme.cfg GRUB theme settings (fonts, colors, backgrounds).

Example grub.cfg

menuentry "Live ISO" {
  set root=(hd0,1)
  loopback loop /iso/image.iso
  linux (loop)/boot/vmlinuz boot=live
  initrd (loop)/boot/initrd.img
}

Example theme.cfg

set theme=/boot/grub/themes/custom/theme.txt  # Defined in theme.cfg

Example loopback.cfg

menuentry "Boot ISO" {
  loopback loop (hd1)/path/to/image.iso
  linux (loop)/casper/vmlinuz boot=casper
  initrd (loop)/casper/initrd.img
}

Live System

The live folder in a Linux ISO is critical for live system functionality, which allows users to boot and run an operating system directly from media (USB/CD) without installation.

Core Live System Files

The live folder contains key components for booting a functional OS:

  • Filesystem.squashfs: Compressed read-only OS root filesystem (includes /bin, /usr, etc.)[^2^][^5^].
    • vmlinuz: Linux kernel loaded during boot[^2^][^5^].
    • initrd.img: Initial RAM disk with tools to mount SquashFS and initialize hardware[^2^][^5^].

How It Works

  • Boot Process:
    • GRUB/ISOLINUX loads vmlinuz and initrd.img, which decompress filesystem.squashfs into RAM or a temporary disk layer[^2^][^5^].
  • Union Mounts:
    • Combines the read-only SquashFS with a writeable layer (e.g., tmpfs in RAM or casper-rw for persistence)[^2^][^5^].

Use Cases

  • Testing/Portability:
    • Run Linux without altering the host system’s disk[^3^][^5^].
  • System Recovery:
    • Access broken systems via live tools (e.g., gparted, fsck)[^3^][^8^].
  • Installation:
    • Many installers (e.g., Ubuntu) run as live sessions before writing to disk[^1^][^5^].

Persistence (Optional)

  • casper-rw File/Partition:
    • Stores user data (e.g., installed apps, files) across reboots[^2^][^5^].
    • Non-Persistent Mode:
  • Changes are discarded after shutdown (uses RAM for temporary writes)[^2^].

Example Folder structure

/live/
├── filesystem.squashfs  # OS root (compressed)
├── vmlinuz              # Kernel
└── initrd.img           # Initial RAM disk

Make the filesystem.squashfs

filesystem.squashfs is a compressed, read-only filesystem image used in Linux live environments (inthis case Debian) and embedded systems. Here's a structured breakdown:

  • Compression: Uses algorithms like zlib, lz4, lzo, xz, or zstd to minimize size.
  • Read-Only: Protects system integrity by preventing writes to the base OS.
  • Efficiency:
    • Small inodes: ~8 bytes per inode (directory/file metadata).
    • Block sizes: Up to 1 MB (default 128 KB) for better compression ratios.

We use this as it enables booting an OS directly from USB/CD without installation

Example command

sudo mksquashfs /pathto your chroot /path to save the/live/filesystem.squashfs -comp xz -e boot
  1. Generate with mksquashfs
  2. Uses XZ compression (high ratio, slower than alternatives like lz4 or zstd). that is -comp xz
  3. Excludes the /boot directory from the image (common for ISOs where boot files are stored separately in /isolinux/ or /boot/grub/) that is -e boot

Compile the ISO

In this case we use xorriso. This is a command-line tool for creating, modifying, and burning ISO 9660 filesystem images. It serves as both a standalone ISO manipulator and a modern replacement for older tools like mkisofs and genisoimage

sudo xorriso -as mkisofs -o ./yourisoname.iso -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -eltorito-alt-boot -e boot/grub/efi.img -no-emul-boot -R -V "YourISO" -follow-links ./iso_configs

Lets break down the commands

  1. xorriso -as mkisofs - Emulates mkisofs behavior for compatibility with legacy ISO creation workflows
  2. -o ./yourisoname.iso - Specifies the output ISO filename (mylive.iso in the current directory)
  3. -b isolinux/isolinux.bin - Sets BIOS boot image (ISOLINUX bootloader)
  4. -c isolinux/boot.cat - Specifies the boot catalog path (required for El Torito BIOS booting)
  5. -no-emul-boot - Boots directly from isolinux.bin without emulating a floppy disk
  6. -boot-load-size 4 - Loads 4 sectors (512B each) of isolinux.bin into memory (historical requirement for older BIOSes)
  7. -boot-info-table - Embeds a BIOS boot information table (required by ISOLINUX)
  8. -eltorito-alt-boot- Enables dual boot entries (BIOS + UEFI) in the ISO's El Torito catalog
  9. --e boot/grub/efi.img - Points UEFI firmware to the GRUB EFI binary within the ISO
  10. -R - Enables Rock Ridge extensions for Unix permissions/long filenames
  11. -V "YourISO" -Sets the volume label
  12. -follow-links - Preserves symbolic links instead of copying their targets
  13. ./iso_configs - Source directory containing files to include in the ISO