X-Git-Url: https://code.delx.au/monosys/blobdiff_plain/0ce6d446467320f04a2496a6ae0ab3ee42803147..599dd6680ce416306c0a0dec4c1d12d9839b25b5:/multiboot-setup diff --git a/multiboot-setup b/multiboot-setup index af5d5ea..3e36eb9 100755 --- a/multiboot-setup +++ b/multiboot-setup @@ -4,8 +4,6 @@ set -eu PARTITION_LABEL="multiboot" MULTIBOOT_MNT="/mnt/multiboot" -SYSLINUX_VERSION="6.03" -SYSLINUX_URL="https://www.kernel.org/pub/linux/utils/boot/syslinux/syslinux-${SYSLINUX_VERSION}.tar.gz" function cmd_format { if [ ! -b "${1:-}" ]; then @@ -21,8 +19,8 @@ function cmd_format { sudo mkfs.vfat -n "$PARTITION_LABEL" "$PARTITION_DEVICE" } -function cmd_bootloader { - DISK_DEVICE="$(mount|grep /mnt/multiboot|cut -d' ' -f1|sed 's/[0-9]*$//')" +function cmd_grub { + DISK_DEVICE="$(findmnt -n -o source "$MULTIBOOT_MNT" | sed 's/[0-9]*$//')" if [ ! -b "$DISK_DEVICE" ]; then echo "ERROR! Could not find disk to install bootloader. Try using mount." exit 1 @@ -32,6 +30,12 @@ function cmd_bootloader { sudo -k install_grub_bios install_grub_efi + install_grub_cfg +} + +function cmd_grubcfg { + set -x + install_grub_cfg } function install_grub_bios { @@ -53,10 +57,14 @@ function install_grub_efi { done } +function install_grub_cfg { + print_grub_cfg | sudo tee "${MULTIBOOT_MNT}/grub/grub.cfg" > /dev/null +} + function cmd_mount { set -x - PARTITION_DEVICE="$(readlink -f /dev/disk/by-label/multiboot)" + PARTITION_DEVICE="$(readlink -f "/dev/disk/by-label/${PARTITION_LABEL}")" sudo mkdir -p "$MULTIBOOT_MNT" while sudo umount "$PARTITION_DEVICE" &> /dev/null; do true; done sudo mount "$PARTITION_DEVICE" "$MULTIBOOT_MNT" -o "uid=$(whoami)" @@ -69,135 +77,93 @@ function cmd_umount { sudo rmdir "$MULTIBOOT_MNT" } -function cmd_add_iso { - if [ ! -f "${MULTIBOOT_MNT}/$(basename "${1:-}")" ]; then - echo "Usage: $0 add_iso ${MULTIBOOT_MNT}/ubuntu.iso" - exit 1 - fi +function cmd_freedos { set -x - ISO_BASENAME="$(basename "$1")" - GRUB_PART_CFG="${MULTIBOOT_MNT}/grub/parts/${ISO_BASENAME}" - - mkdir -p "$(dirname "$GRUB_PART_CFG")" - - if [[ "$ISO_BASENAME" == ubuntu-*-desktop-*.iso ]]; then - setup_ubuntu - elif [[ "$ISO_BASENAME" == debian-live-*.iso ]]; then - setup_debian - elif [[ "$ISO_BASENAME" == Fedora-Workstation-Live-*.iso ]]; then - setup_fedora - elif [[ "$ISO_BASENAME" == archlinux-*.iso ]]; then - setup_archlinux - elif [[ "$ISO_BASENAME" == FD12*.zip ]]; then - setup_freedos - else - echo "Unsupported ISO! $ISO_BASENAME" - fi - - delete_stray_grub_parts - print_grub_cfg > "${MULTIBOOT_MNT}/grub/grub.cfg" -} - -function setup_ubuntu { - cat < "$GRUB_PART_CFG" -menuentry '$ISO_BASENAME' { - loopback loop /$ISO_BASENAME - linux (loop)/casper/vmlinuz.efi boot=casper quiet iso-scan/filename=/$ISO_BASENAME - initrd (loop)/casper/initrd.lz -} - -EOT -} - -function setup_debian { - cat < "$GRUB_PART_CFG" -menuentry '$ISO_BASENAME' { - loopback loop /$ISO_BASENAME - linux (loop)/live/vmlinuz boot=live components findiso=/$ISO_BASENAME - initrd (loop)/live/initrd.img -} + 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" -EOT -} + curl -fL "$SYSLINUX_URL" | \ + tar xz --no-same-owner --strip-components=3 -C "$MULTIBOOT_MNT" \ + "syslinux-${SYSLINUX_VERSION}/bios/memdisk/memdisk" -function setup_fedora { - cat < "$GRUB_PART_CFG" -menuentry '$ISO_BASENAME' { - loopback loop /$ISO_BASENAME - linux (loop)/isolinux/vmlinuz root=live:CDLABEL=$(blkid -s LABEL -o value "${MULTIBOOT_MNT}/$ISO_BASENAME") rd.live.image quiet iso-scan/filename=/$ISO_BASENAME - initrd (loop)/isolinux/initrd.img + curl -fL "$FREEDOS_URL" > "${MULTIBOOT_MNT}/FD12LITE.zip" } -EOT -} - -function setup_archlinux { - cat < "$GRUB_PART_CFG" -menuentry '$ISO_BASENAME' { - loopback loop /$ISO_BASENAME - linux (loop)/arch/boot/x86_64/vmlinuz img_label=${PARTITION_LABEL} img_loop=$ISO_BASENAME archisobasedir=arch earlymodules=loop - initrd (loop)/arch/boot/x86_64/archiso.img -} +function print_grub_cfg { + cat < "$GRUB_PART_CFG" -menuentry '$ISO_BASENAME' { - if [ \${grub_platform} = pc ]; then - linux16 /memdisk raw - initrd16 /$ISO_BASENAME - else - echo "FreeDOS only works with BIOS boot." - sleep 3 +for iso in /archlinux-*.iso; do + if [ -f "\$iso" ]; then + setup_arch \$iso fi -} +done -EOT -} - -function install_memdisk { - local dest="${MULTIBOOT_MNT}/memdisk" +function setup_debian { + menuentry "\$1" { + linux \$1/vmlinuz + initrd \$1/initrd.gz + } +} +for d in /debian-*-hd-media; do + if [ -d "\$d" ]; then + setup_debian \$d + fi +done - if [ -f "$dest" ]; then - return +if [ -f /memdisk -a -f /FD12LITE.zip ]; then + menuentry /FD12LITE.zip { + if [ \${grub_platform} = pc ]; then + linux16 /memdisk raw + initrd16 /FD12LITE.zip + else + echo "FreeDOS only works with BIOS boot." + sleep 3 fi + } +fi - for maybe in /usr/lib/syslinux/bios/memdisk /usr/lib/syslinux/memdisk; do - if [ -f "$maybe" ]; then - cp "$maybe" "$dest" - return - fi - done - - curl --fail "$SYSLINUX_URL" | \ - tar xz --strip-components=3 -C "$MULTIBOOT_MNT" \ - "syslinux-${SYSLINUX_VERSION}/bios/memdisk/memdisk" -} - -function delete_stray_grub_parts { - pushd "${MULTIBOOT_MNT}/grub/parts" &> /dev/null - comm -13 \ - <(find "${MULTIBOOT_MNT}/" -maxdepth 1 -type f -printf '%f\n'|sort) \ - <(find "${MULTIBOOT_MNT}/grub/parts/" -type f -printf '%f\n'|sort) \ - | xargs -d '\n' -r rm - popd &> /dev/null -} +function setup_fedora { + menuentry "\$1" { + loopback loop \$1 + probe -s iso_label -l (loop) + linux (loop)/isolinux/vmlinuz root=live:CDLABEL=\$iso_label rd.live.image quiet iso-scan/filename=\$1 + initrd (loop)/isolinux/initrd.img + } +} +for iso in /Fedora-Workstation-Live-*.iso; do + if [ -f "\$iso" ]; then + setup_fedora \$iso + fi +done -function print_grub_cfg { - cat <