FAT32 Partitionless Void Linux Live USB

Published on 2020-07-14 by Dash Eclipse

1 What is this about and why do I create Live USB this way

I use void-live as my Live USB because it supports booting into RAM, so I can eject USB stick after boot into LiveOS. And it's esay to use void-mklive to generate customized iso, it's simple and just works.

But I don't want to use dd to write iso to my USB stick each time I need to use Live USB, or use a dedicated USB stick for the LiveOS. I can't use the USB stick to store other files once I create Live USB this way.

The solution is pretty simple, just create one FAT32 filesystem on the USB stick without any partition table, install bootloaders and copy LiveOS to it, and then configure the bootloader to boot the LiveOS.

1.1 Advantages

  • Works for both UEFI and Legacy BIOS
  • Maximally use the storage, everything in one filesystem
  • Could still use the USB stick for storing files as noraml
  • Easy to delete the LiveOS from the USB stick, just remove these files
  • Simple and just works, no dirty hacks, no need to load iso files
  • No need to install boot code1

1.2 How does it work?

It's pretty simple, just install the bootloader, configure it to load vmlinuz the linux kernel and initrd the initramfs and it will load LiveOS/squashfs.img from the FAT32 filesystem which labeled as VOID_​LIVE.

Just install bootloaders for UEFI and Legacy BIOS, I choose rEFInd for UEFI and syslinux for Legacy BIOS.

For UEFI, a FAT32 filesystem is necessary for loading a boot manager or bootloader, the FAT32 filesystem does not necessarily need to be inside a GPT or MBR partition table, it could on the whole device without any partition table (a.k.a. partitionless).

For Legacy BIOS, when you have a partition table on the hard drive, you need to install the boot code to the device to be able to boot from it, and the partition which contains the bootloader should be marked as active. But you don't need to install boot code for a partitionless setup1, it just boots from the filesystem.

2 FAT32 filesystem creation and file directory structure

Assume the USB stick where we are going to create Live USB on is /dev/sdc and the FAT32 volume name is VOID_LIVE, you can create it with this command. Note the volume name can be other value but must be identical as boot options specified in bootloader configuration files.

sudo mkfs.vfat -I -F32 -n VOID_LIVE /dev/sdc
  • LiveOS/ linux kernel, initramfs and LiveOS from void-live 2
  • EFI/ rEFInd stuff for UEFI boot
  • syslinux/ syslinux stuff for legacy BIOS boot

Boot options can be found in boot/isolinux/isolinux.cfg or boot/grub/grub_void.cfg from void-live iso.

VOID_LIVE
├── EFI
│   ├── BOOT
│   │   ├── BOOTX64.EFI
│   │   └── refind.conf
│   └── refind
│       ├── refind.conf
│       └── refind_x64.efi
├── LiveOS
│   ├── initrd
│   ├── squashfs.img
│   └── vmlinuz
└── syslinux
    ├── ldlinux.c32
    ├── ldlinux.sys
    └── syslinux.cfg

5 directories, 10 files

3 UEFI

I use rEFInd Boot Manager for UEFI boot, you can just download it from the official website and copy it to the FAT32 filesystem, or install refind the voidlinux package and then copy it from /usr/share/refind. It looks better with themes such like refind-theme-regular. You are free to customize it.

EFI/{BOOT,refind}/refind.conf

timeout 20

menuentry "Void Linux (x86_64-musl)" {
    loader LiveOS/vmlinuz
    initrd /LiveOS/initrd
    options "root=live:CDLABEL=VOID_LIVE ro init=/sbin/init rd.luks=0 rd.md=0 rd.dm=0 loglevel=4 gpt add_efi_memmap vconsole.unicode=1 vconsole.keymap=dvorak-programmer locale.LANG=en_US.UTF-8  rd.live.overlay.overlayfs=1"
}

menuentry "Void Linux (x86_64-musl) (RAM)" {
    loader LiveOS/vmlinuz
    initrd /LiveOS/initrd
    options "root=live:CDLABEL=VOID_LIVE ro init=/sbin/init rd.luks=0 rd.md=0 rd.dm=0 loglevel=4 gpt add_efi_memmap vconsole.unicode=1 vconsole.keymap=dvorak-programmer locale.LANG=en_US.UTF-8  rd.live.overlay.overlayfs=1  rd.live.ram"
}

4 Legacy BIOS

I use syslinux because it's more lightweight than grub, syslinux the package is required to install syslinux to USB stick. You can use the minimal config or graphical boot menu config, I recommend to use the minimal one.

4.1 Minimal config

To avoid syslinux Boot Error I just use this minimal configuration without any non-core syslinux modules, and only run the extlinux/syslinux command once. I recommend you to create the Live USB in this order.

  1. Create FAT32 filesystem
  2. mount it to VOID_​LIVE, create VOID_​LIVE/syslinux/ folder
  3. Install syslinux with extlinux --install VOID_LIVE/syslinux
  4. Add syslinux/syslinux.cfg and LiveOS/{vmlinuz,initrd,squashfs.img}

syslinux/syslinux.cfg

PROMPT 1
TIMEOUT 50
DEFAULT voidram

LABEL void
	LINUX /LiveOS/vmlinuz
	APPEND initrd=/LiveOS/initrd root=live:CDLABEL=VOID_LIVE init=/sbin/init ro rd.luks=0 rd.md=0 rd.dm=0 loglevel=4 vconsole.unicode=1 vconsole.keymap=dvorak-programmer locale.LANG=en_US.UTF-8  rd.live.overlay.overlayfs=1

LABEL voidram
	LINUX /LiveOS/vmlinuz
	APPEND initrd=/LiveOS/initrd root=live:CDLABEL=VOID_LIVE init=/sbin/init ro rd.luks=0 rd.md=0 rd.dm=0 loglevel=4 vconsole.unicode=1 vconsole.keymap=dvorak-programmer locale.LANG=en_US.UTF-8  rd.live.overlay.overlayfs=1  rd.live.ram

4.2 Graphical boot menu

You can check boot/isolinux/{*.c32,isolinux.cfg} from void-live iso for dependencies and config to use graphical boot menu, but from my experience you need to create the Live USB in this order to avoid syslinux Boot Error (not able to boot), especially when the squashfs.img is large.

  1. Create FAT32 filesystem
  2. mount it to VOID_​LIVE
  3. Add syslinux/{chain,libcom32,libutil,vesamenu}.c32 (from /usr/lib/syslinux), /syslinux.cfg (optionally splash.png), and LiveOS/{vmlinuz,initrd}
  4. Install syslinux with extlinux --install VOID_LIVE/syslinux
  5. Add VOID_​LIVE/LiveOS/squashfs.img
  6. umount VOID_​LIVE

Note it may won't able to boot if you change any of files syslinux may load, including kernel and initramfs. Reinstall syslinux to the USB stick won't help and the only solution I know is recreate the FAT32 filesystem and start over again.

Footnotes: