5 PARTITION_LABEL_ESP
="multibt-esp"
6 PARTITION_LABEL_DATA
="multiboot"
7 MULTIBOOT_MNT
="${MULTIBOOT_MNT:-/mnt/multiboot}"
10 if [ ! -b "${1:-}" ]; then
11 echo "Usage: $0 format /dev/sdX"
18 print_sfdisk_command | sudo sfdisk
--wipe always
--wipe-partitions always
"$DISK_DEVICE"
20 sudo mkfs.vfat
-n "${PARTITION_LABEL_ESP}" "/dev/disk/by-partlabel/${PARTITION_LABEL_ESP}"
21 sudo mkfs.ext4
-L "${PARTITION_LABEL_DATA}" -E "root_owner=$(id -u):$(id -g)" "/dev/disk/by-partlabel/${PARTITION_LABEL_DATA}"
24 function print_sfdisk_command
{
29 size=10M, type=uefi, name="$PARTITION_LABEL_ESP"
30 size=1M, type=21686148-6449-6E6F-744E-656564454649
31 type=linux, name="$PARTITION_LABEL_DATA"
36 DISK_DEVICE
="$(findmnt -n -o source "$MULTIBOOT_MNT" | sed 's/[0-9]*$//')"
37 if [ ! -b "$DISK_DEVICE" ]; then
38 echo "ERROR! Could not find disk to install bootloader. Try using mount."
49 function cmd_grubcfg
{
54 function install_grub_bios
{
57 --boot-directory="$MULTIBOOT_MNT" \
61 function install_grub_efi
{
62 for arch
in i386-efi x86_64-efi
; do
67 --efi-directory="${MULTIBOOT_MNT}/EFI" \
68 --boot-directory="$MULTIBOOT_MNT" \
73 function install_grub_cfg
{
74 if [[ -w "${MULTIBOOT_MNT}/grub/" ]]; then
75 # We already have write access, no need to use sudo
76 print_grub_cfg
> "${MULTIBOOT_MNT}/grub/grub.cfg"
78 print_grub_cfg | sudo
tee "${MULTIBOOT_MNT}/grub/grub.cfg" > /dev
/null
85 while sudo umount
"/dev/disk/by-partlabel/${PARTITION_LABEL_ESP}" &> /dev
/null
; do true
; done
86 while sudo umount
"/dev/disk/by-partlabel/${PARTITION_LABEL_DATA}" &> /dev
/null
; do true
; done
87 sudo mkdir
-p "$MULTIBOOT_MNT"
88 sudo mount
"/dev/disk/by-partlabel/${PARTITION_LABEL_DATA}" "$MULTIBOOT_MNT"
89 mkdir
-p "${MULTIBOOT_MNT}/EFI"
90 sudo mount
"/dev/disk/by-partlabel/${PARTITION_LABEL_ESP}" "${MULTIBOOT_MNT}/EFI"
96 sudo umount
"${MULTIBOOT_MNT}/EFI" || true
97 sudo umount
"$MULTIBOOT_MNT" || true
98 sudo
rmdir "$MULTIBOOT_MNT"
101 function cmd_freedos
{
104 local SYSLINUX_VERSION
="6.03"
105 local SYSLINUX_URL
="https://www.kernel.org/pub/linux/utils/boot/syslinux/syslinux-${SYSLINUX_VERSION}.tar.gz"
106 local FREEDOS_URL
="https://www.ibiblio.org/pub/micro/pc-stuff/freedos/files/distributions/1.2/official/FD12LITE.zip"
108 curl
-fL "$SYSLINUX_URL" | \
109 tar xz
--no-same-owner --strip-components=3 -C "$MULTIBOOT_MNT" \
110 "syslinux-${SYSLINUX_VERSION}/bios/memdisk/memdisk"
112 curl
-fL "$FREEDOS_URL" > "${MULTIBOOT_MNT}/FD12LITE.zip"
115 function cmd_memtest
{
116 curl
-fL -o "${MULTIBOOT_MNT}/memtest.tmp.zip" "https://memtest.org/download/v6.20/mt86plus_6.20_64.grub.iso.zip"
117 unzip -d "$MULTIBOOT_MNT" "${MULTIBOOT_MNT}/memtest.tmp.zip"
118 rm "${MULTIBOOT_MNT}/memtest.tmp.zip"
121 function print_grub_cfg
{
123 search --set=root --label $PARTITION_LABEL_DATA
129 terminal_output gfxterm
135 set maybe_quiet='quiet splash'
138 menuentry "! Copy ISO image to ram before booting" {
139 # copytoram is used by arch
140 # toram is used by casper based images (tails, Ubuntu, etc)
141 set maybe_to_ram="copytoram toram"
144 menuentry "! Verbose" {
148 function setup_arch {
151 echo "Loading kernel..."
152 linux (loop)/arch/boot/x86_64/vmlinuz-* img_label=${PARTITION_LABEL_DATA} img_loop=\$1 archisobasedir=arch earlymodules=loop \$maybe_to_ram \$maybe_quiet
153 echo "Loading initrd (and microcode if they exist)..."
154 initrd (loop)/arch/boot/*.img (loop)/arch/boot/x86_64/initramfs-*.img
157 for iso in /archlinux-*.iso /isos/archlinux-*.iso; do
158 if [ -f "\$iso" ]; then
163 function setup_debian {
166 echo "Loading kernel..."
167 linux (loop)/live/vmlinuz* boot=live components findiso=\$1 \$maybe_to_ram \$maybe_quiet
168 echo "Loading initrd..."
169 initrd (loop)/live/initrd*
172 for iso in /debian-live-*.iso /isos/debian-live-*.iso; do
173 if [ -f "\$iso" ]; then
178 if [ -f /memdisk -a -f /FD12LITE.zip ]; then
179 menuentry /FD12LITE.zip {
180 if [ \${grub_platform} = pc ]; then
182 initrd16 /FD12LITE.zip
184 echo "FreeDOS only works with BIOS boot."
191 function setup_memtest {
194 if [ \${grub_platform} = pc ]; then
195 linux (loop)/boot/memtest
197 linux (loop)/EFI/BOOT/memtest
201 for iso in /mt86plus*.grub.iso /isos/mt86plus*.grub.iso; do
202 if [ -f "\$iso" ]; then
208 function setup_fedora {
211 probe -s iso_label -l (loop)
212 echo "Loading kernel..."
213 linux (loop)/images/pxeboot/vmlinuz root=live:CDLABEL=\$iso_label rd.live.image iso-scan/filename=\$1 \$maybe_quiet
214 echo "Loading initrd..."
215 initrd (loop)/images/pxeboot/initrd.img
218 for iso in /Fedora-Workstation-Live-*.iso /isos/Fedora-Workstation-Live-*.iso; do
219 if [ -f "\$iso" ]; then
224 function setup_ubuntu {
227 set maybe_layerfs_path=''
228 for f in minimal.standard.live.squashfs; do
229 if [ -f "(loop)/casper/\$f" ]; then
231 set maybe_layerfs_path="layerfs-path=\$f"
232 echo "Setting \$maybe_layerfs_path"
235 echo "Loading kernel..."
236 linux (loop)/casper/vmlinuz* \$maybe_layerfs_path boot=casper iso-scan/filename=\$1 \$maybe_to_ram \$maybe_quiet
237 echo "Loading initrd..."
238 initrd (loop)/casper/initrd*
241 for iso in /ubuntu-*-desktop-*.iso /isos/ubuntu-*-desktop-*.iso; do
242 if [ -f "\$iso" ]; then
247 function setup_tails {
250 echo "Loading kernel..."
251 linux (loop)/live/vmlinuz* initrd=/live/initrd.img boot=live config iso-scan/filename=\$1 findiso=\$1 nopersistence noprompt timezone=Etc/UTC noautologin module=Tails slab_nomerge slub_debug=FZP mce=0 vsyscall=none page_poison=1 init_on_free=1 mds=full,nosmt \$maybe_to_ram \$maybe_quiet
252 echo "Loading initrd..."
253 initrd (loop)/live/initrd*
256 for iso in /tails-*.iso /isos/tails-*.iso; do
257 if [ -f "\$iso" ]; then
268 if [ "$(type -t -- "$CMD")" = "function" ]; then
271 echo "Usage: $0 [format|mount|grub|grubcfg|freedos|memtest|umount]"