From 3aa6b2030b0817e4134c067dcd8c9962c4574c79 Mon Sep 17 00:00:00 2001 From: Ralph Ronnquist Date: Tue, 6 Feb 2024 10:59:04 +1100 Subject: [PATCH] initial scripting --- init-udevd.template | 22 +++++++ init.template | 17 ++++++ message.txt | 15 +++++ minbase-strap.sh | 140 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 194 insertions(+) create mode 100755 init-udevd.template create mode 100755 init.template create mode 100644 message.txt create mode 100755 minbase-strap.sh diff --git a/init-udevd.template b/init-udevd.template new file mode 100755 index 0000000..1e39fa1 --- /dev/null +++ b/init-udevd.template @@ -0,0 +1,22 @@ +#!/bin/sh +mount -t proc proc /proc +mount -t sysfs sysfs /sys +mount -t devtmpfs devtmpfs /dev +mkdir /dev/pts +mount -t devpts devpts /dev/pts + +#MODULES=" \ +#scsi_mod sd_mod ata_piix \ +#crc32c ext4 \ +#nls_ascii nls_cp437 vfat fat \ +#" +#for m in $MODULES ; do modprobe $m ; done + +cat < udev.log 2>&1 +udevd -d -D +udevadm trigger -c add -v +EOF + +cat message.txt + +exec setsid cttyhack sh diff --git a/init.template b/init.template new file mode 100755 index 0000000..6bb90a8 --- /dev/null +++ b/init.template @@ -0,0 +1,17 @@ +#!/bin/sh +mount -t proc proc /proc +mount -t sysfs sysfs /sys +mount -t devtmpfs devtmpfs /dev +mkdir /dev/pts +mount -t devpts devpts /dev/pts + +MODULES=" \ +scsi_mod sd_mod ata_piix \ +crc32c ext4 \ +nls_ascii nls_cp437 vfat fat \ +" +for m in $MODULES ; do modprobe $m ; done + +cat message.txt + +exec setsid cttyhack sh diff --git a/message.txt b/message.txt new file mode 100644 index 0000000..3ab21ed --- /dev/null +++ b/message.txt @@ -0,0 +1,15 @@ + **____**************************************** + / ___|_ __ ___ ___| |_(_)_ __ __ _ ___ + | | _| '__/ _ \/ _ \ __| | '_ \ / _` / __| + | |_| | | | __/ __/ |_| | | | | (_| \__ \ + \____|_| \___|\___|\__|_|_| |_|\__, |___/ + |___/ + _____ _ _ _ _ _ + | ____|__ _ _ __| |_| |__ | (_)_ __ __ _| | + | _| / _` | '__| __| '_ \| | | '_ \ / _` | | + | |__| (_| | | | |_| | | | | | | | | (_| |_| + |_____\__,_|_| \__|_| |_|_|_|_| |_|\__, (_) + |___/ + ************************************* + + You are now on your own... diff --git a/minbase-strap.sh b/minbase-strap.sh new file mode 100755 index 0000000..852e9cb --- /dev/null +++ b/minbase-strap.sh @@ -0,0 +1,140 @@ +#!/bin/bash +# +# Utility script to debootstrap a minbase filesystem, with additions +# of kernel, busybox and an init script. Then make an initrd.gz from +# that and prepare a boot image file with syslinux from that. +# +if [ $(id -u) -ne 0 ] ; then + exec sudo env http_proxy=$http_proxy $0 $* + echo "** Abort: must be root" >&2 + exit 1 +fi +set -e -x + +ARCH="${1-$(dpkg-architecture -q DEB_HOST_ARCH)}" +DIST=${2-ceres} +IMG=${3-boot-$DIST-$ARCH.img} +FS=${4-FS} + +# Prepare or keep FS +DEBSTRAP=true +USRMERGE=true +if [ -d "$FS" ] ; then + select x in "keep existing $FS and skip debootstrap" \ + "remove existing $FS and debootstrap anew" \ + "abort" ; do + [ "$x" = abort ] && exit 1 + [ -z "$x" ] || break + done + echo "selection: $REPLY" + [ "$REPLY" = 1 ] && DEBSTRAP=false +fi + +if $DEBSTRAP ; then + ## Optionally add the stupid-links + read -n 1 -p "prime $FS with stupid-links? [Yn]" x + [ "$x" = "n" ] && USRMERGE=false + + rm -rf "$FS" # remove if existin + + if $USRMERGE ; then + mkdir -p "$FS"/usr + for d in bin sbin lib ; do + mkdir "$FS"/usr/$d + ln -s usr/$d "$FS"/$d + done + fi + + ## bootstrap a filesystem, with exclusions + echo "http_proxy=$http_proxy debootstrap ..." + debootstrap --exclude=logrotate,cron,cron-daemon-common \ + --arch=$ARCH $DIST "$FS" http://deb.devuan.org/merged + chroot "$FS" apt-get install -y logrotate cron + + ## Select and add a kernel + KERNELS=( $(chroot "$FS" apt-cache search linux-image-\* | \ + sed 's/\s.*//' | sort -h ) ) + echo "** Please select kernel **" + select KERNEL in "${KERNELS[@]}" ; do [ -n "$KERNEL" ] && break ; done + chroot "$FS" apt-get install -y $KERNEL + chroot "$FS" depmod -a ${KERNEL#linux-image-} + + chroot "$FS" apt-get install -y busybox-static debootstrap + touch "$FS"/usr/bin{linuxrc,init} # block these + chroot "$FS" /usr/bin/busybox --install -s /usr/bin + +fi # End of $DEBSTRAP actions + +## (re)install /init +echo "** Please select /init template" +select INIT in none $(echo init*.template) ; do [ -n "$INIT" ] && break ; done +if [ "$INIT" != none ] ; then + cp $INIT "$FS"/init + cp message.txt "$FS"/ + chmod a+x "$FS"/init +fi + +## Pick boot kernel, if there are many +LINUXES=( $(cd "$FS"/boot ; ls vmlinuz* 2>/dev/null) ) +if [ ${#LINUXES[@]} -gt 1 ] ; then + echo "** Please select boot kernel" + select LINUX in $LINUXES ; do [ -n "$LINUX" ] && break ; done +elif [ -n "$LINUXES" ] ; then + LINUX="$FS"/boot/${LINUXES[0]} +else + echo "** Oh No! There is no $FS/boot/vmlinux-* ... bailing out!" >&2 + exit 1 +fi + +#============================================================ +# Prepare a temporary directory tree with a boot kernel and $FS packed +# up into an initrd.gz +TMP=$(mktemp -d XXXX) +trap "rm -r $TMP" 0 2 15 + +( cd "$FS" && find -printf '%P\n' | cpio -o -H newc ) | \ + gzip > $TMP/initrd.gz +cp $LINUX $TMP/vmlinuz + +#============================================================ +# 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 +default menu.c32 +label linux + kernel /vmlinuz + append initrd=/initrd.gz init=/init console=ttyS0,115200 +EOF + +#============================================================ +[ -e "$IMG" ] && read -p "** Will overwrite $IMG (or ^C here and now)" x +rm -f "$IMG" + +# Estimate the required disk image size in Mib +DUM=$(( $(du -sB1 $TMP | sed 's/\s.*//') / 1048576 + 3 )) + +# 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 +mcopy -i "$IMG@@1048576" -s $TMP/* ::/ +[ -z "$SUDO_USER" ] || chown $SUDO_USER: "$IMG" + +#============================================================ +# 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" -- 2.39.2