X-Git-Url: https://git.rrq.au/?a=blobdiff_plain;f=minbase-strap.sh;h=6f41ac05d5f01bfb1abd9df196e498f034c9e152;hb=HEAD;hp=16340d9ea4ffdf3d967b5a3d9879a10ea28d1f72;hpb=e75a7ffa6c10188c831c1d29a5f0cf31ae975d40;p=rrq%2Frescue-boot.git diff --git a/minbase-strap.sh b/minbase-strap.sh index 16340d9..6f41ac0 100755 --- a/minbase-strap.sh +++ b/minbase-strap.sh @@ -47,7 +47,8 @@ if $DEBSTRAP ; then ## 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 + --arch=$ARCH $DIST "$FS" http://deb.devuan.org/merged || \ + chroot "$FS" apt-get -f install -y chroot "$FS" apt-get install -y logrotate cron ## Select and add a kernel @@ -78,125 +79,31 @@ else 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 - -mkdir -p $TMP/prep/{proc,dev,tmp,sys,mnt,usr} -stupid_links $TMP/prep - -# copy FS tree(s) in full into the TMP/prep tree -copyFStree() { - local D - for D in $* ; do - tar cf - -C "$FS" $D \ - | tar -xf - --skip-old-files --keep-directory-symlink -C $TMP/prep - done -} - -# Copy FS binary(s) with all its libraries into the TMP/prep tree -copyFSbin() { - local B BIN - for B in $* ; do - BIN="$(chroot "$FS" which "$B")" - tar cf - --dereference -C "$FS" ${BIN#/} \ - $(chroot "$FS" ldd "$BIN" | grep -oE '/[^ ]*'|sed 's|/||')\ - | tar -xf - --keep-directory-symlink -C $TMP/prep - done -} - -INITRD="$FS"/boot/initrd.img${LINUX#*/vmlinuz} -if [ -r "$INITRD" ] ; then - #select X in my FS ; do [ -n "$X" ] && break ; done - X=FS -else - X=my -fi -case "$X" in - FS) - copyFStree lib/modules - zstdcat $INITRD | ( cd $TMP/prep && cpio -i ) - ;; - my) - copyFStree lib/modules lib/udev - copyFSbin busybox sh cttyhack setsid mount mkdir - copyFSbin udevd udevadm modprobe modinfo kmod blkid - ;; -esac - -## (re)install /init -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 - -( cd "$TMP/prep" && find -printf '%P\n' | cpio -o -H newc ) | \ - gzip > $TMP/initrd.gz -cp $LINUX $TMP/vmlinuz -rm -rf $TMP/prep +. ./minbase-strap-initrd.sh #============================================================ -# 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.img 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" +. ./minbase-strap-bios.sh +. ./minbase-strap-uefi.sh +. ./minbase-strap-mkimg.sh -dd if=FS.sqfs of=$IMG seek=${PART[2]} conv=notrunc status=none +for E in $ENDING ; do $E ; done -#============================================================ -# 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" +#. ./minbase-strap-mkiso.sh $IMG