]> code.delx.au - monosys/blobdiff - hacks/multiboot-setup
multiboot: Add a menu item to attempt booting images from ram.
[monosys] / hacks / multiboot-setup
index 22d73f5e3b13908e203be88a218fadaf95bc29d9..1358aa572e60b3bc185c943641cc493586e17c44 100755 (executable)
@@ -3,7 +3,7 @@
 set -eu
 
 PARTITION_LABEL="multiboot"
-MULTIBOOT_MNT="/mnt/multiboot"
+MULTIBOOT_MNT="${MULTIBOOT_MNT:-/mnt/multiboot}"
 
 function cmd_format {
     if [ ! -b "${1:-}" ]; then
@@ -58,7 +58,12 @@ function install_grub_efi {
 }
 
 function install_grub_cfg {
-    print_grub_cfg | sudo tee "${MULTIBOOT_MNT}/grub/grub.cfg" > /dev/null
+    if [[ -w "${MULTIBOOT_MNT}/grub/" ]]; then
+        # We already have write access, no need to use sudo
+        print_grub_cfg > "${MULTIBOOT_MNT}/grub/grub.cfg"
+    else
+        print_grub_cfg | sudo tee "${MULTIBOOT_MNT}/grub/grub.cfg" > /dev/null
+    fi
 }
 
 function cmd_mount {
@@ -103,15 +108,24 @@ insmod part_msdos
 insmod progress
 insmod regexp
 search --set=root --label $PARTITION_LABEL
+set maybe_to_ram=''
+
+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"
+}
 
 function setup_arch {
   menuentry "\$1" {
     loopback loop \$1
-    linux (loop)/arch/boot/x86_64/vmlinuz-linux img_label=${PARTITION_LABEL} img_loop=\$1 archisobasedir=arch earlymodules=loop
-    initrd (loop)/arch/boot/x86_64/initramfs-linux.img
+    echo "Loading kernel..."
+    linux (loop)/arch/boot/x86_64/vmlinuz-* img_label=${PARTITION_LABEL} img_loop=\$1 archisobasedir=arch earlymodules=loop \$maybe_to_ram
+    echo "Loading initrd (and microcode if they exist)..."
+    initrd (loop)/arch/boot/*.img (loop)/arch/boot/x86_64/initramfs-*.img
   }
 }
-for iso in /archlinux-*.iso; do
+for iso in /archlinux-*.iso /isos/archlinux-*.iso; do
   if [ -f "\$iso" ]; then
     setup_arch \$iso
   fi
@@ -151,11 +165,13 @@ 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
+    echo "Loading initrd..."
     initrd (loop)/isolinux/initrd.img
   }
 }
-for iso in /Fedora-Workstation-Live-*.iso; do
+for iso in /Fedora-Workstation-Live-*.iso /isos/Fedora-Workstation-Live-*.iso; do
   if [ -f "\$iso" ]; then
     setup_fedora \$iso
   fi
@@ -164,16 +180,33 @@ done
 function setup_ubuntu {
   menuentry "\$1" {
     loopback loop \$1
-    linux (loop)/casper/vmlinuz* boot=casper quiet iso-scan/filename=\$1
+    echo "Loading kernel..."
+    linux (loop)/casper/vmlinuz* boot=casper quiet iso-scan/filename=\$1 \$maybe_to_ram
+    echo "Loading initrd..."
     initrd (loop)/casper/initrd*
   }
 }
-for iso in /ubuntu-*-desktop-*.iso; do
+for iso in /ubuntu-*-desktop-*.iso /isos/ubuntu-*-desktop-*.iso; do
   if [ -f "\$iso" ]; then
     setup_ubuntu \$iso
   fi
 done
 
+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
+    echo "Loading initrd..."
+    initrd (loop)/live/initrd*
+  }
+}
+for iso in /tails-*.iso /isos/tails-*.iso; do
+  if [ -f "\$iso" ]; then
+    setup_tails \$iso
+  fi
+done
+
 EOT
 }