--- /dev/null
+# 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
--- /dev/null
+# 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
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
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