2 # --- T2-COPYRIGHT-NOTE-BEGIN ---
3 # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
5 # T2 SDE: package/.../mkinitrd/mkinitrd.sh
6 # Copyright (C) 2005 - 2006 The T2 SDE Project
8 # More information can be found in the files COPYING and README.
10 # This program is free software; you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; version 2 of the License. A copy of the
13 # GNU General Public License can be found in the file COPYING.
14 # --- T2-COPYRIGHT-NOTE-END ---
18 if [ $UID != 0 ]; then
19 echo "Non root - exiting ..."
25 [0-9]*) kernelver="$1" ;;
26 -R) root="$2" ; shift ;;
27 *) echo "Usage: mkinitrd [ -R root ] [ kernelver ]"
33 [ "$root" ] || root=""
34 [ "$kernelver" ] || kernelver=`uname -r`
35 [ "$moddir" ] || moddir="${root}/lib/modules/$kernelver"
37 echo "Kernel: $kernelver, module dir: $moddir"
39 if [ ! -d $moddir ]; then
40 echo "Module dir $moddir does not exist!"
45 [ -f "${root}/boot/System.map-$kernelver" ] && sysmap="${root}/boot/System.map-$kernelver"
47 if [ -z "$sysmap" ]; then
48 echo "System.map_$kernelver not found!"
52 echo "System.map: $sysmap"
55 #for x in cpio gzip ; do
56 # if ! which $x >/dev/null ; then
57 # echo "$x not found!"
64 # create basic structure
66 rm -rf $tmpdir >/dev/null
68 echo "Create dirtree ..."
70 mkdir -p $tmpdir/{dev,bin,sbin,proc,sys,lib/modules,lib/udev,etc/hotplug.d/default}
71 mknod $tmpdir/dev/console c 5 1
73 # copy the basic / rootfs kernel modules
75 echo "Copying kernel modules ..."
78 find $moddir/kernel -type f | grep \
79 -e reiserfs -e reiser4 -e ext2 -e ext3 -e /jfs -e /xfs \
80 -e isofs -e udf -e /unionfs -e ntfs -e fat -e dm-mod \
81 -e /ide/ -e /ata/ -e /scsi/ -e /message/ \
82 -e hci -e usb-storage -e sbp2 \
83 -e drivers/net/ -e '/ipv6\.' -e usbhid |
86 for x in $fn `modinfo $fn | grep depends |
87 cut -d : -f 2- | sed -e 's/ //g' -e 's/,/ /g' `
89 # expand to full name if it was a depend
91 x=`find $moddir/kernel -name "$x.*o"`
98 mkdir -p `dirname $tmpdir/$xt`
99 cp $x $tmpdir/$xt 2>/dev/null
106 /sbin/depmod -ae -b $tmpdir -F $sysmap $kernelver
108 echo "Injecting programs and configuration ..."
112 cp -ar ${root}/etc/udev $tmpdir/etc/
113 # in theory all, but fat and currently only cdrom_id is needed ...
114 #cp -ar ${root}/lib/udev/cdrom_id $tmpdir/lib/udev/
118 for x in ${root}/sbin/{hotplug,udevd,modprobe,insmod}
121 file $x | grep -q "dynamically linked" &&
122 echo "Warning: $x is dynamically linked!"
126 x=${root}/sbin/insmod.old
128 echo "Warning: Skipped optional file $x!"
130 file $x | grep -q "dynamically linked" &&
131 echo "Warning: $x is dynamically linked!"
133 ln -s insmod.old $tmpdir/sbin/modprobe.old
136 ln -s /sbin/udev $tmpdir/etc/hotplug.d/default/10-udev.hotplug
137 cp ${root}/bin/bash $tmpdir/bin/sh
139 # static, tiny embutils and friends
141 #cp ${root}/usr/embutils/{mount,umount,rm,mv,mkdir,ln,ls,switch_root,sleep,losetup,chmod,cat,sed,mknod} \
143 ln -s mv $tmpdir/bin/cp
145 cp ${root}/sbin/init $tmpdir/init
147 # Custom ACPI DSDT table
148 if test -f "${root}/boot/DSDT.aml"; then
149 echo "Adding local DSDT file: $dsdt"
150 cp ${root}/boot/DSDT.aml $tmpdir/DSDT.aml
153 # create the cpio image
157 find . | cpio -o -H newc | gzip -c9 > ${root}/boot/initrd-$kernelver.img
160 # display the resulting image
162 du -sh ${root}/boot/initrd-$kernelver.img