From: Ralph Ronnquist Date: Fri, 8 Mar 2024 13:28:56 +0000 (+1100) Subject: capture X-Git-Url: https://git.rrq.au/?a=commitdiff_plain;h=refs%2Fheads%2Fmaster;p=rrq%2Frescue-boot.git capture --- diff --git a/minbase-strap-initrd.sh b/minbase-strap-initrd.sh new file mode 100755 index 0000000..0a86c40 --- /dev/null +++ b/minbase-strap-initrd.sh @@ -0,0 +1,56 @@ +# Include snippet for minbase-strap.sh + +#============================================================ +# Prepare a temporary directory tree with a boot kernel and a portion +# of $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 +} + +# Grab the "installed" initrd +INITRD="$FS"/boot/initrd.img${LINUX#*/vmlinuz} +zstdcat $INITRD | ( cd $TMP/prep && cpio -i ) + +# Prepare kernel loading +for V in $TMP/prep/lib/modules/* ; do + depmod -a -b $TMP/prep ${V#$TMP/prep/lib/modules/} +done + +## Change to use customm init script +mv $TMP/prep/init{,.FS} +echo "** Please select /init template" +select INIT in init.FS $(echo init*.template) ; do + if [ -n "$INIT" ] ; then + cp $INIT $TMP/prep/init + chmod a+x $TMP/prep/init + break + fi +done + +# Populate $TMP with /initrd.gz. /vmlinuz and /menu.cfg +( cd "$TMP/prep" && find -printf '%P\n' | cpio -o -H newc ) | \ + zstd > $TMP/initrd.img +cp $LINUX $TMP/vmlinuz +rm -r $TMP/prep