2 # --- SDE-COPYRIGHT-NOTE-BEGIN ---
3 # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
5 # Filename: package/.../mkinitrd/mkinitrd.sh
6 # Copyright (C) 2006 - 2008 The OpenSDE Project
7 # Copyright (C) 2005 - 2006 The T2 SDE Project
9 # More information can be found in the files COPYING and README.
11 # This program is free software; you can redistribute it and/or modify
12 # it under the terms of the GNU General Public License as published by
13 # the Free Software Foundation; version 2 of the License. A copy of the
14 # GNU General Public License can be found in the file COPYING.
15 # --- SDE-COPYRIGHT-NOTE-END ---
20 if [ $UID != 0 ]; then
21 echo "Non root - exiting ..."
27 [0-9]*) kernelver
="$1" ;;
28 -R) root
="$2" ; shift ;;
29 *) echo "Usage: mkinitrd [ -R root ] [ kernelver ]"
36 [ "$kernelver" ] || kernelver
=`uname -r`
37 [ "$moddir" ] || moddir
="${root}/lib/modules/$kernelver"
39 echo "Kernel: $kernelver, module dir: $moddir"
41 if [ ! -d $moddir ]; then
42 echo "Module dir $moddir does not exist!"
47 [ -f "${root}/boot/System.map_$kernelver" ] && sysmap
="${root}/boot/System.map_$kernelver"
49 if [ -z "$sysmap" ]; then
50 echo "System.map_$kernelver not found!"
54 echo "System.map: $sysmap"
57 for x
in cpio gzip ; do
58 if ! which $x >/dev
/null
; then
66 # create basic structure
68 rm -rf $tmpdir >/dev
/null
70 echo "Create dirtree ..."
72 mkdir
-p $tmpdir/{dev
,bin
,sbin
,proc
,sys
,lib
/modules
,lib
/udev
,etc
/hotplug.d
/default
}
73 mknod
$tmpdir/dev
/console c
5 1
75 # copy the basic / rootfs kernel modules
77 echo "Copying kernel modules ..."
79 if [ -x /sbin
/modinfo
-a -x /sbin
/depmod
]; then
80 find $moddir/kernel
-type f |
grep \
81 -e reiserfs
-e reiser4
-e ext2
-e ext3
-e /jfs
-e /xfs \
82 -e isofs
-e udf
-e /unionfs
-e ntfs
-e fat
-e dm-mod
-e md-mod \
83 -e /ide
/ -e /ata
/ -e /scsi
/ -e /message
/ -e hci \
84 -e usb-storage
-e sbp2
-e /md
/raid \
85 -e drivers
/net
/ -e '/ipv6\.' |
87 for x
in $fn `/sbin/modinfo $fn | grep depends |
88 cut -d : -f 2- | sed -e 's/ //g' -e 's/,/ /g' `
90 # expand to full name if it was a depend
92 x
=`find $moddir/kernel -name "$x.*o"`
99 mkdir
-p `dirname $tmpdir/$xt`
100 cp $x $tmpdir/$xt 2>/dev
/null
102 done |
fold -s ; echo
106 /sbin
/depmod
-ae -b $tmpdir -F $sysmap $kernelver
109 echo "ERROR: modinfo or depmod are missing in your installation."
114 echo "Injecting programs and configuration ..."
119 # group (needed by udev to resolve group names)
120 cp -a ${root}/etc
/group
$tmpdir/etc
/
122 cp -ar ${root}/etc
/udev
$tmpdir/etc
/
123 # in theory all, but fat and currently only cdrom_id is needed ...
124 cp -ar ${root}/lib
/udev
/* $tmpdir/lib
/udev
/
128 for x
in ${root}/sbin
/{udevd
,udevtrigger
,udevsettle
,modprobe
,insmod
} ${root}/usr
/sbin
/disktype
131 file $x |
grep -q "dynamically linked" &&
132 echo "Warning: $x is dynamically linked!"
136 x
=${root}/sbin
/insmod.old
138 echo "Warning: Skipped optional file $x!"
140 file $x |
grep -q "dynamically linked" &&
141 echo "Warning: $x is dynamically linked!"
143 ln -s insmod.old
$tmpdir/sbin
/modprobe.old
146 ln -s /sbin
/udev
$tmpdir/etc
/hotplug.d
/default
/10-udev.hotplug
147 cp ${root}/bin
/pdksh
$tmpdir/bin
/sh
149 # static, tiny embutils and friends
151 for x
in mount umount
rm mv cp mkdir
ln ls switch_root
sleep losetup
chmod cat sed mknod
153 if [ -x $root/usr
/embutils
/$x ]; then
154 x
=$root/usr
/embutils
/$x
155 elif [ -x $root/usr
/bin
/$x ]; then
157 elif [ -x $root/bin
/$x ]; then
160 echo "Error: $x was not found!" 1>&2
164 file $x |
grep -q "dynamically linked" &&
165 echo "Warning: $x is dynamically linked!"
169 cp ${root}/sbin
/initrdinit
$tmpdir/init
171 # create the cpio image
175 find * |
cpio -o -H newc |
gzip -c9 > ${root}/boot
/initrd-
$kernelver.img
178 # display the resulting image
180 du
-sh ${root}/boot
/initrd-
$kernelver.img