Restructured scripting and added uefi boot equipment.
authorRalph Ronnquist <rrq@rrq.au>
Thu, 8 Feb 2024 11:28:49 +0000 (22:28 +1100)
committerRalph Ronnquist <rrq@rrq.au>
Thu, 8 Feb 2024 11:28:49 +0000 (22:28 +1100)
minbase-strap-bios.sh [new file with mode: 0644]
minbase-strap-mkimg.sh [new file with mode: 0644]
minbase-strap-uefi.sh [new file with mode: 0644]
minbase-strap.sh

diff --git a/minbase-strap-bios.sh b/minbase-strap-bios.sh
new file mode 100644 (file)
index 0000000..3777316
--- /dev/null
@@ -0,0 +1,19 @@
+# Include snippet for minbase-strap.sh
+
+# Add syslinux boot equipment for bios boot under $TMP/syslinux
+# (also includes the syslinux image mastering further below)
+
+mkdir -p $TMP/syslinux
+cp -t $TMP/syslinux /usr/lib/syslinux/modules/bios/*
+cat <<EOF > $TMP/syslinux/syslinux.cfg
+path /syslinux
+include /menu.cfg
+EOF
+
+#============================================================
+# Final syslinux bios boot image mastering
+bios_end() {
+    dd if=/usr/lib/SYSLINUX/mbr.bin of="$IMG" bs=440 conv=notrunc status=none
+    syslinux -i -d /syslinux -t 1048576 "$IMG"
+}
+ENDING+=" bios_end"
diff --git a/minbase-strap-mkimg.sh b/minbase-strap-mkimg.sh
new file mode 100644 (file)
index 0000000..8d77f5a
--- /dev/null
@@ -0,0 +1,38 @@
+# Include snippet for minbase-strap.sh
+#
+# Prepare image $IMG with 2 partitions:
+# 1) a FAT/UEFI partition using directory $TMP, and
+# 2) an squashfs partition using FS.sqfs
+
+[ -e "$IMG" ] && read -p "** Will overwrite $IMG (or ^C here and now)" x
+rm -f "$IMG"
+
+# First partition sectors (round up to a Mb number
+DUM1=$(( ( $(du -sB1 $TMP | sed 's/\s.*//') / 1048576 + 2 ) ))
+DUM2=$(( $(stat -c %s FS.sqfs) / 1048576 + 2 ))
+
+# Estimate the required disk image size in Mib
+DUM=$(( DUM1 + DUM2 + 1 ))
+
+# Create the image, with the partition marked as EFI parition and
+# bootable; acutal format is FAT{12,16,32}
+dd if=/dev/zero of="$IMG" bs=${DUM}M count=0 seek=1 status=none
+cat <<EOF | tee -a /proc/self/fd/2 | sfdisk -q "$IMG"
+label: dos
+
+2048 $(( DUM1 * 2048 )) 0xef *
+- - 0x83
+EOF
+PART=( $(fdisk -l -ostart,sectors $IMG | tail -n 2) )
+echo "${PART[*]}"
+
+# First sector is 2048 by default, which is byte address 1048576
+TMPIMG=$(mktemp XXXX)
+fusefile $TMPIMG $IMG/0+$(( ( ${PART[0]} + ${PART[1]} ) * 512 ))
+mkfs.fat --offset ${PART[0]} "$TMPIMG"  >/dev/null
+umount $TMPIMG
+rm $TMPIMG
+mcopy -i "$IMG@@1048576" -s $TMP/* ::/
+[ -z "$SUDO_USER" ] || chown $SUDO_USER: "$IMG"
+
+dd if=FS.sqfs of=$IMG seek=${PART[2]} conv=notrunc status=none
diff --git a/minbase-strap-uefi.sh b/minbase-strap-uefi.sh
new file mode 100644 (file)
index 0000000..6b95152
--- /dev/null
@@ -0,0 +1,20 @@
+# Include snippet for minbase-strap.sh
+#
+# Add syslinux boot equipments for uefi boot under $TMP/EFI/BOOT
+mkdir -p $TMP/EFI/BOOT/efi64
+cp /usr/lib/SYSLINUX.EFI/efi64/syslinux.efi $TMP/EFI/BOOT/BOOTX64.efi
+cp -t $TMP/EFI/BOOT/efi64 /usr/lib/syslinux/modules/efi64/*
+mv $TMP/EFI/BOOT/efi64/ldlinux.e64 $TMP/EFI/BOOT/
+cat <<EOF > $TMP/EFI/BOOT/syslx64.cfg
+path /EFI/BOOT/efi64
+include /menu.cfg
+EOF
+
+mkdir -p $TMP/EFI/BOOT/efi32
+cp /usr/lib/SYSLINUX.EFI/efi64/syslinux.efi $TMP/EFI/BOOT/BOOTIA32.efi
+cp -t $TMP/EFI/BOOT/efi32 /usr/lib/syslinux/modules/efi32/*
+mv $TMP/EFI/BOOT/efi32/ldlinux.e32 $TMP/EFI/BOOT/
+cat <<EOF > $TMP/EFI/BOOT/syslx32.cfg
+path /EFI/BOOT/efi32
+include /menu.cfg
+EOF
index 16340d9ea4ffdf3d967b5a3d9879a10ea28d1f72..82cc91a4ab8ec1b218296dd1ee043486f8337612 100755 (executable)
@@ -118,6 +118,10 @@ case "$X" in
     FS)
        copyFStree lib/modules
        zstdcat $INITRD | ( cd $TMP/prep && cpio -i )
+       VERSION=( $TMP/prep/lib/modules/* )
+       for V in ${VERSION[@]} ; do
+           depmod -a -b $TMP/prep ${V#$TMP/prep/lib/modules/}
+       done
        ;;
     my)
        copyFStree lib/modules lib/udev
@@ -127,76 +131,40 @@ case "$X" in
 esac
 
 ## (re)install /init
+mv $TMP/prep/init{,.FS}
 echo "** Please select /init template"
 select INIT in none $(echo init*.template) ; do [ -n "$INIT" ] && break ; done
 if [ "$INIT" != none ] ; then
-    mv $TMP/prep/init{,.FS}
     cp $INIT $TMP/prep/init
     chmod a+x $TMP/prep/init
-    cp message.txt $TMP/prep/message.txt
 fi
 
+# Populate $TMP with /initrd.gz. /vmlinuz and /menu.cfg
 ( cd "$TMP/prep" && find -printf '%P\n' | cpio -o -H newc ) | \
     gzip > $TMP/initrd.gz
 cp $LINUX $TMP/vmlinuz
-rm -rf $TMP/prep
+rm -r $TMP/prep
 
-#============================================================
-# Add syslinux boot equipment for bios boot under $TMP/syslinux
-# (also includes the syslinux image mastering further below)
-echo "Please select boot console options"
-
-CONOPTS=( none ttyS0,115200 )
-select CON in "${CONOPTS[@]}" ; do [ -n "$CON" ] && break ; done
-case "$CON" in none) CON= ;; *) CON="console=$CON" ;; esac
-
-mkdir -p $TMP/syslinux
-cp -t $TMP/syslinux /usr/lib/syslinux/modules/bios/*
-cat <<EOF > $TMP/syslinux/syslinux.cfg
+# Common syslinux menu
+CON="console=ttyS0,115200"
+cat <<EOF > $TMP/menu.cfg
 default menu.c32
-label linux
+label rescue (serial)
     kernel /vmlinuz
-    append initrd=/initrd.gz init=/init console=ttyS0,115200 
-label rescue
+    append initrd=/initrd.gz init=/init $CON rescue
+label rescue2 (vt1)
     kernel /vmlinuz
-    append initrd=/initrd.gz init=/init console=ttyS0,115200 rescue
-EOF
-
-#============================================================
-[ -e "$IMG" ] && read -p "** Will overwrite $IMG (or ^C here and now)" x
-rm -f "$IMG"
-
-# First partition sectors (round up to a Mb number
-DUM1=$(( ( $(du -sB1 $TMP | sed 's/\s.*//') / 1048576 + 2 ) ))
-DUM2=$(( $(stat -c %s FS.sqfs) / 1048576 + 2 ))
-
-# Estimate the required disk image size in Mib
-DUM=$(( DUM1 + DUM2 + 1 ))
-
-# Create the image, with the partition marked as EFI parition and
-# bootable; acutal format is FAT{12,16,32}
-dd if=/dev/zero of="$IMG" bs=${DUM}M count=0 seek=1 status=none
-cat <<EOF | tee -a /proc/self/fd/2 | sfdisk -q "$IMG"
-label: dos
-
-2048 $(( DUM1 * 2048 )) 0xef *
-- - 0x83
+    append initrd=/initrd.gz init=/init rescue
+label linux2 (sda2)
+    kernel /vmlinuz
+    append initrd=/initrd.gz root=/dev/sda2 rootfstype=squashfs $CON
+label linux (sdb1)
+    kernel /vmlinuz
+    append initrd=/initrd.gz root=/dev/sdb1 $CON
 EOF
-PART=( $(fdisk -l -ostart,sectors $IMG | tail -n 2) )
-echo "${PART[*]}"
-
-# First sector is 2048 by default, which is byte address 1048576
-TMPIMG=$(mktemp XXXX)
-fusefile $TMPIMG $IMG/0+$(( ( ${PART[0]} + ${PART[1]} ) * 512 ))
-mkfs.fat --offset ${PART[0]} "$TMPIMG"  >/dev/null
-umount $TMPIMG
-rm $TMPIMG
-mcopy -i "$IMG@@1048576" -s $TMP/* ::/
-[ -z "$SUDO_USER" ] || chown $SUDO_USER: "$IMG"
 
-dd if=FS.sqfs of=$IMG seek=${PART[2]} conv=notrunc status=none
+. ./minbase-strap-bios.sh
+. ./minbase-strap-uefi.sh
+. ./minbase-strap-mkimg.sh
 
-#============================================================
-# Final syslinux bios boot image mastering
-dd if=/usr/lib/SYSLINUX/mbr.bin of="$IMG" bs=440 conv=notrunc status=none
-syslinux -i -d syslinux -t 1048576 "$IMG"
+for E in $ENDING ; do $E ; done