2 # This a simple implementaton of mkinitrd
6 # Set the umask. For iscsi, the initrd can contain platintext
7 # password (chap secret), so only allow read by owner.
15 IMAGE=$1/initrd.img.$3
28 # this is a hack, but the only better way requires binutils or elfutils
29 # be installed. i.e., we need readelf to find the interpretter.
30 if [ -z "$LDSO" ]; then
31 for ldso in /lib*/ld*.so* ; do
32 [ -L $ldso ] && continue
33 [ -x $ldso ] || continue
34 $ldso --verify $bin >/dev/null 2>&1 || continue
41 while read NAME I0 FILE ADDR I1 ; do
42 [ "$FILE" == "not" ] && FILE="$FILE $ADDR"
47 $(LD_TRACE_PRELINKING=1 LD_WARN= LD_TRACE_LOADED_OBJECTS=1 \
48 $LDSO $bin 2>/dev/null)
51 [ ${#FILES[*]} -eq 0 ] && return 1
53 # we don't want the name of the binary in the list
54 if [ "${FILES[0]}" == "$bin" ]; then
57 [ ${#FILES[*]} -eq 1 ] && return 1
61 while [ $n -lt ${#FILES[*]} ]; do
63 if [ "$FILE" == "not found" ]; then
65 There are missing files on your system. The dynamic object $bin
66 requires ${NAMES[$n]} n order to properly function. mkinitrd cannot continue.
72 TLIBDIR=`echo "$FILE" | sed 's,\(/lib[^/]*\)/.*$,\1,'`
73 BASE=`basename "$FILE"`
74 # Prefer nosegneg libs over direct segment accesses on i686.
75 if [ -f "$TLIBDIR/i686/nosegneg/$BASE" ]; then
76 FILE="$TLIBDIR/i686/nosegneg/$BASE"
77 # Otherwise, prefer base libraries rather than their optimized
79 elif [ -f "$TLIBDIR/$BASE" ]; then
89 DSO_DEPS="${FILES[@]}"
93 echo nash-readlink "$1" | /sbin/nash --force --quiet
98 if [ "$#" != "2" -a "$#" != "3" ];then
99 echo "usage: inst <file> <root> [<destination file>]"
102 local file="$1" ; shift
103 local root="${1%%/}/" ; shift
104 local dest="${1##/}" ; shift
105 [ -z "$dest" ] && dest="${file##/}"
107 local old_indent_chars=${indent_chars}
108 indent_chars="${indent_chars} "
109 indent=${indent_chars:2}
111 mkdir -p "$root/$(dirname $dest)"
115 [ -L "$file" ] && target=$(readlink "$file")
116 if [ -n "$target" -a "$dest" != "$target" ]; then
117 if [ -e "$root$dest" ]; then
118 # echo "${indent}$root/$dest already exists"
121 echo "${indent}$file -> $root$dest"
122 ln -sf "$target" "$root$dest"
124 inst "$target" "$root"
125 l=`echo "$x" | sed -n 's,\(/lib[^/]*\)/.*$,\1,p'`
127 inst "$x" "$root" "$l"/`basename "$x"`
132 indent_chars=${old_indent_chars}
137 local SHEBANG=$(dd if="$file" bs=2 count=1 2>/dev/null)
138 if [ "$SHEBANG" == '#!' ]; then
139 # We're intentionally not playing the "what did this moron run
140 # in his shell script" game. There's nothing but pain in that.
141 local interp=$(head -1 "$file" | sed 's/^#! *//')
142 inst "$interp" "$root"
144 indent_chars=${old_indent_chars}
148 # echo "indent=${indent}, file=${file}"
150 if [ -e "$root$dest" ]; then
151 # echo "${indent}$root$dest already exists"
154 if [ -n "$target" -a -L "$target" ]; then
155 inst "$target" "$root"
158 echo "${indent}$file -> $root$dest"
159 cp -aL "$file" "$root$dest"
162 local DEPS="$DSO_DEPS"
164 TLIBDIR=`echo "$x" | sed 's,\(/lib[^/]*\)/.*$,\1,'`
166 inst "$x" "$root" "$TLIBDIR/$BASE"
171 indent_chars=${old_indent_chars}
175 #if [ -z "$MNTIMAGE" -o -z "$IMAGE" ]; then
176 # error "Error creating temporaries. Try again"
180 rm -fr $MNTIMAGE $IMAGE
183 mkdir -p $MNTIMAGE/lib/firmware
184 mkdir -p $MNTIMAGE/bin
185 mkdir -p $MNTIMAGE/etc
186 mkdir -p $MNTIMAGE/dev
187 mkdir -p $MNTIMAGE/proc
188 mkdir -p $MNTIMAGE/sys
189 mkdir -p $MNTIMAGE/sysroot
190 ln -s bin $MNTIMAGE/sbin
192 echo "Building initrd in $MNTIMAGE"
193 inst /sbin/nash "$MNTIMAGE" /bin/nash
194 ln -s /sbin/nash $MNTIMAGE/sbin/modprobe
195 ln -s /lib/ld-2.7.so $MNTIMAGE/lib/ld-linux.so.2
197 inst /sbin/insmod "$MNTIMAGE" /bin/insmod
198 inst /sbin/rmmod "$MNTIMAGE" /bin/rmmod
200 # mknod'ing the devices instead of copying them works both with and
202 mkdir $MNTIMAGE/dev/mapper
204 mknod $MNTIMAGE/dev/ram0 b 1 0
205 mknod $MNTIMAGE/dev/ram1 b 1 1
206 ln -sf ram1 $MNTIMAGE/dev/ram
208 mknod $MNTIMAGE/dev/null c 1 3
209 mknod $MNTIMAGE/dev/zero c 1 5
210 mknod $MNTIMAGE/dev/systty c 4 0
211 if ! echo "$(uname -m)" | grep -q "s390"; then
212 for i in 0 1 2 3 4 5 6 7 8 9 10 11 12 ; do
213 mknod $MNTIMAGE/dev/tty$i c 4 $i
216 for i in 0 1 2 3 ; do
217 mknod $MNTIMAGE/dev/ttyS$i c 4 $(($i + 64))
219 mknod $MNTIMAGE/dev/tty c 5 0
220 mknod $MNTIMAGE/dev/console c 5 1
221 mknod $MNTIMAGE/dev/ptmx c 5 2
222 mknod $MNTIMAGE/dev/rtc c 10 135
223 if [ "$(uname -m)" == "ia64" ]; then
224 mknod $MNTIMAGE/dev/efirtc c 10 136
235 if [ "$1" == "-n" ]; then
239 echo $NONL "$@" >> $RCFILE
246 mount -t proc /proc /proc
248 echo Mounting proc filesystem
249 echo Mounting sysfs filesystem
250 mount -t sysfs /sys /sys
252 mount -o mode=0755 -t tmpfs /dev /dev
254 mount -t devpts -o gid=5,mode=620 /dev/pts /dev/pts
257 echo Creating initial device nodes
258 mknod /dev/null c 1 3
259 mknod /dev/zero c 1 5
260 mknod /dev/systty c 4 0
262 mknod /dev/console c 5 1
263 mknod /dev/ptmx c 5 2
264 mknod /dev/rtc c 10 135
266 if [ "$(uname -m)" == "ia64" ]; then
267 emit "mknod /dev/efirtc c 10 136"
270 # XXX really we need to openvt too, in case someting changes the
271 # color palette and then changes vts on fbcon before gettys start.
273 if ! echo "$(uname -m)" | grep -q "s390"; then
274 for i in 0 1 2 3 4 5 6 7 8 9 10 11 12 ; do
275 emit "mknod /dev/tty$i c 4 $i"
279 for i in 0 1 2 3 ; do
280 emit "mknod /dev/ttyS$i c 4 $(($i + 64))"
283 emit "echo Setting up hotplug."
286 emit "echo Creating block device nodes."
289 # HACK: module loading + device creation isn't necessarily synchronous...
290 # this will make sure that we have all of our devices before trying
291 # things like RAID or LVM
294 emit "echo Execute customized programs"