[runit] fixed to not create ${root}sbin/
[opensde-package-nopast.git] / base / mkinitrd / mkinitrd.sh
blob7e1fb9ddf3d3eb3222b42a26050ad74c5d8e18bf
1 #!/bin/sh
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 ---
18 set -e
20 if [ $UID != 0 ]; then
21 echo "Non root - exiting ..."
22 exit 1
25 while [ "$1" ]; do
26 case $1 in
27 [0-9]*) kernelver="$1" ;;
28 -R) root="$2" ; shift ;;
29 *) echo "Usage: mkinitrd [ -R root ] [ kernelver ]"
30 exit 1 ;;
31 esac
32 shift
33 done
35 [ "$root" ] || root=
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!"
43 exit 2
46 sysmap=
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!"
51 exit 2
54 echo "System.map: $sysmap"
56 # check needed tools
57 for x in cpio gzip ; do
58 if ! which $x >/dev/null ; then
59 echo "$x not found!"
60 exit 2
62 done
64 tmpdir=`mktemp`
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\.' |
86 while read fn ; do
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
91 [ $x = ${x##*/} ] &&
92 x=`find $moddir/kernel -name "$x.*o"`
94 echo -n "${x##*/} "
96 # strip $root prefix
97 xt=${x##$root}
99 mkdir -p `dirname $tmpdir/$xt`
100 cp $x $tmpdir/$xt 2>/dev/null
101 done
102 done | fold -s ; echo
104 # generate map files
106 /sbin/depmod -ae -b $tmpdir -F $sysmap $kernelver
108 else
109 echo "ERROR: modinfo or depmod are missing in your installation."
110 exit 1
114 echo "Injecting programs and configuration ..."
116 # copying config
119 # group (needed by udev to resolve group names)
120 cp -a ${root}/etc/group $tmpdir/etc/
121 # udev
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/
126 # setup programs
128 for x in ${root}/sbin/{udevd,udevtrigger,udevsettle,modprobe,insmod} ${root}/usr/sbin/disktype
130 # sanity check
131 file $x | grep -q "dynamically linked" &&
132 echo "Warning: $x is dynamically linked!"
133 cp $x $tmpdir/sbin/
134 done
136 x=${root}/sbin/insmod.old
137 if [ ! -e $x ]; then
138 echo "Warning: Skipped optional file $x!"
139 else
140 file $x | grep -q "dynamically linked" &&
141 echo "Warning: $x is dynamically linked!"
142 cp $x $tmpdir/sbin/
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
156 x=$root/usr/bin/$x
157 elif [ -x $root/bin/$x ]; then
158 x=$root/bin/$x
159 else
160 echo "Error: $x was not found!" 1>&2
161 false
163 # sanity check
164 file $x | grep -q "dynamically linked" &&
165 echo "Warning: $x is dynamically linked!"
166 cp $x $tmpdir/bin/
167 done
169 cp ${root}/sbin/initrdinit $tmpdir/init
171 # create the cpio image
173 echo "Archiving ..."
174 ( cd $tmpdir
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
181 rm -rf $tmpdir