1 # Include snippet for minbase-strap.sh
3 #============================================================
4 # Prepare a temporary directory tree with a boot kernel and a portion
5 # of $FS packed up into an initrd.gz
7 trap "rm -r $TMP" 0 2 15
9 mkdir -p $TMP/prep/{proc,dev,tmp,sys,mnt,usr}
10 stupid_links $TMP/prep
12 # copy FS tree(s) in full into the TMP/prep tree
16 tar cf - -C "$FS" $D \
17 | tar -xf - --skip-old-files --keep-directory-symlink -C $TMP/prep
21 # Copy FS binary(s) with all its libraries into the TMP/prep tree
25 BIN="$(chroot "$FS" which "$B")"
26 tar cf - --dereference -C "$FS" ${BIN#/} \
27 $(chroot "$FS" ldd "$BIN" | grep -oE '/[^ ]*'|sed 's|/||')\
28 | tar -xf - --keep-directory-symlink -C $TMP/prep
32 # Grab the "installed" initrd
33 INITRD="$FS"/boot/initrd.img${LINUX#*/vmlinuz}
34 zstdcat $INITRD | ( cd $TMP/prep && cpio -i )
36 # Prepare kernel loading
37 for V in $TMP/prep/lib/modules/* ; do
38 depmod -a -b $TMP/prep ${V#$TMP/prep/lib/modules/}
41 ## Change to use customm init script
42 mv $TMP/prep/init{,.FS}
43 echo "** Please select /init template"
44 select INIT in init.FS $(echo init*.template) ; do
45 if [ -n "$INIT" ] ; then
46 cp $INIT $TMP/prep/init
47 chmod a+x $TMP/prep/init
52 # Populate $TMP with /initrd.gz. /vmlinuz and /menu.cfg
53 ( cd "$TMP/prep" && find -printf '%P\n' | cpio -o -H newc ) | \
54 zstd > $TMP/initrd.img
55 cp $LINUX $TMP/vmlinuz