|
|
|
#!/bin/sh
|
|
|
|
# --- SDE-COPYRIGHT-NOTE-BEGIN ---
|
|
|
|
# This copyright note is auto-generated by ./scripts/Create-CopyPatch.
|
|
|
|
#
|
|
|
|
# Filename: package/.../mkinitrd/mkinitrd.sh
|
|
|
|
# Copyright (C) 2006 - 2008 The OpenSDE Project
|
|
|
|
# Copyright (C) 2005 - 2006 The T2 SDE Project
|
|
|
|
#
|
|
|
|
# More information can be found in the files COPYING and README.
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; version 2 of the License. A copy of the
|
|
|
|
# GNU General Public License can be found in the file COPYING.
|
|
|
|
# --- SDE-COPYRIGHT-NOTE-END ---
|
|
|
|
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
|
|
|
if [ $UID != 0 ]; then
|
|
|
|
echo "Non root - exiting ..."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
while [ "$1" ]; do
|
|
|
|
case $1 in
|
|
|
|
[0-9]*) kernelver="$1" ;;
|
|
|
|
-R) root="$2" ; shift ;;
|
|
|
|
*) echo "Usage: mkinitrd [ -R root ] [ kernelver ]"
|
|
|
|
exit 1 ;;
|
|
|
|
esac
|
|
|
|
shift
|
|
|
|
done
|
|
|
|
|
|
|
|
[ "$root" ] || root=
|
|
|
|
[ "$kernelver" ] || kernelver=`uname -r`
|
|
|
|
[ "$moddir" ] || moddir="${root}/lib/modules/$kernelver"
|
|
|
|
|
|
|
|
echo "Kernel: $kernelver, module dir: $moddir"
|
|
|
|
|
|
|
|
if [ ! -d $moddir ]; then
|
|
|
|
echo "Module dir $moddir does not exist!"
|
|
|
|
exit 2
|
|
|
|
fi
|
|
|
|
|
|
|
|
sysmap=
|
|
|
|
[ -f "${root}/boot/System.map_$kernelver" ] && sysmap="${root}/boot/System.map_$kernelver"
|
|
|
|
|
|
|
|
if [ -z "$sysmap" ]; then
|
|
|
|
echo "System.map_$kernelver not found!"
|
|
|
|
exit 2
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "System.map: $sysmap"
|
|
|
|
|
|
|
|
# check needed tools
|
|
|
|
for x in cpio gzip ; do
|
|
|
|
if ! which $x >/dev/null ; then
|
|
|
|
echo "$x not found!"
|
|
|
|
exit 2
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
tmpdir=`mktemp`
|
|
|
|
|
|
|
|
# create basic structure
|
|
|
|
#
|
|
|
|
rm -rf $tmpdir >/dev/null
|
|
|
|
|
|
|
|
echo "Create dirtree ..."
|
|
|
|
|
|
|
|
mkdir -p $tmpdir/{dev,bin,sbin,proc,sys,lib/modules,lib/udev,etc/hotplug.d/default}
|
|
|
|
mknod $tmpdir/dev/console c 5 1
|
|
|
|
|
|
|
|
# copy the basic / rootfs kernel modules
|
|
|
|
#
|
|
|
|
echo "Copying kernel modules ..."
|
|
|
|
|
|
|
|
if [ -x /sbin/modinfo -a -x /sbin/depmod ]; then
|
|
|
|
find $moddir/kernel -type f | grep \
|
|
|
|
-e reiserfs -e reiser4 -e ext2 -e ext3 -e /jfs -e /xfs \
|
|
|
|
-e isofs -e udf -e /unionfs -e ntfs -e fat -e dm-mod -e md-mod \
|
|
|
|
-e /ide/ -e /ata/ -e /scsi/ -e /message/ -e hci \
|
|
|
|
-e usb-storage -e sbp2 -e /md/raid \
|
|
|
|
-e drivers/net/ -e '/ipv6\.' |
|
|
|
|
while read fn ; do
|
|
|
|
for x in $fn `/sbin/modinfo $fn | grep depends |
|
|
|
|
cut -d : -f 2- | sed -e 's/ //g' -e 's/,/ /g' `
|
|
|
|
do
|
|
|
|
# expand to full name if it was a depend
|
|
|
|
[ $x = ${x##*/} ] &&
|
|
|
|
x=`find $moddir/kernel -name "$x.*o"`
|
|
|
|
|
|
|
|
echo -n "${x##*/} "
|
|
|
|
|
|
|
|
# strip $root prefix
|
|
|
|
xt=${x##$root}
|
|
|
|
|
|
|
|
mkdir -p `dirname $tmpdir/$xt`
|
|
|
|
cp $x $tmpdir/$xt 2>/dev/null
|
|
|
|
done
|
|
|
|
done | fold -s ; echo
|
|
|
|
|
|
|
|
# generate map files
|
|
|
|
#
|
|
|
|
/sbin/depmod -ae -b $tmpdir -F $sysmap $kernelver
|
|
|
|
|
|
|
|
else
|
|
|
|
echo "ERROR: modinfo or depmod are missing in your installation."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
echo "Injecting programs and configuration ..."
|
|
|
|
|
|
|
|
# copying config
|
|
|
|
#
|
|
|
|
|
|
|
|
# group (needed by udev to resolve group names)
|
|
|
|
cp -a ${root}/etc/group $tmpdir/etc/
|
|
|
|
# udev
|
|
|
|
cp -ar ${root}/etc/udev $tmpdir/etc/
|
|
|
|
# in theory all, but fat and currently only cdrom_id is needed ...
|
|
|
|
cp -ar ${root}/lib/udev/* $tmpdir/lib/udev/
|
|
|
|
|
|
|
|
# setup programs
|
|
|
|
#
|
|
|
|
for x in ${root}/sbin/{udevd,udevtrigger,udevsettle,modprobe,insmod} ${root}/usr/sbin/disktype
|
|
|
|
do
|
|
|
|
# sanity check
|
|
|
|
file $x | grep -q "dynamically linked" &&
|
|
|
|
echo "Warning: $x is dynamically linked!"
|
|
|
|
cp $x $tmpdir/sbin/
|
|
|
|
done
|
|
|
|
|
|
|
|
x=${root}/sbin/insmod.old
|
|
|
|
if [ ! -e $x ]; then
|
|
|
|
echo "Warning: Skipped optional file $x!"
|
|
|
|
else
|
|
|
|
file $x | grep -q "dynamically linked" &&
|
|
|
|
echo "Warning: $x is dynamically linked!"
|
|
|
|
cp $x $tmpdir/sbin/
|
|
|
|
ln -s insmod.old $tmpdir/sbin/modprobe.old
|
|
|
|
fi
|
|
|
|
|
|
|
|
ln -s /sbin/udev $tmpdir/etc/hotplug.d/default/10-udev.hotplug
|
|
|
|
cp ${root}/bin/pdksh $tmpdir/bin/sh
|
|
|
|
|
|
|
|
# static, tiny embutils and friends
|
|
|
|
#
|
|
|
|
for x in mount umount rm mv cp mkdir ln ls switch_root sleep losetup chmod cat sed mknod
|
|
|
|
do
|
|
|
|
if [ -x $root/usr/embutils/$x ]; then
|
|
|
|
x=$root/usr/embutils/$x
|
|
|
|
elif [ -x $root/usr/bin/$x ]; then
|
|
|
|
x=$root/usr/bin/$x
|
|
|
|
elif [ -x $root/bin/$x ]; then
|
|
|
|
x=$root/bin/$x
|
|
|
|
else
|
|
|
|
echo "Error: $x was not found!" 1>&2
|
|
|
|
false
|
|
|
|
fi
|
|
|
|
# sanity check
|
|
|
|
file $x | grep -q "dynamically linked" &&
|
|
|
|
echo "Warning: $x is dynamically linked!"
|
|
|
|
cp $x $tmpdir/bin/
|
|
|
|
done
|
|
|
|
|
|
|
|
cp ${root}/sbin/initrdinit $tmpdir/init
|
|
|
|
|
|
|
|
# create the cpio image
|
|
|
|
#
|
|
|
|
echo "Archiving ..."
|
|
|
|
( cd $tmpdir
|
|
|
|
find * | cpio -o -H newc | gzip -c9 > ${root}/boot/initrd-$kernelver.img
|
|
|
|
)
|
|
|
|
|
|
|
|
# display the resulting image
|
|
|
|
#
|
|
|
|
du -sh ${root}/boot/initrd-$kernelver.img
|
|
|
|
rm -rf $tmpdir
|
|
|
|
|
|
|
|
|