blob: dd80ad55a55c50f4ceeeb39dfa5279c03981e67b [file] [log] [blame]
#!/bin/sh
# This is still a bit of an experiment.
FAKEVER=0.0.0
MODDIR=".virtme_mods/lib/modules/$FAKEVER"
# Some distro don't have /sbin or /usr/sbin in user's default path. Make sure
# to setup the right path to find all the commands needed to setup the modules
# (depmod, etc.).
PATH=$PATH:/sbin:/usr/sbin
if ! [ -f "modules.order" ]; then
echo 'virtme-prep-kdir-mods must be run from a kernel build directory' >&2
echo "modules.order is missing. Your kernel may be too old or you didn't make modules." >&2
exit 1
fi
# Set up .virtme_mods/lib/modules/0.0.0 as a module directory for this kernel,
# but fill it with symlinks instead of actual modules.
mkdir -p "$MODDIR/kernel"
ln -srfT . "$MODDIR/build"
# Remove all preexisting symlinks and add symlinks to all modules that belong
# to the build kenrnel.
find "$MODDIR/kernel" -type l -print0 |xargs -0 rm -f --
while read -r i; do
[ ! -e "$i" ] && i=$(echo "$i" | sed s:^kernel/::)
mkdir -p "$MODDIR/kernel/$(dirname "$i")"
ln -sr "$i" "$MODDIR/kernel/$i"
done < modules.order
# Link in the files that make modules_install would copy
ln -srf modules.builtin modules.builtin.modinfo modules.order "$MODDIR/"
# Now run depmod to collect dependencies
depmod -ae -F System.map -b .virtme_mods "$FAKEVER"