ezup.dev

Source Code of Dash Eclipse's Personal Site (ezup.dev)
git clone git://ezup.dev/ezup.dev.git
Log | Files | Refs | README | LICENSE

fat32-partitionless-voidlinux-liveusb.org (7394B)


      1#+STARTUP: content
      2#+TITLE: FAT32 Partitionless Void Linux Live USB
      3#+AUTHOR: Dash Eclipse
      4#+DATE: [2020-07-14 Tue]
      5#+KEYWORDS: voidlinux, liveusb, liveos, refind, syslinux, uefi, legacy bios
      6#+DESCRIPTION: Install Void Linux LiveOS on A FAT32 Partitionless USB Stick, Works for Both UEFI and Legacy BIOS
      7#+OPTIONS: toc:t
      8
      9* What is this about and why do I create Live USB this way
     10
     11  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.
     12
     13  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.
     14
     15  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.
     16
     17** Advantages
     18
     19   - Works for both UEFI and Legacy BIOS
     20   - Maximally use the storage, everything in one filesystem
     21   - Could still use the USB stick for storing files as noraml
     22   - Easy to delete the LiveOS from the USB stick, just remove these files
     23   - Simple and just works, no dirty hacks, no need to load iso files
     24   - No need to install boot code[fn:2]
     25
     26** How does it work?
     27
     28   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~.
     29
     30   Just install bootloaders for UEFI and Legacy BIOS, I choose rEFInd for UEFI and syslinux for Legacy BIOS.
     31
     32   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).
     33
     34   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 setup[fn:2], it just boots from the filesystem.
     35
     36* FAT32 filesystem creation and file directory structure
     37
     38  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.
     39  #+BEGIN_SRC sh
     40    sudo mkfs.vfat -I -F32 -n VOID_LIVE /dev/sdc
     41  #+END_SRC
     42
     43  - ~LiveOS/~ linux kernel, initramfs and LiveOS from void-live [fn:1]
     44  - ~EFI/~ rEFInd stuff for UEFI boot
     45  - ~syslinux/~ syslinux stuff for legacy BIOS boot
     46  Boot options can be found in ~boot/isolinux/isolinux.cfg~ or ~boot/grub/grub_void.cfg~ from void-live iso.
     47  #+BEGIN_EXPORT html
     48  <pre style="line-height:1;">
     49  VOID_LIVE
     50  ├── EFI
     51  │   ├── BOOT
     52  │   │   ├── BOOTX64.EFI
     53  │   │   └── refind.conf
     54  │   └── refind
     55  │       ├── refind.conf
     56  │       └── refind_x64.efi
     57  ├── LiveOS
     58  │   ├── initrd
     59  │   ├── squashfs.img
     60  │   └── vmlinuz
     61  └── syslinux
     62      ├── ldlinux.c32
     63      ├── ldlinux.sys
     64      └── syslinux.cfg
     65
     66  5 directories, 10 files
     67  </pre>
     68  #+END_EXPORT
     69
     70* UEFI
     71
     72  I use rEFInd Boot Manager for UEFI boot, you can just download it from [[https://www.rodsbooks.com/refind/getting.html][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 [[https://github.com/munlik/refind-theme-regular][refind-theme-regular]]. You are free to customize it.
     73
     74  ~EFI/{BOOT,refind}/refind.conf~
     75  #+BEGIN_EXAMPLE
     76    timeout 20
     77
     78    menuentry "Void Linux (x86_64-musl)" {
     79	loader LiveOS/vmlinuz
     80	initrd /LiveOS/initrd
     81	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"
     82    }
     83
     84    menuentry "Void Linux (x86_64-musl) (RAM)" {
     85	loader LiveOS/vmlinuz
     86	initrd /LiveOS/initrd
     87	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"
     88    }
     89  #+END_EXAMPLE
     90
     91* Legacy BIOS
     92
     93  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.
     94
     95** Minimal config
     96
     97   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.
     98
     99   1. Create FAT32 filesystem
    100   2. mount it to VOID_​LIVE, create VOID_​LIVE/syslinux/ folder
    101   3. Install syslinux with ~extlinux --install VOID_LIVE/syslinux~
    102   4. Add syslinux/syslinux.cfg and LiveOS/{vmlinuz,initrd,squashfs.img}
    103
    104   ~syslinux/syslinux.cfg~
    105   #+BEGIN_EXAMPLE
    106     PROMPT 1
    107     TIMEOUT 50
    108     DEFAULT voidram
    109
    110     LABEL void
    111	     LINUX /LiveOS/vmlinuz
    112	     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
    113
    114     LABEL voidram
    115	     LINUX /LiveOS/vmlinuz
    116	     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
    117   #+END_EXAMPLE
    118
    119** Graphical boot menu
    120
    121   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.
    122
    123   1. Create FAT32 filesystem
    124   2. mount it to VOID_​LIVE
    125   3. Add ~syslinux/{chain,libcom32,libutil,vesamenu}.c32~ (from ~/usr/lib/syslinux~), ~/syslinux.cfg~ (optionally ~splash.png~), and ~LiveOS/{vmlinuz,initrd}~
    126   4. Install syslinux with ~extlinux --install VOID_LIVE/syslinux~
    127   5. Add VOID_​LIVE/LiveOS/squashfs.img
    128   6. umount VOID_​LIVE
    129
    130   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.
    131
    132* Footnotes
    133
    134[fn:1] Use the official [[https://voidlinux.org/download/][void-live]] or create your own iso by using [[https://github.com/void-linux/void-mklive][void-mklive]]
    135
    136[fn:2] [[https://unix.stackexchange.com/a/103568][For Legacy BIOS, Using a filesystem without a partition table thus not only saves space, but also a step in the boot process.]]