From: Ralph Ronnquist Date: Thu, 8 Feb 2024 11:28:49 +0000 (+1100) Subject: Restructured scripting and added uefi boot equipment. X-Git-Url: https://git.rrq.au/?a=commitdiff_plain;h=3b35d478a2bf7730eb333ba04b55c8372eff30b8;p=rrq%2Frescue-boot.git Restructured scripting and added uefi boot equipment. --- diff --git a/minbase-strap-bios.sh b/minbase-strap-bios.sh new file mode 100644 index 0000000..3777316 --- /dev/null +++ b/minbase-strap-bios.sh @@ -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 < $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 index 0000000..8d77f5a --- /dev/null +++ b/minbase-strap-mkimg.sh @@ -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 </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 index 0000000..6b95152 --- /dev/null +++ b/minbase-strap-uefi.sh @@ -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 < $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 < $TMP/EFI/BOOT/syslx32.cfg +path /EFI/BOOT/efi32 +include /menu.cfg +EOF diff --git a/minbase-strap.sh b/minbase-strap.sh index 16340d9..82cc91a 100755 --- a/minbase-strap.sh +++ b/minbase-strap.sh @@ -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 < $TMP/syslinux/syslinux.cfg +# Common syslinux menu +CON="console=ttyS0,115200" +cat < $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 </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