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