From 5d60d1008409c64ab7a3e92dbffed1c139791e4b Mon Sep 17 00:00:00 2001 From: Ralph Ronnquist Date: Wed, 21 Jun 2023 13:26:07 +1000 Subject: [PATCH] Various refactoring --- init/init | 2 +- mkit.sh | 30 +++++++------------------- packiso.sh | 54 +++++++++++++++++++++++++++++----------------- vm.sh | 63 +++++++++++++++++++++++++++++++++++++++--------------- 4 files changed, 89 insertions(+), 60 deletions(-) diff --git a/init/init b/init/init index 23b40ac..b1f25b4 100644 --- a/init/init +++ b/init/init @@ -51,5 +51,5 @@ mount $DEV /cdrom mount -t ramfs -o size=1G initrd /target gunzip < $(find /cdrom -name initrd.gz ) | ( cd /target && cpio -i ) -#exec /bin/sh +exec /bin/sh exec switch_root -c /dev/console /target /init diff --git a/mkit.sh b/mkit.sh index e8dc657..728fe33 100755 --- a/mkit.sh +++ b/mkit.sh @@ -14,7 +14,7 @@ REPO="deb.devuan.org/merged" SUITE="daedalus" SECTION="main" ARCH="amd64" -MBR=gpt # or dos +MBR=dos # or dos PKGFILE=${REPO//\//_}_${SUITE}_${SECTION}_binary-${ARCH}_Packages if [ ! -r $PKGFILE ] ; then @@ -100,8 +100,8 @@ MODULES=( t10-pi sd_mod sg nls_cp437 nls_ascii fat vfat crc32c_generic jbd2 mbcache crc16 ext4 + usb-storage usbcore usb-common xhci-pci xhci-hcd isofs - overlay # input psmouse evdev # network @@ -129,22 +129,7 @@ depmod -F initrd/System.map-$V -b initrd $V $MOODLES echo "# setup a scripted init. The kernel runs this via the #! interpreter" rm -f initrd/sbin/init # just in case -cat < initrd/init -#!/bin/sh -echo -echo -echo "Hi there, tiniest lover!" - -mkdir /proc -mount -t proc proc /proc -mount -t devtmpfs devtmpfs /dev -mkdir /dev/pts -mount -t devpts devpts /dev/pts -mkdir /sys -mount -t sysfs sysfs /sys -$(for m in ${MODULES[@]} ; do echo modprobe $m ; done) -exec /bin/sh -EOF +cp init/init initrd/init chmod a+x initrd/init echo "# Now pack up that initrd as initrd.gz" @@ -188,6 +173,8 @@ mcopy $IMG \ kernel/usr/lib/syslinux/modules/bios/* ::/boot/syslinux/bios mcopy $IMG syslinux-legacy.cfg ::/syslinux.cfg +syslinux --install --offset=${IMG#*@@} bootimage.raw + echo "# Set up UEFI boot" cat < syslinux-uefi.cfg path /EFI/BOOT/efi64 @@ -196,15 +183,14 @@ EOF mmd $IMG ::/EFI mmd $IMG ::/EFI/BOOT -mmd $IMG ::/EFI/BOOT/efi64 mcopy $IMG kernel/usr/lib/SYSLINUX.EFI/efi64/syslinux.efi \ ::/EFI/BOOT/bootx64.efi mcopy $IMG \ kernel/usr/lib/syslinux/modules/efi64/* ::/EFI/BOOT -mcopy $IMG syslinux-uefi.cfg ::/EFI/BOOT/syslx64.cfg +mcopy $IMG syslinux-uefi.cfg ::/EFI/BOOT/syslinux.cfg - -syslinux --install --offset=${IMG#*@@} bootimage.raw +#echo "# Set up isolinux boot" +#mcopy $IMG kernel/usr/lib/ISOLINUX/isolinux.bin ::/ case "$MBR" in dos) MBRBIN=mbr.bin ;; diff --git a/packiso.sh b/packiso.sh index 0f1ed45..aed2a7e 100755 --- a/packiso.sh +++ b/packiso.sh @@ -7,26 +7,33 @@ set -e ISOTREE=isotree ISO=tiniest.iso -P1=$ISOTREE/part1.raw +P1=part1.raw # $ISOTREE/part1.raw echo "# Prepare ISO content tree" if [ ! -d $ISOTREE ] ; then mkdir $ISOTREE - touch $ISOTREE/catalog # Boot catalog + #touch $ISOTREE/catalog # Boot catalog # Determine start and size of first parition X=( $(sfdisk -l -ostart,sectors bootimage.raw | tail -n 2) ) dd if=bootimage.raw of=$P1 skip=${X[0]} count=${X[1]} - echo "# Set up the isolinux boot loader" - mkdir -p $ISOTREE/boot/syslinux/bios - cp kernel/usr/lib/syslinux/modules/bios/* $ISOTREE/boot/syslinux/bios - mv $ISOTREE/boot/syslinux/bios/ldlinux.c32 $ISOTREE/ - cp kernel/usr/lib/ISOLINUX/isolinux.bin $ISOTREE/ - mcopy -i $P1 ::/syslinux.cfg $ISOTREE/ - mcopy -i $P1 ::/bootmenu.cfg $ISOTREE/ - mcopy -i $P1 ::/splash.png $ISOTREE/ - mcopy -i $P1 ::/vmlinuz $ISOTREE/ - mcopy -i $P1 ::/initrd.gz $ISOTREE/ + + echo "# Set up the isolinux boot loader in $ISOTREE" + mkdir -p $ISOTREE/boot/isolinux/bios + cp kernel/usr/lib/syslinux/modules/bios/* $ISOTREE/boot/isolinux/bios + mv $ISOTREE/boot/isolinux/bios/ldlinux.c32 $ISOTREE/boot/isolinux + cp kernel/usr/lib/ISOLINUX/isolinux.bin $ISOTREE/boot/isolinux + cp syslinux-iso.cfg $ISOTREE/boot/isolinux/syslinux.cfg + mcopy -i $P1 ::/splash.png ::/vmlinuz $ISOTREE/ + + #mkdir -p $ISOTREE/EFI/BOOT + #cp kernel/usr/lib/SYSLINUX.EFI/efi64/syslinux.efi \ + # $ISOTREE/EFI/BOOT/bootia64.efi + #cp $ISOTREE/boot/isolinux/*.* $ISOTREE/EFI/boot/ + + #mcopy -i $P1 ::/ldlinux.sys ::/ldlinux.c32 $ISOTREE/ + #mcopy -i $P1 ::/initrd.gz $ISOTREE/ + #cp devuan/initrd.gz $ISOTREE/ fi [ ! -r $ISO ] || rm $ISO @@ -34,7 +41,7 @@ PREPID="'$(id -un), $(getent passwd $(id -un)|awk -F: '{print $5}')'" XORRISO=( -report_about ALL - --outdev $ISO + -outdev $ISO -map $ISOTREE / -rockridge on -joliet on -volid "TINIEST" @@ -50,15 +57,22 @@ XORRISO=( #-out_charset "UTF8" ?? -uid 0 -gid 0 - -append_partition 2 0xef ${P1} - -boot_image next cat_path=/catalog - -boot_image any system_area=kernel/usr/lib/ISOLINUX/isohdppx.bin - -boot_image any bin_path=/isolinux.bin - -boot_image any boot_info_table=on + # Mastering a cdrom legacy boot that uses the ISO tree only + -boot_image isolinux system_area=kernel/usr/lib/ISOLINUX/isohdpfx.bin + + # Mastering a disk legacy boot reusing the cdrom legacy boot + -boot_image isolinux dir=/boot/isolinux -boot_image any next - -boot_image any + + # Mastering a disk UEFI boot using the separate boot partition $P1 + # Bootloader = /EFI/BOOT/bootx64.efi + -append_partition 2 0xef ${P1} + -boot_image any efi_path=--interval:appended_partition_2:all::/EFI/BOOT/bootx64.efi - -boot_image any next + + # cdrom UEFI boot is missing ) xorriso "${XORRISO[@]}" +#sfdisk -f --part-attrs tiniest.iso 2 LegacyBIOSBootable +sfdisk -A tiniest.iso 2 diff --git a/vm.sh b/vm.sh index 41f024d..5d8b79c 100755 --- a/vm.sh +++ b/vm.sh @@ -2,27 +2,54 @@ # # QEMU setup for trial VM -if [ -z "$ISO" ] ; then - if [ -z "$EFI" ] ; then - BOOT="-boot menu=on" - DISK2="-drive index=1,id=boot,media=disk,format=raw,file=bootimage.raw" - else - BOOT="-bios /usr/share/OVMF/OVMF_CODE.fd" - DISK2="-drive index=1,id=boot,media=disk,format=raw,file=bootimage.raw" - fi +N="12345678" +if [ ${#1} = 1 ] && [ "${N#*$1}" != "$N" ] ; then + REPLY=$1 else - if [ -z "$EFI" ] ; then - BOOT="-boot menu=on" - DISK2="-drive index=1,id=boot,media=cdrom,format=raw,file=tiniest.iso" - else - BOOT="-bios /usr/share/OVMF/OVMF_CODE.fd" - DISK2="-drive index=1,id=boot,media=disk,format=raw,file=tiniest.iso" - fi -fi + VARIANT=( + "use bootimage.raw as harddisk with legacy boot (and boot menu)" + "use bootimage.raw as harddisk with UEFI boot" + "use tiniest.iso as harddisk with legacy boot (and boot menu)" + "use tiniest.iso as harddisk with UEFI boot" + "use tiniest.iso as cdrom with legacy boot (and boot menu)" + "use tiniest.iso as cdrom with UEFI boot" + "use tiniest.iso as USB disk with legacy boot (and boot menu)" + "use tiniest.iso as USB disk with UEFI boot" + ) + + select V in "${VARIANT[@]}" ; do + [ -z "$V" ] || break + done +fi +[ -z "$REPLY" ] && exit 0 + +FILE=bootimage.raw +[ $REPLY -ge 3 ] && FILE=tiniest.iso +MEDIA=disk +[ $REPLY -ge 5 ] && MEDIA=cdrom +[ $REPLY -ge 7 ] && MEDIA=usb + +case "$MEDIA" in + disk) + DISK2="-drive index=1,format=raw,media=$MEDIA,file=$FILE" + ;; + usb) + USB=" + -device qemu-xhci,id=xhci + -drive if=none,id=stick,format=raw,media=disk,file=${FILE} + -device usb-storage,bus=xhci.0,port=1,drive=stick + " + ;; + cdrom*) + DISK2="-drive index=1,format=raw,media=$MEDIA,file=$FILE" + ;; +esac + +BOOT="-boot menu=on,splash=boot.jpg,splash-time=60000" +[ $(( $REPLY % 2 )) -eq 0 ] && BOOT="-bios /usr/share/OVMF/OVMF_CODE.fd" case "$NET" in vde) - #NET="-net nic,macaddr=06:7f:57:5e:c8:92 -net vde,sock=/run/vde.ctl" NET="-net nic,model=e1000 -net vde,sock=/run/vde.ctl" ;; *) @@ -38,7 +65,9 @@ ARGS=( $BOOT -drive index=0,id=disk,media=disk,format=raw,file=disk.raw $DISK2 + $USB $NET ) +echo "${ARGS[*]}" | sed "s/ -/\n -/g" exec qemu-system-x86_64 ${ARGS[@]} -- 2.39.2