+# Helper function to copy a file or link, given full path
+# $1 = full pathname, $2 = (relative) root path
+copylinks() {
+ echo "copylinks $*" >&2
+ [ -e "initrd/$1" ] && return 0
+ mkdir -p "initrd${1%/*}"
+ if [ -L "$1" ] ; then
+ local L=$(readlink $2$1)
+ ln -s $L initrd$1
+ [ "${L:0:1}" = "/" ] || L="${1%/*}/$L"
+ copylinks $L $2
+ else
+ cp $2$1 initrd/$1
+ fi
+}
+
+# Helper function to copy dynamic binary and its libraries
+# $1 = full pathname, $2 = (relative) root path
+bincp() {
+ echo "bincp $*" >&2
+ [ -e "initrd/$1" ] && return 0
+ copylinks $1 $2
+ objdump -x $2$1 | while read A B ; do
+ [ "$A" == "NEEDED" ] || continue
+ local L="$(find ${2:-/} -name $B)"
+ [ -z "$L" ] && echo "MISSING $B" && exit 1
+ copylinks ${L#$2} $2
+ done
+}
+
+echo '# Include static vtoydump for Ventoy support'
+VTOYDUMP=../ventoy/vtoydump/vtoydump
+if [ -e "$VTOYDUMP" ] ; then
+ mkdir -p initrd/bin
+ cp "$VTOYDUMP" initrd/bin
+fi
+
+echo "# Extract static busybox, and fluff it up for more utilities"
+mkdir -p initrd