about summary refs log tree commit diff stats
path: root/gen_iso
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2019-08-09 21:54:07 -0700
committerKartik Agaram <vc@akkartik.com>2019-08-09 21:57:27 -0700
commit30b2fcf8e6b2b127f769d339ced085ac685c3bcf (patch)
tree897e894f6993cc9bd75f8ad55f6887960b426c2a /gen_iso
parent4ea0d46109442adcee2a38beacafa4d14b3e694d (diff)
downloadmu-30b2fcf8e6b2b127f769d339ced085ac685c3bcf.tar.gz
5502 - package up into a bootable disk image
Many thanks to John Davidson for Minimal Linux Live (GPLv3), from which
I cribbed gen_iso.
Diffstat (limited to 'gen_iso')
-rwxr-xr-xgen_iso89
1 files changed, 89 insertions, 0 deletions
diff --git a/gen_iso b/gen_iso
new file mode 100755
index 00000000..ba08e8cb
--- /dev/null
+++ b/gen_iso
@@ -0,0 +1,89 @@
+#!/bin/sh
+# Build one or more .subx files into an ELF binary, and package it up into a
+# bootable ISO image.
+#
+# Must be run on Linux.
+#
+# Dependencies:
+#   apt install build-essential flex bison libelf-dev libssl-dev xorriso
+#
+# Based on http://minimal.linux-bg.org (GPLv3)
+
+set -e
+
+if [ $# -eq 0 ]
+then
+  echo "Usage: `basename $0` file.subx ..."
+  exit 1
+fi
+
+echo "=== constructing initramfs out of SubX binary"
+./ntranslate $*
+mv a.elf init
+chmod +x init
+rm -rf tmp/isoimage
+mkdir -p tmp/isoimage/boot
+echo init | cpio -R root:root -H newc -o | xz -9 --check=none > tmp/isoimage/boot/rootfs.xz
+
+if [ ! -d kernel ]
+then
+  echo "=== downloading kernel"
+  test -f tmp/linux-4.14.12.tar.xz  ||  wget https://kernel.org/pub/linux/kernel/v4.x/linux-4.14.12.tar.xz -P tmp
+  echo "=== unpacking kernel"
+  tar xf tmp/linux-4.14.12.tar.xz
+  mv linux-4.14.12 kernel
+fi
+
+echo "=== building kernel"
+( cd kernel
+
+  make mrproper -j $NUM_JOBS
+  make defconfig -j $NUM_JOBS
+  sed -i "s/.*CONFIG_DEFAULT_HOSTNAME.*/CONFIG_DEFAULT_HOSTNAME=\"mu\"/" .config
+  # enable overlay support, e.g. merge ro and rw directories (3.18+).
+  sed -i "s/.*CONFIG_OVERLAY_FS.*/CONFIG_OVERLAY_FS=y/" .config
+  # enable overlayfs redirection (4.10+).
+  echo "CONFIG_OVERLAY_FS_REDIRECT_DIR=y" >> .config
+  # turn on inodes index feature (4.13+).
+  echo "CONFIG_OVERLAY_FS_INDEX=y" >> .config
+  # disable all kernel compression options
+  sed -i "s/.*\\(CONFIG_KERNEL_.*\\)=y/\\#\\ \\1 is not set/" .config
+  # enable the VESA framebuffer for graphics support
+  sed -i "s/.*CONFIG_FB_VESA.*/CONFIG_FB_VESA=y/" .config
+  # disable boot logo
+  sed -i "s/.*CONFIG_LOGO_LINUX_CLUT224.*/\\# CONFIG_LOGO_LINUX_CLUT224 is not set/" .config
+  sed -i "s/.*CONFIG_EFI_STUB.*/CONFIG_EFI_STUB=y/" .config
+  # request that the firmware clear the contents of RAM after reboot (4.14+)
+  echo "CONFIG_RESET_ATTACK_MITIGATION=y" >> .config
+  echo "CONFIG_APPLE_PROPERTIES=n" >> .config
+
+  if [ "`grep "CONFIG_X86_64=y" .config`" = "CONFIG_X86_64=y" ]
+  then
+    echo "CONFIG_EFI_MIXED=y" >> .config
+  fi
+
+  make bzImage -j $(grep ^processor /proc/cpuinfo | wc -l)
+)
+cp kernel/arch/x86/boot/bzImage tmp/isoimage/boot/kernel.xz
+
+echo "=== downloading syslinux"
+test -f tmp/syslinux-6.03.tar.xz  ||  wget https://kernel.org/pub/linux/utils/boot/syslinux/syslinux-6.03.tar.xz -P tmp
+echo "=== unpacking syslinux"
+tar xf tmp/syslinux-*.tar.xz -C tmp
+
+mkdir -p tmp/isoimage/boot/syslinux
+cp syslinux.cfg \
+   tmp/syslinux-*/bios/core/isolinux.bin \
+   tmp/syslinux-*/bios/com32/elflink/ldlinux/ldlinux.c32 \
+   tmp/isoimage/boot/syslinux
+
+echo "=== generating ISO"
+# 'hybrid' ISO can also be used on non-optical media such as a disk or USB stick
+xorriso -as mkisofs \
+  -isohybrid-mbr tmp/syslinux-*/bios/mbr/isohdpfx.bin \
+  -c boot/syslinux/boot.cat \
+  -b boot/syslinux/isolinux.bin \
+    -no-emul-boot \
+    -boot-load-size 4 \
+    -boot-info-table \
+  tmp/isoimage -o mu.iso