]> code.delx.au - monosys/commitdiff
multiboot improvements
authorJames Bunton <jamesbunton@delx.net.au>
Sun, 11 Jun 2023 04:03:56 +0000 (14:03 +1000)
committerJames Bunton <jamesbunton@delx.net.au>
Sun, 11 Jun 2023 09:35:05 +0000 (19:35 +1000)
- Split into ESP and ext4 partition to support larger ISO images
- Wipe filesystem labels
- Better graphics mode on HiDPI screens
- Quiet/Splash on by default
- memtest now works on EFI
- Debian Live support
- Updated Ubuntu/Fedora to work with the latest images
- Fix FreeDOS URL

hacks/multiboot-setup

index 1358aa572e60b3bc185c943641cc493586e17c44..aafcb4883d2f9f0cf9e4515844d1e61431de3f37 100755 (executable)
@@ -2,7 +2,8 @@
 
 set -eu
 
-PARTITION_LABEL="multiboot"
+PARTITION_LABEL_ESP="multibt-esp"
+PARTITION_LABEL_DATA="multiboot"
 MULTIBOOT_MNT="${MULTIBOOT_MNT:-/mnt/multiboot}"
 
 function cmd_format {
@@ -14,9 +15,21 @@ function cmd_format {
 
     sudo -k
     DISK_DEVICE="$1"
-    PARTITION_DEVICE="${DISK_DEVICE}1"
-    echo -ne 'label: dos\ntype=c, bootable\n' | sudo sfdisk "$DISK_DEVICE"
-    sudo mkfs.vfat -n "$PARTITION_LABEL" "$PARTITION_DEVICE"
+    print_sfdisk_command | sudo sfdisk --wipe always --wipe-partitions always "$DISK_DEVICE"
+    udevadm settle
+    sudo mkfs.vfat -n "${PARTITION_LABEL_ESP}" "/dev/disk/by-partlabel/${PARTITION_LABEL_ESP}"
+    sudo mkfs.ext4 -L "${PARTITION_LABEL_DATA}" -E "root_owner=$(id -u):$(id -g)" "/dev/disk/by-partlabel/${PARTITION_LABEL_DATA}"
+}
+
+function print_sfdisk_command {
+    cat <<EOT
+label: gpt
+unit: sectors
+
+size=10M, type=uefi, name="$PARTITION_LABEL_ESP"
+size=1M, type=21686148-6449-6E6F-744E-656564454649
+type=linux, name="$PARTITION_LABEL_DATA"
+EOT
 }
 
 function cmd_grub {
@@ -51,7 +64,7 @@ function install_grub_efi {
             --target="$arch" \
             --no-nvram \
             --removable \
-            --efi-directory="$MULTIBOOT_MNT" \
+            --efi-directory="${MULTIBOOT_MNT}/EFI" \
             --boot-directory="$MULTIBOOT_MNT" \
             "$DISK_DEVICE"
     done
@@ -69,16 +82,19 @@ function install_grub_cfg {
 function cmd_mount {
     set -x
 
-    PARTITION_DEVICE="$(readlink -f "/dev/disk/by-label/${PARTITION_LABEL}")"
+    while sudo umount "/dev/disk/by-partlabel/${PARTITION_LABEL_ESP}" &> /dev/null; do true; done
+    while sudo umount "/dev/disk/by-partlabel/${PARTITION_LABEL_DATA}" &> /dev/null; do true; done
     sudo mkdir -p "$MULTIBOOT_MNT"
-    while sudo umount "$PARTITION_DEVICE" &> /dev/null; do true; done
-    sudo mount "$PARTITION_DEVICE" "$MULTIBOOT_MNT" -o "uid=$(whoami)"
+    sudo mount "/dev/disk/by-partlabel/${PARTITION_LABEL_DATA}" "$MULTIBOOT_MNT"
+    mkdir -p "${MULTIBOOT_MNT}/EFI"
+    sudo mount "/dev/disk/by-partlabel/${PARTITION_LABEL_ESP}" "${MULTIBOOT_MNT}/EFI"
 }
 
 function cmd_umount {
     set -x
 
-    sudo umount "$MULTIBOOT_MNT"
+    sudo umount "${MULTIBOOT_MNT}/EFI" || true
+    sudo umount "$MULTIBOOT_MNT" || true
     sudo rmdir "$MULTIBOOT_MNT"
 }
 
@@ -87,7 +103,7 @@ function cmd_freedos {
 
     local SYSLINUX_VERSION="6.03"
     local SYSLINUX_URL="https://www.kernel.org/pub/linux/utils/boot/syslinux/syslinux-${SYSLINUX_VERSION}.tar.gz"
-    local FREEDOS_URL="http://www.freedos.org/download/download/FD12LITE.zip"
+    local FREEDOS_URL="https://www.ibiblio.org/pub/micro/pc-stuff/freedos/files/distributions/1.2/official/FD12LITE.zip"
 
     curl -fL "$SYSLINUX_URL" | \
         tar xz --no-same-owner --strip-components=3 -C "$MULTIBOOT_MNT" \
@@ -97,30 +113,43 @@ function cmd_freedos {
 }
 
 function cmd_memtest {
-    curl -fL "https://www.memtest.org/download/5.01/memtest86+-5.01.bin.gz" | \
-        zcat - > "${MULTIBOOT_MNT}/memtest.bin"
+    curl -fL -o "${MULTIBOOT_MNT}/memtest.tmp.zip" "https://memtest.org/download/v6.20/mt86plus_6.20_64.grub.iso.zip"
+    unzip -d "$MULTIBOOT_MNT" "${MULTIBOOT_MNT}/memtest.tmp.zip"
+    rm "${MULTIBOOT_MNT}/memtest.tmp.zip"
 }
 
 function print_grub_cfg {
     cat <<EOT
+search --set=root --label $PARTITION_LABEL_DATA
+
 insmod all_video
+insmod gfxterm
+loadfont unicode
+set gfxmode=1024x768
+terminal_output gfxterm
+
 insmod part_msdos
 insmod progress
 insmod regexp
-search --set=root --label $PARTITION_LABEL
+
+set maybe_quiet='quiet splash'
 set maybe_to_ram=''
 
-menuentry "Copy ISO image to ram before booting" {
+menuentry "Copy ISO image to ram before booting" {
   # copytoram is used by arch
   # toram is used by casper based images (tails, Ubuntu, etc)
   set maybe_to_ram="copytoram toram"
 }
 
+menuentry "! Verbose" {
+  set maybe_quiet=''
+}
+
 function setup_arch {
   menuentry "\$1" {
     loopback loop \$1
     echo "Loading kernel..."
-    linux (loop)/arch/boot/x86_64/vmlinuz-* img_label=${PARTITION_LABEL} img_loop=\$1 archisobasedir=arch earlymodules=loop \$maybe_to_ram
+    linux (loop)/arch/boot/x86_64/vmlinuz-* img_label=${PARTITION_LABEL_DATA} img_loop=\$1 archisobasedir=arch earlymodules=loop \$maybe_to_ram \$maybe_quiet
     echo "Loading initrd (and microcode if they exist)..."
     initrd (loop)/arch/boot/*.img (loop)/arch/boot/x86_64/initramfs-*.img
   }
@@ -133,13 +162,16 @@ done
 
 function setup_debian {
   menuentry "\$1" {
-    linux \$1/vmlinuz
-    initrd \$1/initrd.gz
+    loopback loop \$1
+    echo "Loading kernel..."
+    linux (loop)/live/vmlinuz* boot=live components findiso=\$1 \$maybe_to_ram \$maybe_quiet
+    echo "Loading initrd..."
+    initrd (loop)/live/initrd*
   }
 }
-for d in /debian-*-hd-media; do
-  if [ -d "\$d" ]; then
-    setup_debian \$d
+for iso in /debian-live-*.iso /isos/debian-live-*.iso; do
+  if [ -f "\$iso" ]; then
+    setup_debian \$iso
   fi
 done
 
@@ -155,20 +187,32 @@ if [ -f /memdisk -a -f /FD12LITE.zip ]; then
   }
 fi
 
-if [ -f /memtest.bin ]; then
-  menuentry "/memtest" {
-    linux16 /memtest.bin
+
+function setup_memtest {
+  menuentry "\$1" {
+    loopback loop \$1
+    if [ \${grub_platform} = pc ]; then
+      linux (loop)/boot/memtest
+    else
+      linux (loop)/EFI/BOOT/memtest
+    fi
   }
-fi
+}
+for iso in /mt86plus*.grub.iso /isos/mt86plus*.grub.iso; do
+  if [ -f "\$iso" ]; then
+    setup_memtest \$iso
+  fi
+done
+
 
 function setup_fedora {
   menuentry "\$1" {
     loopback loop \$1
     probe -s iso_label -l (loop)
     echo "Loading kernel..."
-    linux (loop)/isolinux/vmlinuz root=live:CDLABEL=\$iso_label rd.live.image quiet iso-scan/filename=\$1
+    linux (loop)/images/pxeboot/vmlinuz root=live:CDLABEL=\$iso_label rd.live.image iso-scan/filename=\$1 \$maybe_quiet
     echo "Loading initrd..."
-    initrd (loop)/isolinux/initrd.img
+    initrd (loop)/images/pxeboot/initrd.img
   }
 }
 for iso in /Fedora-Workstation-Live-*.iso /isos/Fedora-Workstation-Live-*.iso; do
@@ -181,7 +225,7 @@ function setup_ubuntu {
   menuentry "\$1" {
     loopback loop \$1
     echo "Loading kernel..."
-    linux (loop)/casper/vmlinuz* boot=casper quiet iso-scan/filename=\$1 \$maybe_to_ram
+    linux (loop)/casper/vmlinuz* layerfs-path=minimal.standard.live.squashfs boot=casper iso-scan/filename=\$1 \$maybe_to_ram \$maybe_quiet
     echo "Loading initrd..."
     initrd (loop)/casper/initrd*
   }
@@ -196,7 +240,7 @@ function setup_tails {
   menuentry "\$1" {
     loopback loop \$1
     echo "Loading kernel..."
-    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 splash quiet \$maybe_to_ram
+    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
     echo "Loading initrd..."
     initrd (loop)/live/initrd*
   }