-#============================================================
-# 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 )
- VERSION=( $TMP/prep/lib/modules/* )
- for V in ${VERSION[@]} ; do
- depmod -a -b $TMP/prep ${V#$TMP/prep/lib/modules/}
- done
- ;;
- my)
- copyFStree lib/modules lib/udev
- copyFSbin busybox sh cttyhack setsid mount mkdir
- copyFSbin udevd udevadm modprobe modinfo kmod blkid
- ;;
-esac
-
-## (re)install /init
-mv $TMP/prep/init{,.FS}
-echo "** Please select /init template"
-select INIT in none $(echo init*.template) ; do [ -n "$INIT" ] && break ; done
-if [ "$INIT" != none ] ; then
- cp $INIT $TMP/prep/init
- chmod a+x $TMP/prep/init
-fi
-
-# Populate $TMP with /initrd.gz. /vmlinuz and /menu.cfg
-( cd "$TMP/prep" && find -printf '%P\n' | cpio -o -H newc ) | \
- gzip > $TMP/initrd.gz
-cp $LINUX $TMP/vmlinuz
-rm -r $TMP/prep