# At this stage, the following paths for Slackware OS are mounted:
# /proc, /sys, /run, /dev
# The root file system ('/') is mounted under /mnt
#


function hook_pre_switch_root() {
  # Need to write to /mnt temporarily:
  echo "Just about to switch into the Slackware OS proper, leaving the OS InitRD"
  echo "Detecting module sub system names"
  mount -o remount rw /mnt

cat << 'EOF' > /mnt/tmp/grab-mods
( awk '{print $1}' /proc/modules| while read mod ; do
   mfile=$( modinfo "${mod}" | grep -E '^filename:' | awk '{print $2}' )
   echo ${mfile%/*}
  done ) | sort | uniq | cut -d/ -f5- > /tmp/kernel-modules-within-initrd

lsmod > /tmp/lsmod-os-initrd
ls /dev > /tmp/ls-dev
EOF

   chmod 755 /mnt/tmp/grab-mods
   chroot /mnt /tmp/grab-mods
}
