]>
Commit | Line | Data |
---|---|---|
bb529f94 JK |
1 | #!/bin/sh |
2 | ||
3 | # geninitrd | |
4 | # | |
45d4d8cb | 5 | # by PLD Linux Team |
bb529f94 | 6 | # |
9e1ceabe | 7 | # based on mkinitrd from RedHat Linux |
e4b07ddc | 8 | # |
9 | # TODO: | |
10 | # - make udev start before insomds | |
11 | # - make proper use of USE_UDEV - don't copy fules if USE_UDEV is off no! | |
12 | # - sanitize - one mounting of /proc and /sys at the begining and one umount at the end! | |
aebe301c | 13 | # |
c31050f3 | 14 | |
28eec2b1 | 15 | RCSID='$Id$' |
ca2c2012 ER |
16 | R=${RCSID#* * }; VERSION=${R%% *} |
17 | PROGRAM=${0##*/} | |
bb529f94 JK |
18 | |
19 | . /etc/rc.d/init.d/functions | |
1cea325b | 20 | . /etc/geninitrd/functions |
bb529f94 JK |
21 | |
22 | COMPRESS="yes" | |
2ad94d8a AF |
23 | # INITRDFS is set later (catch obsoleted FS option) |
24 | #INITRDFS="rom" | |
6bd433bc | 25 | USERAIDSTART="yes" |
d3fa6ec7 | 26 | USEMDADMSTATIC="no" |
b2e62ae1 | 27 | USEINSMODSTATIC="no" |
4ef98747 | 28 | USE_SUSPEND="yes" |
1cd2aabd | 29 | USE_TUXONICE="yes" |
7c38b114 | 30 | uselvm="no" |
6fe19d5b | 31 | usenfs="no" |
10c3df06 MM |
32 | # it should be safe to remove scsi_mod from here, but I'm not sure... |
33 | PRESCSIMODS="-scsi_mod unknown -sd_mod" | |
64497ebb AM |
34 | PREIDEMODS="-ide-core unknown -ide-detect -ide-disk" |
35 | PREIDEMODSOLD="-ide-probe -ide-probe-mod -ide-disk" | |
bb529f94 JK |
36 | target="" |
37 | kernel="" | |
38 | force="" | |
39 | verbose="" | |
40 | MODULES="" | |
41 | img_vers="" | |
f121024f | 42 | modulefile="" |
bb529f94 | 43 | fstab="/etc/fstab" |
0868f49f AF |
44 | insmod="insmod" |
45 | modext=".o" | |
4e9eb79c | 46 | rootdev_nr=0 |
738c05d8 ER |
47 | # device node for rootfs from fstab |
48 | rootdev="" | |
5b71959c AM |
49 | # default bootsplash is off, if it have to be on, install bootsplash package |
50 | BOOT_SPLASH=no | |
e4b07ddc | 51 | # default same as bootsplash, if on install splashutils and some splashutils theme |
52 | FB_SPLASH=no | |
53 | # defualt we don't use udev to make nodes for static modules, as per default | |
54 | # PLD loads the modules needed to mount and boot | |
55 | PROBESTATICMODULES=no | |
bb529f94 | 56 | |
8bd582f1 ER |
57 | # internal variables |
58 | # is /dev on tmpfs | |
59 | tmpfs_dev=no | |
60 | # is /proc/devices entries already created | |
61 | proc_partitions=no | |
f155a80b ER |
62 | # dmraid component devices of rootfs is on dmraid |
63 | dmraid_devices='' | |
b4d9d384 | 64 | |
447ff04b | 65 | if [ -f /etc/udev/udev.conf -a -x /sbin/initrd-udevd ]; then |
1606e343 | 66 | USE_UDEV="yes" |
1606e343 AM |
67 | . /etc/udev/udev.conf |
68 | fi | |
882472ae ER |
69 | |
70 | if [ -x /sbin/dmraid-initrd ]; then | |
71 | USE_DMRAID="yes" | |
72 | fi | |
ac085800 | 73 | |
2cc3ae8b ER |
74 | if [ -x /sbin/multipath ]; then |
75 | USE_MULTIPATH="yes" | |
76 | fi | |
77 | ||
bb529f94 | 78 | usage () { |
553786c4 | 79 | uname_r=$(uname -r) |
00eaa938 | 80 | echo "usage: $PROGRAM [--version] [-v] [-f] [--ifneeded] [--preload <module>]" |
ac085800 | 81 | echo " [--with=<module>] [--image-version] [--fstab=<fstab>] [--nocompress]" |
92ed99b6 | 82 | echo " [--initrdfs=rom|initramfs|ext2|cram] [--modules-conf=<modules.conf>]" |
ac085800 | 83 | echo " [--with-raidstart] [--without-raidstart] [--with-insmod-static]" |
ba5d09f0 | 84 | echo " [--with-bootsplash] [--without-bootsplash]" |
85 | echo " [ --with-fbsplash] [--without-fbsplash]" | |
e4b07ddc | 86 | echo " [--lvmtoolsversion=1|2] [--with-udev] [--without-udev]" |
ba5d09f0 | 87 | echo " [--with-suspend] [--without-suspend]" |
1cd2aabd | 88 | echo " [--with-tuxonice] [--without-tuxonice]" |
2cc3ae8b | 89 | echo " [--without-dmraid] [--without-multipath]" |
ac085800 | 90 | echo " <initrd-image> <kernel-version>" |
553786c4 ER |
91 | echo "" |
92 | echo "example:" | |
00eaa938 | 93 | echo " $PROGRAM -f --initrdfs=rom /boot/initrd-$uname_r.gz $uname_r" |
7d2fc5eb | 94 | exit 1 |
bb529f94 JK |
95 | } |
96 | ||
94769f11 | 97 | debug() { |
f155a80b | 98 | [ -n "$verbose" ] && echo >&2 "$*" |
94769f11 | 99 | } |
aa69da6e | 100 | |
bf6c3fcb ER |
101 | # aborts program abnormally |
102 | die() { | |
b5f5c089 | 103 | local rc=${2:-1} |
bf6c3fcb ER |
104 | echo >&2 "$PROGRAM: ERROR: $1" |
105 | exit $rc | |
106 | } | |
107 | ||
9299682f ER |
108 | # Checks if busybox has support for APPLET(s) |
109 | # Exits from geninitrd if the support is not present. | |
110 | # | |
111 | # NB! XXX do not output to STDOUT, it will appear in initrd images in some cases! | |
112 | busybox_applet() { | |
113 | local err=0 | |
114 | ||
115 | if [ -z "$busybox_functions" ]; then | |
9b1373fb ER |
116 | local tmp=$(/bin/initrd-busybox 2>&1) |
117 | ||
118 | # BusyBox v1.1.3 says applet not found if it's not called 'busybox'. | |
119 | if [[ "$tmp" = *applet\ not\ found* ]]; then | |
120 | local t=$(mktemp -d) | |
121 | ln -s /bin/initrd-busybox $t/busybox | |
122 | local tmp=$($t/busybox 2>&1) | |
123 | rm -rf $t | |
124 | fi | |
125 | ||
126 | busybox_functions=$(echo "$tmp" | \ | |
9299682f ER |
127 | sed -ne '/Currently defined functions:/,$p' | \ |
128 | xargs | sed -e 's,.*Currently defined functions: ,,' | |
129 | ) | |
130 | fi | |
131 | for applet in $*; do | |
132 | local have | |
133 | # try cache | |
134 | eval have='$'busybox_have_$applet | |
135 | if [ -z "$have" ]; then | |
136 | have=$(echo "$busybox_functions" | egrep -c "( |^)$applet(,|$)") | |
137 | if [ "$have" = 0 ]; then | |
138 | echo >&2 "This setup requires busybox-initrd compiled with applet '$applet' support" | |
139 | err=1 | |
140 | fi | |
141 | eval busybox_have_$applet=$have | |
142 | fi | |
143 | done | |
144 | if [ $err = 1 ]; then | |
00eaa938 | 145 | die "Aborted" |
9299682f ER |
146 | fi |
147 | } | |
148 | ||
10c3df06 MM |
149 | find_depmod () { |
150 | typeset mods module f level depfile first | |
151 | ||
152 | depfile=/lib/modules/$kernel/modules.dep | |
ac085800 | 153 | |
00eaa938 | 154 | if [ ! -f $depfile ]; then |
9e1ceabe | 155 | die "No $depfile! Run depmod and rerun $PROGRAM." |
f6de9380 | 156 | fi |
ac085800 | 157 | |
0868f49f | 158 | # prepend / if no path given, append $modext.gz if not given, |
10c3df06 | 159 | # quote / |
3b00e899 | 160 | origmodule="$2" |
10c3df06 | 161 | module=$(echo "$2" | \ |
ac085800 ER |
162 | awk '/\// {print;next} {print "/" $0}' | \ |
163 | awk '/\./ {print;next} {print $0 "'$modext'.gz"}' | | |
164 | awk '{gsub("/","\\/");print}') | |
10c3df06 MM |
165 | mods=$(awk ' |
166 | BEGIN { here = 0 } | |
167 | /'"$module"':(.*)/ { gsub(/:/," "); gsub(/\\/," "); print; here = 1; next } | |
168 | /:/ { here = 0 } | |
169 | /(.*)/ { gsub(/\\/," "); if (here) print } | |
4fd11db9 AF |
170 | ' $depfile | xargs) |
171 | ||
0868f49f | 172 | # fallback to $modext |
4fd11db9 | 173 | if [ "$mods" = "" ] ; then |
00eaa938 | 174 | module=$(echo "$module" | awk '{gsub("\'$modext'\.gz$","\'$modext'",$0);print}') |
740d6215 | 175 | # ") - vim |
ac085800 | 176 | fi |
00eaa938 | 177 | |
4fd11db9 AF |
178 | mods=$(awk ' |
179 | BEGIN { here = 0 } | |
180 | /'"$module"':(.*)/ { gsub(/:/," "); gsub(/\\/," "); print; here = 1; next } | |
181 | /:/ { here = 0 } | |
182 | /(.*)/ { gsub(/\\/," "); if (here) print } | |
10c3df06 MM |
183 | ' $depfile | xargs) |
184 | ||
185 | if [ "$mods" = "" ] ; then | |
186 | if [ "$1" != silent ] ; then | |
94769f11 | 187 | echo >&2 "$origmodule: module not found in $depfile" |
10c3df06 | 188 | fi |
00eaa938 | 189 | if ! is_no "$EXIT_IF_MISSING"; then |
fd2dc249 AF |
190 | exit 1 |
191 | else | |
94769f11 | 192 | echo >&2 "If $origmodule isn't compiled in kernel then this initrd may not start your system." |
fd2dc249 | 193 | fi |
10c3df06 | 194 | fi |
ac085800 | 195 | |
10c3df06 MM |
196 | level=$3 |
197 | if [ "$level" = "" ] ; then | |
198 | level=0 | |
199 | fi | |
94769f11 | 200 | level=$((level + 1)) |
10c3df06 | 201 | if [ $level -gt 20 ] ; then |
00eaa938 | 202 | die "$origmodule: cycle in $depfile" |
10c3df06 | 203 | fi |
ac085800 | 204 | |
10c3df06 MM |
205 | first= |
206 | for f in $mods ; do | |
207 | if [ "$first" = "" ] ; then | |
208 | first=$f | |
413878f8 | 209 | else |
10c3df06 | 210 | find_depmod $1 $f $level |
9c9f7cdb | 211 | fi |
aa69da6e | 212 | done |
ac085800 | 213 | |
10c3df06 | 214 | echo $first |
aa69da6e | 215 | } |
216 | ||
10c3df06 MM |
217 | addmodule() { |
218 | fmPath=$1 | |
219 | skiperrors=$2 | |
220 | ||
221 | if [ ! -f "/lib/modules/$kernel/$fmPath" ]; then | |
222 | if [ -n "$skiperrors" ]; then | |
223 | return | |
224 | fi | |
225 | ||
00eaa938 | 226 | die "module $fmPath present in modules.dep, but not in filesystem (kernel = $kernel)" |
10c3df06 MM |
227 | fi |
228 | ||
229 | # only need to add each module once | |
230 | # quote / | |
231 | tmpFmPath=$(echo $fmPath | awk '{gsub(/\//,"\\/");print}') | |
232 | if echo "$MODULES" | awk '/'"$tmpFmPath"'/ {exit 1}' ; then | |
233 | MODULES="$MODULES $fmPath" | |
234 | fi | |
81de8443 AF |
235 | } |
236 | ||
bb529f94 | 237 | findmodule() { |
413878f8 | 238 | skiperrors="" |
239 | modName=$1 | |
10c3df06 | 240 | |
94769f11 | 241 | if [ ${modName#-} != ${modName} ]; then |
413878f8 | 242 | skiperrors=1 |
94769f11 | 243 | modName=${modName#-} |
413878f8 | 244 | fi |
bb529f94 | 245 | |
10c3df06 | 246 | # what's that? |
413878f8 | 247 | if [ "$modName" = "pluto" ]; then |
248 | findmodule fc4 | |
249 | findmodule soc | |
250 | fi | |
251 | if [ "$modName" = "fcal" ]; then | |
252 | findmodule fc4 | |
253 | findmodule socal | |
254 | fi | |
bb529f94 | 255 | |
10c3df06 | 256 | if [ -n "$skiperrors" ]; then |
94769f11 | 257 | allModulesToFind=$(find_depmod silent $modName) |
10c3df06 | 258 | else |
94769f11 ER |
259 | allModulesToFind=$(find_depmod normal $modName) |
260 | if [ $? != 0 ]; then | |
10c3df06 | 261 | exit 1 |
413878f8 | 262 | fi |
413878f8 | 263 | fi |
ac085800 | 264 | |
94769f11 ER |
265 | for mod in $allModulesToFind; do |
266 | mod=$(echo $mod | awk '{sub(/^\/lib\/modules\/[^\/]*\//, ""); print}') | |
10c3df06 MM |
267 | addmodule $mod "$skiperrors" |
268 | done | |
bb529f94 JK |
269 | } |
270 | ||
034fdd5d ER |
271 | # install a file to temporary mount image. |
272 | # it will operate recursively (copying directories) | |
273 | # and will symlink destinations if source is symlink. | |
bb529f94 | 274 | inst() { |
dab92b1d | 275 | if [ "$#" -lt "2" ];then |
1775ba37 | 276 | die 'Usage: inst <file> $MNTIMAGE<destination>' |
c31050f3 | 277 | fi |
dab92b1d | 278 | debug "$1${3:+ ...} -> $MNTIMAGE$2" |
1775ba37 | 279 | cp -HR "$1" "$MNTIMAGE$2" |
bb529f94 JK |
280 | } |
281 | ||
dab92b1d | 282 | inst_d() { |
034fdd5d | 283 | if [ "$#" = "0" ];then |
dab92b1d | 284 | die 'Usage: inst_d $MNTIMAGE<destination> $MNTIMAGE<destination>' |
034fdd5d ER |
285 | fi |
286 | for dir in "$@"; do | |
287 | debug "mkdir $MNTIMAGE$dir" | |
288 | install -d "$MNTIMAGE$dir" | |
289 | done | |
290 | } | |
291 | ||
7c38b114 | 292 | find_modules_softraid() { |
ac085800 | 293 | if [ -f /etc/mdadm.conf ]; then |
94769f11 | 294 | debug "Finding RAID details using mdadm for rootdev=$1" |
ac085800 ER |
295 | eval `/sbin/mdadm -v --examine --scan --config=/etc/mdadm.conf | awk -v rootdev="$1" ' |
296 | BEGIN { | |
297 | found = "no"; | |
298 | dev_list = ""; | |
299 | raidlevel = "" | |
300 | rootdev_devfs = rootdev; | |
301 | if (rootdev ~ /\/dev\/md\/[0-9]/) { | |
302 | gsub(/\/dev\/md\//,"/dev/md",rootdev_devfs); | |
303 | } | |
514a668a | 304 | } |
ac085800 ER |
305 | |
306 | /^ARRAY/ { | |
307 | if (($2 == rootdev) || ($2 == rootdev_devfs)) { | |
308 | raidlevel=$3; | |
309 | gsub(/level=/,NUL,raidlevel); | |
310 | if (raidlevel ~ /^raid([0-6]|10)/) { | |
311 | gsub(/raid/,NUL,raidlevel); | |
312 | }; | |
313 | found="yes"; | |
314 | getline x; | |
315 | if (x ~ /devices=/) { | |
316 | dev_list = x; | |
317 | gsub(".*devices=", NUL, dev_list); | |
318 | gsub(",", " ", dev_list); | |
319 | } | |
320 | } | |
56946560 | 321 | } |
ac085800 ER |
322 | |
323 | END { | |
324 | print "raidfound=" found; | |
325 | print "raidlevel=" raidlevel; | |
326 | print "dev_list=\"" dev_list "\""; | |
327 | }'` | |
328 | fi | |
7c38b114 | 329 | |
59846acb | 330 | if [ "$raidfound" != "yes" -a -f /etc/raidtab ]; then |
00eaa938 | 331 | die "raidtools are not longer supported. Please migrate to mdadm setup!" |
809cc4cc | 332 | fi |
ac085800 | 333 | |
7c38b114 AF |
334 | if is_yes "$raidfound" ; then |
335 | case "$raidlevel" in | |
bf17c86c | 336 | [01]|10) |
7c38b114 AF |
337 | findmodule "raid$raidlevel" |
338 | ;; | |
bf17c86c AM |
339 | [456]) |
340 | findmodule "-raid$raidlevel" | |
341 | findmodule "-raid456" | |
342 | ;; | |
7c38b114 AF |
343 | linear) |
344 | findmodule "linear" | |
345 | ;; | |
346 | *) | |
94769f11 | 347 | echo >&2 "raid level $number (in mdadm config) not recognized" |
7c38b114 AF |
348 | ;; |
349 | esac | |
88614cd1 | 350 | else |
00eaa938 | 351 | die "RAID devices not found for \"$1\", check your configuration!" |
7c38b114 | 352 | fi |
4e9eb79c AM |
353 | |
354 | rootdev_nr=$(( $rootdev_nr + 1 )) | |
355 | eval "rootdev${rootdev_nr}=\"$1\"" | |
356 | eval "dev_list${rootdev_nr}=\"${dev_list}\"" | |
ac085800 | 357 | |
7c38b114 | 358 | for device in $dev_list; do |
a8007847 | 359 | find_modules_for_device $device |
7c38b114 AF |
360 | done |
361 | } | |
362 | ||
363 | find_modules_scsi() { | |
364 | for n in $PRESCSIMODS; do | |
365 | if [ "X$n" = "Xunknown" ] ; then | |
7c38b114 | 366 | if [ -f "$modulefile" ]; then |
d4a15d5f | 367 | scsimodules="`awk '/scsi_hostadapter/ && ! /^[\t ]*#/ { print $3; }' $modulefile`" |
7c38b114 AF |
368 | for n in $scsimodules; do |
369 | # for now allow scsi modules to come from anywhere. There are some | |
370 | # RAID controllers with drivers in block | |
371 | findmodule "$n" | |
372 | done | |
373 | fi | |
374 | else | |
375 | findmodule "$n" | |
376 | fi | |
377 | done | |
84df18b8 | 378 | findmodule "-scsi_wait_scan" |
7c38b114 AF |
379 | } |
380 | ||
381 | find_modules_ide() { | |
f0615744 ER |
382 | local rootblkdev |
383 | ||
384 | # set blockdev for rootfs (hda, sdc, ...) | |
385 | rootblkdev="$(echo "$1" | awk ' { gsub(/\/dev\//,NUL); gsub(/[0-9].*/, NUL); print $0 } ')" | |
ac085800 | 386 | |
ac085800 | 387 | if [ "$pack_version_long" -lt "002004021" ]; then |
94769f11 | 388 | debug "Finding IDE modules for kernels <= 2.4.20" |
ac085800 ER |
389 | for n in $PREIDEMODSOLD; do |
390 | findmodule "$n" | |
391 | done | |
64497ebb | 392 | else |
ac085800 ER |
393 | tryauto=1 |
394 | for n in $PREIDEMODS; do | |
395 | if [ "X$n" = "Xunknown" ] ; then | |
396 | if [ -f "$modulefile" ]; then | |
94769f11 | 397 | debug "Finding IDE modules using ide_hostadapter" |
ac085800 ER |
398 | idemodules="`awk '/ide_hostadapter/ && ! /^[\t ]*#/ { print $3; }' $modulefile`" |
399 | for na in $idemodules; do | |
400 | tryauto=0; | |
401 | findmodule "$na" | |
402 | done | |
403 | fi | |
64497ebb | 404 | |
ac085800 ER |
405 | if [ "$tryauto" -eq 1 ]; then |
406 | # If tryauto {{{ | |
407 | if [ -r /usr/share/pci-database/ide.pci -a -r /proc/bus/pci/devices ]; then | |
94769f11 | 408 | debug "Finding IDE modules using PCI ID database" |
ac085800 ER |
409 | # Finding IDE modules using PCI ID database {{{ |
410 | if is_yes "${ide_only_root}"; then | |
f0615744 ER |
411 | if [ -f /sys/block/${rootblkdev}/device/../../vendor -a -f /sys/block/${rootblkdev}/device/../../device ]; then |
412 | vendorid="$(awk ' { gsub(/0x/,NUL); print $0 } ' /sys/block/${rootblkdev}/device/../../vendor)" | |
413 | deviceid="$(awk ' { gsub(/0x/,NUL); print $0 } ' /sys/block/${rootblkdev}/device/../../device)" | |
ac085800 | 414 | searchpciid="${vendorid}${deviceid}" |
f0615744 ER |
415 | elif [ -f /proc/ide/${rootblkdev}/../config ]; then |
416 | searchpciid="$(awk ' /pci bus/ { print $7$9 } ' /proc/ide/${rootblkdev}/../config)" | |
ac085800 ER |
417 | fi |
418 | fi | |
419 | ||
420 | if [ -z "${searchpciid}" ]; then | |
421 | searchpciid="$(awk ' { print $2 } ' /proc/bus/pci/devices)" | |
422 | fi | |
423 | ||
424 | idemodules="" | |
425 | ||
426 | for nb in $searchpciid; do | |
427 | eval `awk -v pciid="$nb" '{ | |
428 | gsub("\t"," "); | |
429 | gsub(" +", " "); | |
430 | gsub("^ ",""); | |
431 | if (/^[\t ]*#/) | |
432 | next; | |
433 | compmod = $1 ""; # make sure comparison type will be string | |
434 | # cause pci IDs are hexadecimal numeric | |
435 | if (compmod == pciid) { | |
436 | module=$2; | |
437 | # min_kernel=$3; # now in ide.pci $3,$4 = vendor and device name | |
438 | # max_kernel=$4; # | |
439 | exit 0; | |
440 | } | |
441 | } | |
442 | ||
443 | END { | |
444 | print "module=" module "\nmin_kernel=" min_kernel "\nmax_kernel=\"" max_kernel "\"\n"; | |
445 | }' /usr/share/pci-database/ide.pci` | |
446 | [ -n "$module" ] && idemodules="$idemodules $module" | |
447 | done | |
448 | if is_yes "$(awk ' /ide=reverse/ { print "yes" } ' /proc/cmdline)"; then | |
449 | new_idemodules="" | |
450 | for nc in idemodules; do | |
451 | new_idemodules="$nc $new_idemodules" | |
452 | done | |
453 | idemodules="${new_idemodules}" | |
454 | fi | |
455 | ||
456 | if [ -z "$idemodules" ]; then | |
457 | echo "WARNING: rootfs on IDE device but no related modules found, loading ide-generic." | |
458 | idemodules="ide-generic" | |
459 | fi | |
460 | ||
461 | # }}} | |
462 | for nd in $idemodules; do | |
463 | findmodule "-$nd" | |
464 | done | |
465 | # }}} | |
466 | # else tryauto {{{ | |
467 | else | |
468 | [ -r /usr/share/pci-database/ide.pci ] || echo "WARNING: /usr/share/pci-database/ide.pci missing." | |
469 | [ -r /proc/bus/pci/devices ] || echo "WARNING: /proc/bus/pci/devices missing." | |
470 | echo "Automatic IDE modules finding not available." | |
471 | fi | |
472 | # }}} | |
473 | fi | |
474 | else | |
475 | findmodule "$n" | |
5de40f1f | 476 | fi |
ac085800 | 477 | done |
64497ebb | 478 | fi |
7c38b114 AF |
479 | } |
480 | ||
a7fce633 ER |
481 | # return true if node is lvm node |
482 | _check_lvm() { | |
483 | local node="$1" | |
484 | if [ ! -e "$node" ]; then | |
94769f11 | 485 | echo >&2 "WARNING: check_lvm(): node $node doesn't exist!" |
a7fce633 ER |
486 | return 1 |
487 | fi | |
488 | ||
489 | # block-major-58 is lvm1 | |
490 | ls -lL "$node" 2> /dev/null | awk '{if (/^b/) { if ($5 == "58,") { exit 0; } else { exit 1; } } else { exit 1; }}' | |
491 | rc=$? | |
492 | ||
493 | if [ $rc = 0 ]; then | |
94769f11 | 494 | debug "$node is LVM1 node" |
a7fce633 ER |
495 | # is lvm1 |
496 | return 0 | |
497 | fi | |
498 | ||
499 | /sbin/lvm lvdisplay "$node" > /dev/null 2>&1 | |
500 | rc=$? | |
501 | if [ $rc -gt 127 ]; then | |
502 | # lvdisplay terminated by signal! most likely it segfaulted. | |
00eaa938 | 503 | die "Unexpected exit from 'lvdisplay $node': $rc - are your lvm tools broken?" |
a7fce633 ER |
504 | fi |
505 | ||
506 | if [ $rc = 0 ]; then | |
94769f11 | 507 | debug "$node is lvm2 node" |
a7fce633 | 508 | else |
94769f11 | 509 | debug "$node is not any lvm node" |
a7fce633 ER |
510 | fi |
511 | return $rc | |
512 | } | |
513 | ||
bc0d6f2d | 514 | # find modules for $devpath |
a8007847 | 515 | find_modules_for_device() { |
bc0d6f2d ER |
516 | local devpath="$1" |
517 | if [ -z "$devpath" ]; then | |
a8007847 | 518 | die "No argument passed to find_modules_for_device() - is your /etc/fstab correct?" |
f6536797 | 519 | fi |
ac085800 | 520 | |
bc0d6f2d ER |
521 | # /dev/dm-3 -> /dev/mapper/sil_ahbgadcbchfc3 |
522 | case "$devpath" in | |
523 | /dev/dm-*) | |
524 | devpath=$(dm_longname "$devpath") | |
525 | ;; | |
526 | esac | |
527 | ||
bc0d6f2d | 528 | if is_yes "`echo "$devpath" | awk '/^([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+:|\/dev\/nfs)/ { print "yes"; }'`"; then |
5c4cec75 | 529 | if [ ! -x /usr/bin/pcidev -a -z "$NFS_ETH_MODULES" ] ; then |
00eaa938 | 530 | die "root on NFS but /usr/bin/pcidev not found. Please install correct pci-database package and rerun $PROGRAM." |
6fe19d5b | 531 | fi |
5c4cec75 AM |
532 | [ -z "$NFS_ETH_MODULES" ] && NFS_ETH_MODULES=$(/usr/bin/pcidev /m net | xargs) |
533 | for m in $NFS_ETH_MODULES; do | |
ac085800 | 534 | findmodule "$m" |
6fe19d5b AM |
535 | done |
536 | findmodule "-ipv4" | |
ac085800 | 537 | findmodule "nfs" |
6fe19d5b | 538 | usenfs="yes" |
d024196b | 539 | echo "Remember to use \`root=/dev/ram0 init=/linuxrc' when starting kernel" >&2 |
ac085800 | 540 | echo "or you will have problems like init(xx) being child process of swapper(1)." >&2 |
d9179777 ER |
541 | return |
542 | fi | |
543 | ||
544 | if is_yes "`echo "$devpath" | awk '/^\/dev\/md/ { print "yes"; }'`"; then | |
bc0d6f2d | 545 | find_modules_softraid "$devpath" |
d9179777 ER |
546 | return |
547 | fi | |
548 | ||
549 | if is_yes "$(echo "$devpath" | awk '/^\/dev\/(sd|scsi)/ { print "yes"; }')" ; then | |
7c38b114 | 550 | find_modules_scsi |
d9179777 ER |
551 | return |
552 | fi | |
553 | ||
554 | if is_yes "`echo "$devpath" | awk '/^\/dev\/(hd|ide)/ { print "yes"; }'`" ; then | |
bc0d6f2d | 555 | find_modules_ide "$devpath" |
d9179777 ER |
556 | return |
557 | fi | |
558 | ||
559 | if [[ "$devpath" == /dev/mapper/* ]] && is_yes "$USE_MULTIPATH"; then | |
560 | : | |
561 | fi | |
562 | ||
563 | if is_yes "$(echo "$devpath" | awk '/^\/dev\/mapper\/(sil|hpt37x|hpt45x|isw|lsi|nvidia|pdc|sil|via|dos)_/ { print "yes"; }')"; then | |
bc0d6f2d ER |
564 | # dmraid nodes taken from: `dmraid -l` output |
565 | if [ ! -x /usr/sbin/dmraid ]; then | |
566 | die "root on dmraid but /usr/sbin/dmraid not found." | |
567 | fi | |
568 | ||
569 | # XXX dmraid could say to us that /dev/dm-3 consists from /dev/sda, /dev/sdb | |
570 | ||
571 | # get blockdev itself (without partition) | |
572 | local node blockdev | |
573 | blockdev=${devpath%%[0-9]*} | |
574 | blockdev=${blockdev#/dev/mapper/} | |
575 | for node in $(dmraid -r -cdevpath,raidname |awk -F, -vv="$blockdev" '{if ($2 == v) print $1}'); do | |
a8007847 | 576 | find_modules_for_device $node |
f155a80b | 577 | dmraid_devices="$dmraid_devices $node" |
bc0d6f2d ER |
578 | done |
579 | ||
580 | # XXX probably should detect | |
581 | findmodule "dm-mirror" | |
d9179777 ER |
582 | return |
583 | fi | |
bc0d6f2d | 584 | |
d9179777 | 585 | if is_yes "`echo "$devpath" | awk '/\/dev\/rd\// { print "yes"; }'`" ; then |
7c38b114 | 586 | findmodule "DAC960" |
d9179777 ER |
587 | return |
588 | fi | |
589 | ||
590 | if is_yes "`echo "$devpath" | awk '/\/dev\/ida\// { print "yes"; }'`" ; then | |
7c38b114 | 591 | findmodule "cpqarray" |
d9179777 ER |
592 | return |
593 | fi | |
594 | ||
595 | if is_yes "`echo "$devpath" | awk '/\/dev\/cciss\// { print "yes"; }'`" ; then | |
7c38b114 | 596 | findmodule "cciss" |
d9179777 ER |
597 | return |
598 | fi | |
599 | ||
600 | if is_yes "`echo "$devpath" | awk '/\/dev\/ataraid\// { print "yes"; }'`"; then | |
ac085800 | 601 | find_modules_ide |
7c38b114 | 602 | findmodule "ataraid" |
d4a15d5f | 603 | ataraidmodules="`awk '/ataraid_hostadapter/ && ! /^[\t ]*#/ { print $3; }' $modulefile`" |
7c38b114 AF |
604 | if -n "$ataraidmodules" ; then |
605 | # FIXME: think about modules compiled in kernel | |
00eaa938 | 606 | die "ataraid_hostadapter alias not defined in $modulefile! Please set it and run $PROGRAM again." |
7c38b114 AF |
607 | fi |
608 | for n in $ataraidmodules; do | |
609 | findmodule "$n" | |
610 | done | |
d9179777 ER |
611 | return |
612 | fi | |
613 | ||
7c38b114 | 614 | # check to see if we need to set up a loopback filesystem |
d9179777 | 615 | if is_yes "`echo "$devpath" | awk -F/ '{print($3);}' | awk '/loop/ { print "yes"; }'`" ; then |
00eaa938 | 616 | die "Sorry, root on loop device isn't supported." |
7c38b114 AF |
617 | # TODO: rewrite for bsp and make nfs ready |
618 | if [ ! -x /sbin/losetup ]; then | |
00eaa938 | 619 | die "losetup is missing" |
7c38b114 | 620 | fi |
bc0d6f2d | 621 | key="^# $(echo $devpath | awk -F/ '{print($3);}' | tr '[a-z]' '[A-Z]'):" |
7c38b114 | 622 | if ! is_yes "`awk '/'$key'/ { print( "yes"); }' $fstab`" ; then |
bc0d6f2d | 623 | die "The root filesystem is on a $devpath, but there is no magic entry in $fstab for this device. Consult the geninitrd man page for more information" |
7c38b114 AF |
624 | fi |
625 | ||
626 | line="`awk '/'$key'/ { print $0; }' $fstab`" | |
627 | loopDev="$(echo $line | awk '{print $3}')" | |
628 | loopFs="$(echo $line | awk '{print $4}')" | |
629 | loopFile="$(echo $line | awk '{print $5}')" | |
630 | ||
631 | BASICMODULES="$BASICMODULES -loop" | |
632 | findmodule "-$loopFs" | |
633 | BASICMODULES="$BASICMODULES -${loopFs}" | |
d9179777 ER |
634 | return |
635 | fi | |
636 | ||
637 | if _check_lvm "$devpath"; then | |
bc0d6f2d | 638 | node="$devpath" |
f6536797 | 639 | |
9f2d32ed | 640 | if [ ! -f /sbin/initrd-lvm -o ! -x /sbin/lvdisplay -o ! -x /sbin/pvdisplay ] ; then |
00eaa938 | 641 | die "root on LVM but /sbin/initrd-lvm, /sbin/lvdisplay and /sbin/pvdisplay not found. Please install lvm(2) and lvm(2)-initrd package and rerun $PROGRAM." |
7c38b114 | 642 | fi |
ac085800 ER |
643 | if [ -z "$LVMTOOLSVERSION" ] ; then |
644 | LVMTOOLSVERSION=$(/sbin/initrd-lvm vgchange --version 2>/dev/null|head -n 1|awk '{gsub("vgchange: Logical Volume Manager ",NIL); gsub("LVM version: ",NIL); gsub(/\..*/,NIL); print $1}') | |
645 | if [ -z "$LVMTOOLSVERSION" ] ; then | |
00eaa938 | 646 | die "Can't determine LVM tools version. Please set LVMTOOLSVERSION and rerun $PROGRAM." |
ac085800 | 647 | fi |
77bcfc68 | 648 | fi |
decd277c | 649 | if [ -z "$PVDEVICES" ] ; then |
f6536797 | 650 | VGVOLUME=$(/sbin/lvdisplay -c "$node" 2> /dev/null | awk -F":" ' { print $2 } ') |
d2dc16e9 | 651 | PVDEVICES=$(/sbin/pvdisplay -c 2>/dev/null | awk -F":" -v vg="$VGVOLUME" ' BEGIN { devices="" } { if ($2 == vg) { devices = devices " " $1 } } END { print devices } ') |
decd277c | 652 | fi |
7c38b114 AF |
653 | if [ -n "$PVDEVICES" ] ; then |
654 | for device in $PVDEVICES; do | |
a8007847 | 655 | find_modules_for_device $device |
7c38b114 AF |
656 | done |
657 | else | |
00eaa938 | 658 | die "I wasn't able to find PV (via lvdisplay and pvdisplay). You can try to set PVDEVICES in /etc/sysconfig/geninitrd." |
7c38b114 | 659 | fi |
e0c502bb | 660 | if [ "$LVMTOOLSVERSION" = "2" ]; then |
ac085800 | 661 | findmodule "-dm-mod" |
e0c502bb | 662 | elif [ "$LVMTOOLSVERSION" = "1" ]; then |
ac085800 ER |
663 | findmodule "-lvm" |
664 | findmodule "-lvm-mod" | |
93d781d1 | 665 | else |
00eaa938 | 666 | die "LVM version $LVMTOOLSVERSION is not supported yet." |
93d781d1 | 667 | fi |
94769f11 | 668 | debug "LVM $LVMTOOLSVERSION enabled" |
7c38b114 | 669 | uselvm="yes" |
d9179777 | 670 | return |
7c38b114 AF |
671 | fi |
672 | } | |
673 | ||
9ed6e1db AM |
674 | firmware_install_module_pre() { |
675 | module="$1" | |
676 | linuxrc="$2" | |
677 | firmware_files="$3" | |
678 | ||
94769f11 | 679 | debug "Adding Firmwares ($firmware_files) to initrd for module $module" |
034fdd5d ER |
680 | inst_d /proc |
681 | inst_d /sys | |
9ed6e1db AM |
682 | # firmware not yet installed |
683 | if [ ! -f "$MNTIMAGE/lib/firmware/firmware.sh" ]; then | |
034fdd5d | 684 | inst_d /lib/firmware |
9ed6e1db AM |
685 | cat << 'EOF' >> "$MNTIMAGE/lib/firmware/firmware.sh" |
686 | #!/bin/sh -e | |
8639f99a AM |
687 | echo 1 > /sys$DEVPATH/loading |
688 | cat "/lib/firmware/$FIRMWARE" > /sys$DEVPATH/data | |
689 | echo 0 > /sys$DEVPATH/loading | |
690 | exit 0 | |
9ed6e1db | 691 | EOF |
94769f11 | 692 | chmod 755 "$MNTIMAGE/lib/firmware/firmware.sh" |
9ed6e1db AM |
693 | fi |
694 | ||
695 | for firmware in $firmware_files; do | |
dcc1b914 | 696 | inst /lib/firmware/$firmware /lib/firmware/$firmware |
9ed6e1db AM |
697 | done |
698 | ||
699 | echo "mount -t proc none /proc" >> "$linuxrc" | |
700 | echo "mount -t sysfs none /sys" >> "$linuxrc" | |
0867ab75 | 701 | echo "echo -n "/lib/firmware/firmware.sh" > /proc/sys/kernel/hotplug" >> "$linuxrc" |
9ed6e1db AM |
702 | } |
703 | ||
704 | firmware_install_module_post() { | |
705 | module="$1" | |
706 | linuxrc="$2" | |
707 | firmware_files="$3" | |
708 | echo "umount /sys" >> "$linuxrc" | |
709 | echo "umount /proc" >> "$linuxrc" | |
710 | } | |
711 | ||
2a5bcca9 AM |
712 | modules_install() { |
713 | modules="$1" | |
714 | ||
715 | for mod in $modules; do | |
034fdd5d ER |
716 | MODULEDIR=$(dirname "$mod") |
717 | inst_d "/lib/modules/$kernel/$MODULEDIR" | |
dd87738f | 718 | cp -a "/lib/modules/$kernel/$mod" "$MNTIMAGE/lib/modules/$kernel/$mod" |
ac085800 | 719 | gunzip "$MNTIMAGE/lib/modules/$kernel/$mod" 2> /dev/null |
2a5bcca9 AM |
720 | done |
721 | } | |
722 | ||
723 | modules_add_linuxrc() { | |
724 | modules="$1" | |
725 | linuxrc="$2" | |
ac085800 | 726 | |
2a5bcca9 | 727 | for mod in $modules; do |
87d21026 | 728 | MODULE2="`dirname "$mod"`" |
ac085800 ER |
729 | NAME2=`basename "$mod" .gz` |
730 | MODULE2=$MODULE2/$NAME2 | |
731 | module="`echo $mod | awk -F/ '{ $0=$NF } /'$modext'.*$/ { gsub(/'$modext'.*/, NIL, $0); } { print $0; }'`" | |
732 | options="`awk '{ if($1 == "options" && $2 == "'${module}'") { for(i=3;i<=NF;i++) printf("%s ",$i); }}' "$modulefile"`" | |
ffa1b198 | 733 | |
9ed6e1db AM |
734 | generic_module=$(echo "${module}" | awk ' { gsub("-", "_", $0) } { print $0; } ') |
735 | sleep_var="$(eval echo \$MODULE_${generic_module}_USLEEP)" | |
94769f11 | 736 | firmware_var="$(eval echo \$MODULE_${generic_module}_FIRMWARE)" |
2a5bcca9 | 737 | |
ac085800 ER |
738 | if [ -n "$verbose" ]; then |
739 | echo -n "Loading module [$module] " | |
740 | if [ -n "$options" ] ; then | |
741 | echo -n "with options [$options]" | |
742 | else | |
743 | echo -n "without options" | |
744 | fi | |
8e598759 | 745 | if [ -n "$sleep_var" ]; then |
ba0552ce | 746 | echo " and $sleep_var usleep." |
8e598759 AM |
747 | else |
748 | echo "." | |
749 | fi | |
ac085800 ER |
750 | fi |
751 | ||
9ed6e1db AM |
752 | if [ -n "$firmware_var" ]; then |
753 | firmware_install_module_pre "$module" "$linuxrc" "$firmware_var" | |
754 | fi | |
ac085800 | 755 | echo "$insmod /lib/modules/$kernel/$MODULE2 $options" >> "$linuxrc" |
8e598759 AM |
756 | if [ -n "${sleep_var}" ]; then |
757 | echo "usleep $sleep_var" >> "$linuxrc" | |
758 | fi | |
9ed6e1db AM |
759 | if [ -n "$firmware_var" ]; then |
760 | firmware_install_module_post "$module" "$linuxrc" "$firmware_var" | |
761 | fi | |
2a5bcca9 AM |
762 | done |
763 | } | |
764 | ||
5dc785c7 | 765 | if [ -r /etc/sysconfig/geninitrd ] ; then |
766 | . /etc/sysconfig/geninitrd | |
767 | fi | |
768 | ||
5b71959c AM |
769 | if [ -r /etc/sysconfig/bootsplash ] ; then |
770 | . /etc/sysconfig/bootsplash | |
771 | fi | |
772 | ||
e4b07ddc | 773 | if [ -r /etc/sysconfig/fbsplash ] ; then |
774 | . /etc/sysconfig/fbsplash | |
775 | fi | |
776 | ||
ac085800 | 777 | if [ ! -x /bin/initrd-busybox ] ; then |
00eaa938 | 778 | die "/bin/initrd-busybox is missing!" |
5dc785c7 | 779 | fi |
901afd79 | 780 | |
7591cd37 ER |
781 | # backwards compatible |
782 | if [ "$USE_SUSPEND2" ] ; then | |
783 | USE_TUXONICE=$USE_SUSPEND2 | |
784 | echo >&2 "USE_SUSPEND2 is deprecated, use USE_TUXONICE now instead." | |
785 | fi | |
786 | ||
bb529f94 | 787 | while [ $# -gt 0 ]; do |
413878f8 | 788 | case $1 in |
6bd433bc AF |
789 | --fstab=*) |
790 | fstab="`echo $1 | awk -F= '{print $2;}'`" | |
791 | ;; | |
792 | --fstab) | |
793 | fstab="$2" | |
794 | shift | |
413878f8 | 795 | ;; |
cd670d83 AF |
796 | --modules-conf=*) |
797 | modulefile="`echo $1 | awk -F= '{print $2;}'`" | |
798 | ;; | |
57188d60 | 799 | --modules-conf) |
cd670d83 AF |
800 | modulefile="$2" |
801 | shift | |
802 | ;; | |
6bd433bc AF |
803 | --use-raidstart|--with-raidstart) |
804 | USERAIDSTART="yes" | |
805 | ;; | |
806 | --without-raidstart) | |
807 | USERAIDSTART="no" | |
808 | ;; | |
57227e0a AF |
809 | --use-insmod-static|--with-insmod-static) |
810 | USEINSMODSTATIC="yes" | |
811 | ;; | |
812 | --without-insmod-static) | |
813 | USEINSMODSTATIC="no" | |
814 | ;; | |
ba5d09f0 | 815 | --with-bootsplash) |
816 | BOOT_SPLASH="yes" | |
817 | ;; | |
5b71959c AM |
818 | --without-bootsplash) |
819 | BOOT_SPLASH="no" | |
820 | ;; | |
ba5d09f0 | 821 | --with-fbsplash) |
822 | FB_SPLASH="yes" | |
823 | ;; | |
e4b07ddc | 824 | --without-fbsplash) |
825 | FB_SPLASH="no" | |
826 | ;; | |
ba5d09f0 | 827 | --with-suspend) |
828 | USE_SUSPEND="yes" | |
829 | ;; | |
4ef98747 | 830 | --without-suspend) |
ba5d09f0 | 831 | USE_SUSPEND="no" |
832 | ;; | |
1cd2aabd ER |
833 | --with-suspend2 | --with-tuxonice) |
834 | USE_TUXONICE="yes" | |
22b0c9f4 | 835 | ;; |
1cd2aabd ER |
836 | --without-suspend2 | --without-tuxonice) |
837 | USE_TUXONICE="no" | |
2c52f208 | 838 | ;; |
e0c502bb AM |
839 | --lvmtoolsversion=|--lvmversion=) |
840 | LVMTOOLSVERSION="`echo $1 | awk -F= '{print $2;}'`" | |
77bcfc68 | 841 | ;; |
e0c502bb AM |
842 | --lvmtoolsversion|--lvmversion) |
843 | LVMTOOLSVERSION="$2" | |
77bcfc68 AF |
844 | shift |
845 | ;; | |
1606e343 AM |
846 | --without-udev) |
847 | USE_UDEV= | |
848 | ;; | |
d7d5530e ER |
849 | --with-udev) |
850 | USE_UDEV="yes" | |
851 | ;; | |
882472ae ER |
852 | --without-dmraid) |
853 | USE_DMRAID= | |
854 | ;; | |
2cc3ae8b ER |
855 | --without-multipath) |
856 | USE_MULTPATH= | |
857 | ;; | |
6bd433bc AF |
858 | --with=*) |
859 | BASICMODULES="$BASICMODULES `echo $1 | awk -F= '{print $2;}'`" | |
860 | ;; | |
861 | --with) | |
862 | BASICMODULES="$BASICMODULES $2" | |
863 | shift | |
413878f8 | 864 | ;; |
bb529f94 | 865 | --version) |
9e1ceabe | 866 | echo "$PROGRAM: version $VERSION" |
413878f8 | 867 | exit 0 |
868 | ;; | |
bb529f94 | 869 | -v) |
413878f8 | 870 | verbose=-v |
871 | ;; | |
bb529f94 | 872 | --nocompress) |
413878f8 | 873 | COMPRESS="no" |
874 | ;; | |
bb529f94 | 875 | --ifneeded) |
413878f8 | 876 | ifneeded=1 |
877 | ;; | |
bb529f94 | 878 | -f) |
413878f8 | 879 | force=1 |
880 | ;; | |
6bd433bc AF |
881 | --preload=*) |
882 | PREMODS="$PREMODS `echo $1 | awk -F= '{print $2;}'`" | |
883 | ;; | |
884 | --preload) | |
72623c13 | 885 | PREMODS="$PREMODS $2" |
6bd433bc | 886 | shift |
413878f8 | 887 | ;; |
2ad94d8a | 888 | --fs=*) |
94769f11 | 889 | echo >&2 "Warning: --fs option is obsoleted. Use --initrdfs instead" |
2ad94d8a AF |
890 | INITRDFS="`echo $1 | awk -F= '{print $2;}'`" |
891 | ;; | |
2ad94d8a | 892 | --fs) |
94769f11 | 893 | echo >&2 "Warning: --fs option is obsoleted. Use --initrdfs instead" |
2ad94d8a AF |
894 | INITRDFS="$2" |
895 | shift | |
cd670d83 | 896 | ;; |
6bd433bc AF |
897 | --initrdfs=*) |
898 | INITRDFS="`echo $1 | awk -F= '{print $2;}'`" | |
899 | ;; | |
fd2dc249 | 900 | --initrdfs) |
2ad94d8a | 901 | INITRDFS="$2" |
413878f8 | 902 | shift |
903 | ;; | |
bb529f94 | 904 | --image-version) |
413878f8 | 905 | img_vers=yes |
906 | ;; | |
4f4e832d AM |
907 | --ide-only-root) |
908 | ide_only_root="yes" | |
909 | ;; | |
bb529f94 | 910 | *) |
413878f8 | 911 | if [ -z "$target" ]; then |
912 | target="$1" | |
913 | elif [ -z "$kernel" ]; then | |
914 | kernel="$1" | |
915 | else | |
916 | usage | |
917 | fi | |
918 | ;; | |
919 | esac | |
920 | ||
921 | shift | |
bb529f94 JK |
922 | done |
923 | ||
06ac05d6 | 924 | if [ -z "$target" -o -z "$kernel" ]; then |
413878f8 | 925 | usage |
06ac05d6 AF |
926 | fi |
927 | ||
0868f49f | 928 | pack_version="`echo "$kernel"|awk -F. '{print sprintf("%03d%03d",$1,$2)}'`" |
64497ebb | 929 | pack_version_long="`echo "$kernel"|awk -F. '{print sprintf("%03d%03d%03d",$1,$2,$3)}'`" |
0868f49f | 930 | |
48413b7f AM |
931 | if [ "x" = "x$INITRDFS" ] ; then |
932 | if [ "x" = "x$FS" ] ; then | |
933 | # default value | |
8d6cdf87 | 934 | if [ "$pack_version" -ge "002005" ] ; then |
935 | INITRDFS="initramfs" | |
936 | else | |
ac085800 | 937 | INITRDFS="rom" |
8d6cdf87 | 938 | fi |
48413b7f | 939 | else |
94769f11 | 940 | echo >&2 "Warning: FS configuration options is obsoleted. Use INITRDFS instead" |
48413b7f AM |
941 | INITRDFS="$FS" |
942 | fi | |
943 | fi | |
944 | ||
1606e343 | 945 | if [ "$pack_version" -lt "002006" ] ; then |
882472ae ER |
946 | USE_UDEV= |
947 | USE_DMRAID= | |
1606e343 | 948 | fi |
ac085800 | 949 | |
0868f49f AF |
950 | if [ "$pack_version" -ge "002005" ] ; then |
951 | modext=".ko" | |
0b6536f5 | 952 | insmod="insmod" |
0868f49f AF |
953 | fi |
954 | ||
57227e0a AF |
955 | if is_yes "$USEINSMODSTATIC" ; then |
956 | insmod="insmod.static" | |
b2e62ae1 | 957 | INSMOD="/sbin/insmod.static" |
f7c18703 AM |
958 | if [ "$pack_version" -lt "002005" -a -f /sbin/insmod.static.modutils ] ; then |
959 | INSMOD="/sbin/insmod.static.modutils" | |
b2e62ae1 AF |
960 | fi |
961 | if [ ! -f "$INSMOD" ] ; then | |
00eaa938 | 962 | die "insmod.static requested but /sbin/insmod.static not found!" |
b2e62ae1 | 963 | fi |
57227e0a AF |
964 | fi |
965 | ||
2ad94d8a | 966 | case "$INITRDFS" in |
8b1e4ac7 | 967 | ext2) |
f5d71bb2 | 968 | if [ ! -x /sbin/mke2fs ]; then |
00eaa938 | 969 | die "/sbin/mke2fs is missing" |
8b1e4ac7 AF |
970 | fi |
971 | ;; | |
972 | rom) | |
973 | if [ ! -x /sbin/genromfs ]; then | |
00eaa938 | 974 | die "/sbin/genromfs is missing" |
8b1e4ac7 AF |
975 | fi |
976 | ;; | |
977 | cram) | |
978 | if [ ! -x /sbin/mkcramfs ]; then | |
00eaa938 | 979 | die "/sbin/mkcramfs is missing" |
8b1e4ac7 | 980 | fi |
c31050f3 | 981 | ;; |
48413b7f AM |
982 | initramfs) |
983 | if [ ! -x /bin/cpio ]; then | |
00eaa938 | 984 | die "/bin/cpio is missing" |
48413b7f AM |
985 | fi |
986 | if [ ! -x /usr/bin/find ]; then | |
00eaa938 | 987 | die "/usr/bin/find is missing" |
48413b7f AM |
988 | fi |
989 | ;; | |
8b1e4ac7 | 990 | *) |
00eaa938 | 991 | die "Filesystem $INITRDFS on initrd is not supported" |
8b1e4ac7 AF |
992 | ;; |
993 | esac | |
bb529f94 | 994 | |
bb529f94 | 995 | if [ -n "$img_vers" ]; then |
413878f8 | 996 | target="$target-$kernel" |
bb529f94 JK |
997 | fi |
998 | ||
35164381 | 999 | if [ -z "$force" -a -f "$target" ]; then |
00eaa938 | 1000 | die "$target already exists." |
bb529f94 JK |
1001 | fi |
1002 | ||
35164381 | 1003 | if [ ! -d "/lib/modules/$kernel" ]; then |
00eaa938 | 1004 | die "/lib/modules/$kernel is not a directory." |
bb529f94 JK |
1005 | fi |
1006 | ||
1cd2aabd ER |
1007 | if is_yes "$USE_SUSPEND" && is_yes "$USE_TUXONICE"; then |
1008 | die "Tuxonice shouldn't be used in parallel with mainline suspend!." | |
22b0c9f4 AM |
1009 | fi |
1010 | ||
e4b07ddc | 1011 | if is_yes "$FB_SPLASH"; then |
1012 | if is_yes "$BOOT_SPLASH"; then | |
00eaa938 | 1013 | die "You can't use both bootsplash and fbsplash! Please choose one." |
e4b07ddc | 1014 | elif [ "$INITRDFS" != "initramfs" ]; then |
00eaa938 | 1015 | die "FB_SPLASH works only if INITRDFS is initramfs!." |
e4b07ddc | 1016 | fi |
1017 | fi | |
1018 | ||
48762878 | 1019 | if [ ! -f /proc/mounts ]; then |
94769f11 | 1020 | echo >&2 "WARNING: /proc filesystem not mounted, may cause wrong results or failure." |
48762878 | 1021 | fi |
f121024f AM |
1022 | |
1023 | if [ "$pack_version" -lt "002005" ]; then | |
1024 | modulefile=/etc/modules.conf | |
1025 | if [ ! -f "$modulefile" -a -f /etc/conf.modules ]; then | |
1026 | modulefile=/etc/conf.modules | |
1027 | fi | |
1028 | else | |
1029 | modulefile=/etc/modprobe.conf | |
1030 | fi | |
ac085800 | 1031 | |
bb529f94 | 1032 | for n in $PREMODS; do |
35164381 | 1033 | findmodule "$n" |
bb529f94 JK |
1034 | done |
1035 | ||
7c38b114 AF |
1036 | # allow forcing loading SCSI and/or IDE modules |
1037 | if is_yes "$ADDSCSI" ; then | |
1038 | find_modules_scsi | |
bb529f94 JK |
1039 | fi |
1040 | ||
7c38b114 AF |
1041 | if is_yes "$ADDIDE" ; then |
1042 | find_modules_ide | |
cd670d83 AF |
1043 | fi |
1044 | ||
1cea325b ER |
1045 | find_root "$fstab" || exit |
1046 | debug "Using $rootdev as device for rootfs" | |
1047 | ||
a8007847 ER |
1048 | find_modules_for_device "$rootdev" |
1049 | [ -n "$rootdev_add" ] && find_modules_for_device "$rootdev_add" | |
cd670d83 | 1050 | |
7c38b114 | 1051 | findmodule "-$rootFs" |
bb529f94 | 1052 | |
c31050f3 | 1053 | for n in $BASICMODULES; do |
7d2fc5eb | 1054 | findmodule "$n" |
bb529f94 JK |
1055 | done |
1056 | ||
1cd2aabd | 1057 | if is_yes "$USE_TUXONICE"; then |
335cd101 JR |
1058 | findmodule "-lzf" |
1059 | fi | |
1060 | ||
e4b07ddc | 1061 | if is_yes "$FB_SPLASH"; then |
1062 | findmodule "-evdev" | |
1063 | fi | |
2cc3ae8b ER |
1064 | |
1065 | if is_yes "$USE_MULTIPATH"; then | |
1066 | findmodule "dm-multipath" | |
1067 | findmodule "dm-round-robin" | |
1068 | findmodule "dm-emc" | |
1069 | fi | |
1070 | ||
bb529f94 | 1071 | if [ -n "$ifneeded" -a -z "$MODULES" ]; then |
94769f11 | 1072 | debug "No modules are needed -- not building initrd image." |
7d2fc5eb | 1073 | exit 0 |
bb529f94 | 1074 | fi |
94769f11 | 1075 | debug "Using modules: $MODULES" |
bb529f94 | 1076 | |
35164381 SZ |
1077 | MNTIMAGE="`mktemp -d /tmp/initrd.XXXXXX`" |
1078 | IMAGE="`mktemp -u /tmp/initrd.img-XXXXXX`" | |
1079 | MNTPOINT="`mktemp -d /tmp/initrd.mnt-XXXXXX`" | |
1080 | RCFILE="$MNTIMAGE/linuxrc" | |
bb529f94 | 1081 | |
35164381 | 1082 | if [ -f "$MNTIMAGE" ]; then |
00eaa938 | 1083 | die "$MNTIMAGE already exists. Remove it and try again" |
bb529f94 JK |
1084 | fi |
1085 | ||
35164381 | 1086 | if [ -f "$IMAGE" ]; then |
00eaa938 | 1087 | die "$IMAGE already exists. Remove it and try again" |
bb529f94 JK |
1088 | fi |
1089 | ||
73edc0c1 | 1090 | mkdir -p "$MNTPOINT" |
bb529f94 | 1091 | # We don't need this directory, so let's save space |
35164381 | 1092 | rm -rf "$MNTPOINT"/lost+found |
bb529f94 | 1093 | |
034fdd5d ER |
1094 | inst_d /{lib,bin,etc,dev,loopfs,var} |
1095 | ||
2a5bcca9 | 1096 | modules_install "$MODULES" |
bb529f94 JK |
1097 | |
1098 | # mknod'ing the devices instead of copying them works both with and | |
1099 | # without devfs... | |
35164381 | 1100 | mknod "$MNTIMAGE/dev/console" c 5 1 |
eb6e37ff MM |
1101 | mknod "$MNTIMAGE/dev/null" c 1 3 |
1102 | mknod "$MNTIMAGE/dev/zero" c 1 5 | |
034fdd5d | 1103 | inst_d /dev/pts /dev/shm |
bb529f94 | 1104 | |
84670990 | 1105 | s="$RCFILE" |
566ad08b | 1106 | ln -s /linuxrc $MNTIMAGE/init |
ef66f232 | 1107 | |
dcc1b914 | 1108 | inst /bin/initrd-busybox /bin/initrd-busybox |
dab92b1d ER |
1109 | ln -s initrd-busybox $MNTIMAGE/bin/sh |
1110 | ln -s initrd-busybox $MNTIMAGE/bin/busybox # for older busyboxes who had /bin/busybox as EXEPATH | |
ef66f232 | 1111 | |
1775ba37 ER |
1112 | if is_yes "$USEINSMODSTATIC"; then |
1113 | inst "$INSMOD" /bin/insmod.static | |
57227e0a AF |
1114 | fi |
1115 | ||
f116bd42 | 1116 | cat > "$s" <<'EOF' |
84670990 | 1117 | #! /bin/sh |
f116bd42 | 1118 | mount -t proc none /proc |
c3e2550c AM |
1119 | if [ "$(awk ' /debuginitrd/ { print "yes"; } ' /proc/cmdline)" = "yes" ]; then |
1120 | export DEBUG=yes | |
1121 | set -x | |
1122 | fi | |
1123 | umount /proc | |
84670990 MM |
1124 | EOF |
1125 | chmod 755 "$s" | |
c31050f3 | 1126 | |
2a5bcca9 | 1127 | modules_add_linuxrc "$MODULES" "$s" |
fd2dc249 | 1128 | |
4e9eb79c | 1129 | # TODO: rewrite for busybox |
fd2dc249 AF |
1130 | #if [ -n "$loopDev" ]; then |
1131 | # if [ ! -d /initrd ]; then | |
1132 | # mkdir /initrd | |
1133 | # fi | |
1134 | # | |
1135 | # cp -a "$loopDev" "$MNTIMAGE/dev" | |
738c05d8 | 1136 | # cp -a "$rootdev" "$MNTIMAGE/dev" |
fd2dc249 AF |
1137 | # echo "echo Mounting device containing loopback root filesystem" >> "$RCFILE" |
1138 | # echo "mount -t $loopFs $loopDev /loopfs" >> "$RCFILE" | |
738c05d8 ER |
1139 | # echo "echo Setting up loopback device $rootdev" >> $RCFILE |
1140 | # echo "losetup $rootdev /loopfs$loopFile" >> "$RCFILE" | |
fd2dc249 | 1141 | #fi |
bb529f94 | 1142 | |
22b0c9f4 AM |
1143 | initrd_gen_suspend() { |
1144 | if [ ! -x /usr/sbin/resume ]; then | |
00eaa938 | 1145 | die "/usr/sbin/resume is missing!" |
22b0c9f4 | 1146 | fi |
034fdd5d | 1147 | inst_d /etc /dev |
22b0c9f4 | 1148 | resume_dev="$(awk '/^resume device =/ { print $4 } ' /etc/suspend.conf)" |
1775ba37 ER |
1149 | inst /dev/snapshot /dev |
1150 | inst $resume_dev /dev | |
1151 | inst /etc/suspend.conf /etc/suspend.conf | |
dcc1b914 | 1152 | inst /usr/sbin/resume /bin/resume |
22b0c9f4 AM |
1153 | echo "resume" >> "$s" |
1154 | } | |
1155 | ||
1cd2aabd | 1156 | initrd_gen_tuxonice() { |
034fdd5d | 1157 | inst_d /sys /proc |
5a61a17c | 1158 | cat << 'EOF' >> "$s" |
2b1a3707 | 1159 | mount -t proc none /proc |
050198fa | 1160 | mount -t sysfs none /sys |
5a61a17c | 1161 | if [ "$(awk ' /resume2=/ { print "yes"; } ' /proc/cmdline)" = "yes" ]; then |
2b1a3707 | 1162 | EOF |
2b1a3707 | 1163 | cat << EOF >> "$s" |
050198fa | 1164 | [ -e /proc/suspend2/do_resume ] && echo > /proc/suspend2/do_resume |
1165 | [ -e /sys/power/suspend2/do_resume ] && echo > /sys/power/suspend2/do_resume | |
5b26c57b | 1166 | [ -e /sys/power/tuxonice/do_resume ] && echo > /sys/power/tuxonice/do_resume |
2b1a3707 | 1167 | fi |
050198fa | 1168 | umount /sys |
2b1a3707 AM |
1169 | umount /proc |
1170 | EOF | |
2df2e995 | 1171 | } |
2c52f208 | 1172 | |
7915c8b1 | 1173 | # generate code to mount /dev on tmpfs and create initial nodes |
4ca8a6c5 ER |
1174 | # can be called multiple times. /dev is cleaned up (umounted) automatically at |
1175 | # the end of script. | |
b4d9d384 | 1176 | initrd_gen_tmpfs_dev() { |
dd856379 AG |
1177 | if [ "$INITRDFS" = "initramfs" ]; then |
1178 | # initramfs is read-write filesystem, no need for tmpfs | |
1179 | return | |
1180 | fi | |
7915c8b1 ER |
1181 | |
1182 | # we already generated tmpfs code; return | |
1183 | if is_yes "$tmpfs_dev"; then | |
1184 | return | |
1185 | fi | |
1186 | ||
b4d9d384 | 1187 | tmpfs_dev=yes |
9299682f ER |
1188 | |
1189 | busybox_applet mount mknod mkdir | |
d07b92a4 | 1190 | cat >> "$s" <<-EOF |
b4d9d384 ER |
1191 | : 'Creating /dev' |
1192 | mount -o mode=0755 -t tmpfs none /dev | |
1193 | mknod /dev/console c 5 1 | |
1194 | mknod /dev/null c 1 3 | |
1195 | mknod /dev/zero c 1 5 | |
1196 | mkdir /dev/pts | |
1197 | mkdir /dev/shm | |
1198 | EOF | |
1199 | } | |
1200 | ||
1606e343 | 1201 | initrd_gen_udev() { |
94769f11 | 1202 | debug "Setting up udev..." |
034fdd5d | 1203 | inst_d /sbin /proc /etc/udev /sys |
ac085800 | 1204 | |
9299682f | 1205 | if [ ! -x /sbin/initrd-udevd ]; then |
00eaa938 | 1206 | die "/sbin/initrd-udevd not present" |
9299682f ER |
1207 | fi |
1208 | ||
1775ba37 ER |
1209 | inst /sbin/initrd-udevd /sbin/udevd |
1210 | inst /etc/udev/udev.conf /etc/udev/udev.conf | |
1606e343 | 1211 | |
1606e343 | 1212 | if is_yes "$USE_UDEV"; then |
d07b92a4 | 1213 | initrd_gen_tmpfs_dev |
e4b07ddc | 1214 | cat >> "$s" <<- 'EOF' |
1215 | mount -t proc none /proc | |
1216 | mount -t sysfs none /sys | |
1217 | : 'Starting udev' | |
fdc8f895 | 1218 | /sbin/udevd --daemon |
7915c8b1 | 1219 | EOF |
e4b07ddc | 1220 | if is_yes "$PROBESTATICMODS"; then |
1775ba37 ER |
1221 | inst /sbin/initrd-udevtrigger /sbin/udevtrigger |
1222 | inst /sbin/initrd-udevsettle /sbin/udevsettle | |
7915c8b1 | 1223 | cat >> "$s" <<-'EOF' |
e4b07ddc | 1224 | /sbin/udevtrigger |
1225 | /sbin/udevsettle | |
7915c8b1 | 1226 | EOF |
e4b07ddc | 1227 | fi |
9299682f ER |
1228 | |
1229 | busybox_applet killall | |
1230 | cat >> "$s" <<-'EOF' | |
93f2f7c3 | 1231 | killall udevd |
e4b07ddc | 1232 | umount /proc |
1233 | umount /sys | |
7915c8b1 | 1234 | EOF |
1606e343 AM |
1235 | fi |
1236 | } | |
1237 | ||
2cc3ae8b | 1238 | initrd_gen_multipath() { |
2cc3ae8b ER |
1239 | inst_d /proc /sys /sbin /lib/udev |
1240 | # inst /sbin/multipathd /sbin | |
1241 | inst /sbin/kpartx /sbin | |
1242 | # inst /bin/mountpoint /bin | |
1243 | # inst /sbin/devmap_name /sbin | |
1244 | inst /sbin/multipath /sbin | |
1245 | # for udev callouts | |
1246 | inst /sbin/scsi_id /lib/udev | |
1247 | for a in /sbin/mpath*; do | |
1248 | inst $a /sbin | |
1249 | done | |
1250 | ||
1251 | if [ -d /lib64 ]; then | |
1252 | lib=/lib64 | |
1253 | else | |
1254 | lib=/lib | |
1255 | fi | |
1256 | inst_d $lib | |
1257 | inst /lib64/ld-linux-x86-64.so.2 $lib | |
1258 | for a in $(ldd /sbin/kpartx /sbin/multipath | awk '{print $3}'); do | |
1259 | inst $a $lib | |
1260 | done | |
1261 | for a in $(ldd $MNTIMAGE$lib/lib* | awk '{print $3}'); do | |
1262 | inst $a $lib | |
1263 | done | |
1264 | ||
1265 | cat <<-'EOF' >> "$s" | |
1266 | mount -t proc none /proc | |
1267 | mount -t sysfs none /sys | |
1268 | EOF | |
1269 | ||
1270 | initrd_gen_tmpfs_dev | |
1271 | initrd_gen_devices | |
1272 | ||
1273 | cat <<-'EOF' >> "$s" | |
1274 | /sbin/multipath -v 0 | |
1275 | ||
1276 | for a in /dev/mapper/*; do | |
1277 | [ $a = /dev/mapper/control ] && continue | |
1278 | kpartx -a $a | |
1279 | done | |
1280 | rm -f /dev/sd?* # XXX adjust lvm.conf instead. however at initrd creation time | |
1281 | sh | |
1282 | ||
1283 | umount /sys | |
1284 | umount /proc | |
1285 | EOF | |
1286 | } | |
1287 | ||
882472ae | 1288 | initrd_gen_dmraid() { |
ac085800 | 1289 | if [ ! -x /sbin/dmraid-initrd ] ; then |
00eaa938 | 1290 | die "/sbin/dmraid-initrd is missing missing!" |
ac085800 ER |
1291 | fi |
1292 | ||
661cd523 | 1293 | # always make /dev on tmpfs |
7915c8b1 | 1294 | initrd_gen_tmpfs_dev |
ac085800 | 1295 | |
034fdd5d | 1296 | inst_d /sbin /sys |
1775ba37 | 1297 | inst /sbin/dmraid-initrd /sbin/dmraid |
9bb6d02a | 1298 | cat <<-EOF >> "$s" |
882472ae ER |
1299 | mount -t proc none /proc |
1300 | mount -t sysfs none /sys | |
2ffb1734 ER |
1301 | EOF |
1302 | ||
1303 | initrd_gen_devices | |
1304 | ||
1305 | cat <<-EOF >> "$s" | |
882472ae ER |
1306 | # 2 secs was enough for my system to initialize. but really this is udev issue? |
1307 | usleep 2000000 | |
e5d02b56 | 1308 | : 'Activating Device-Mapper RAID(s)' |
882472ae ER |
1309 | /sbin/dmraid -ay -i |
1310 | umount /sys | |
1311 | umount /proc | |
1312 | EOF | |
1313 | } | |
1314 | ||
8bd582f1 ER |
1315 | # Generates /dev nodes based on /proc/partitions information. |
1316 | # Needs /proc mounted. | |
1317 | # Can be called multiple times. | |
2ffb1734 | 1318 | initrd_gen_devices() { |
8bd582f1 ER |
1319 | if is_yes "$proc_partitions"; then |
1320 | return | |
1321 | fi | |
1322 | proc_partitions=yes | |
1323 | ||
06ae4e5a | 1324 | cat <<-'EOF' >> "$s" |
2ffb1734 ER |
1325 | : 'Making device nodes' |
1326 | # ignore first two lines, header, empty line and process rest | |
1327 | cat /proc/partitions | (read b; read b; while read major minor blocks dev rest; do | |
06ae4e5a ER |
1328 | node=/dev/$dev |
1329 | mkdir -p ${node%/*} | |
1330 | mknod $node b $major $minor | |
2ffb1734 ER |
1331 | done |
1332 | ) | |
1333 | EOF | |
1334 | } | |
1335 | ||
2df2e995 | 1336 | initrd_gen_softraid() { |
94769f11 | 1337 | debug "Setting up mdadm..." |
ac085800 | 1338 | |
00eaa938 ER |
1339 | if [ ! -x /sbin/mdadm -o ! -x /sbin/initrd-mdassemble ]; then |
1340 | die "/sbin/mdadm or /sbin/initrd-mdassemble is missing!" | |
d3fa6ec7 | 1341 | fi |
994eb509 | 1342 | |
dcc1b914 | 1343 | inst /sbin/initrd-mdassemble /bin/mdassemble |
6cca3165 | 1344 | |
4e9eb79c | 1345 | # LVM on RAID case |
6cca3165 AM |
1346 | dev_list_extra=$(awk '/^DEVICE / { for (i=2; i<=NF; i++) { printf "%s ", $i; }; } ' /etc/mdadm.conf) |
1347 | for ex_dev in $dev_list_extra; do | |
1348 | echo "DEVICE $ex_dev" >> "$MNTIMAGE/etc/mdadm.conf" | |
1349 | done | |
ac085800 | 1350 | do_md0=1 |
4e9eb79c | 1351 | for nr in `seq 1 $rootdev_nr`; do |
ac085800 ER |
1352 | eval cr_rootdev="\$rootdev${nr}" |
1353 | eval cr_dev_list="\$dev_list${nr}" | |
94769f11 | 1354 | debug echo "Setting up array ($cr_rootdev = $cr_dev_list)" |
ac085800 ER |
1355 | |
1356 | [ "$cr_rootdev" = "/dev/md0" ] && do_md0=0 | |
1357 | ||
1358 | echo "DEVICE $cr_dev_list" >> "$MNTIMAGE/etc/mdadm.conf" | |
1359 | cr_dev_list_md="$(echo "$cr_dev_list" | xargs | awk ' { gsub(/ +/,",",$0); print $0; }')" | |
a46f8bda | 1360 | cr_md_conf=$(/sbin/mdadm --detail --brief --config=/etc/mdadm.conf $cr_rootdev | awk ' { gsub(/spares=[0-9]+/, "", $0); print $0; }') |
ac085800 ER |
1361 | if [ -n "$cr_md_conf" ]; then |
1362 | echo "$cr_md_conf" >> "$MNTIMAGE/etc/mdadm.conf" | |
1363 | else | |
1364 | echo "ARRAY $cr_rootdev devices=$cr_dev_list_md" >> "$MNTIMAGE/etc/mdadm.conf" | |
1365 | fi | |
1366 | ||
1367 | for f in $cr_dev_list $cr_rootdev $dev_list_extra; do | |
1368 | # mkdir in case of devfs name | |
034fdd5d | 1369 | inst_d $(dirname $f) |
ac085800 | 1370 | [ -e "$MNTIMAGE/$f" ] && continue |
ac085800 | 1371 | # this works fine with and without devfs |
1775ba37 | 1372 | inst $f $f |
ac085800 | 1373 | done |
ef66f232 | 1374 | done |
4e9eb79c | 1375 | |
6cca3165 | 1376 | echo "mdassemble" >> "$s" |
33d24e12 | 1377 | |
4e9eb79c AM |
1378 | # needed to determine md-version |
1379 | if [ "$do_md0" -eq 1 ] ; then | |
1380 | mknod $MNTIMAGE/dev/md0 b 9 0 | |
1381 | fi | |
2df2e995 | 1382 | } |
2968c9dd | 1383 | |
2df2e995 | 1384 | initrd_gen_nfs() { |
5a61a17c | 1385 | # use root=/dev/ram0 init=/linuxrc when starting kernel or you will |
51447ab3 | 1386 | # have problems like init(XX) being child process of swapper(1). |
94769f11 | 1387 | debug "Adding rootfs on NFS support to initrd (dhcp)" |
7fc1e5bd | 1388 | mknod "$MNTIMAGE/dev/urandom" c 1 9 |
5c4cec75 | 1389 | mkdir "$MNTIMAGE/newroot" |
7d400dbe | 1390 | mkdir "$MNTIMAGE/proc" |
5c4cec75 AM |
1391 | echo "ifconfig lo 127.0.0.1 up" >> "$s" |
1392 | echo "route add -net 127.0.0.0 netmask 255.0.0.0 lo" >> "$s" | |
1393 | echo "ifconfig eth0 0.0.0.0 up" >> "$s" | |
ac085800 | 1394 | echo "udhcpc -i eth0 -f -q -s /bin/setdhcp" >> "$s" |
5a61a17c | 1395 | cat << 'EOF' > "$MNTIMAGE/bin/setdhcp" |
5c4cec75 | 1396 | #!/bin/sh |
5a61a17c ER |
1397 | [ "$1" != "bound" ] && exit |
1398 | [ -n "$broadcast" ] && BROADCAST="broadcast $broadcast" | |
1399 | [ -n "$subnet" ] && NETMASK="netmask $subnet" | |
5a61a17c | 1400 | ifconfig $interface $ip $BROADCAST $NETMASK up |
5a61a17c | 1401 | if [ -n "$router" ]; then |
ac085800 | 1402 | for r in $router; do |
ac085800 | 1403 | route add default gw $r dev $interface |
ac085800 | 1404 | done |
5c4cec75 | 1405 | fi |
7d400dbe ER |
1406 | |
1407 | mount -t proc none /proc | |
5a61a17c ER |
1408 | for o in $(cat /proc/cmdline); do |
1409 | case $o in | |
7d400dbe | 1410 | nfsroot=*) |
5a61a17c | 1411 | rootpath=${o#nfsroot=} |
7d400dbe ER |
1412 | ;; |
1413 | esac | |
1414 | done | |
1415 | umount /proc | |
1416 | ||
5a61a17c | 1417 | if [ -n "$rootpath" ]; then |
ac085800 | 1418 | mount -n -t nfs -o ro,nolock,posix,tcp,wsize=8192,rsize=8192 $rootpath /newroot |
5c4cec75 | 1419 | else |
ac085800 ER |
1420 | echo "Missing rootpath in what DHCP server sent to us. Failing..." |
1421 | echo "All seen variables are listed below:" | |
1422 | set | |
5c4cec75 AM |
1423 | fi |
1424 | EOF | |
1425 | chmod 755 "$MNTIMAGE/bin/setdhcp" | |
1426 | echo "cd /newroot" >> "$s" | |
c52ba2fe | 1427 | echo "pivot_root . initrd" >> "$s" |
d4a8e40e | 1428 | echo "[ -x /sbin/chroot ] && exec /sbin/chroot . /sbin/init -i < dev/console > dev/console 2>&1" >> "$s" |
c52ba2fe | 1429 | echo "exec /usr/sbin/chroot . /sbin/init -i < dev/console > dev/console 2>&1" >> "$s" |
2df2e995 | 1430 | } |
6fe19d5b | 1431 | |
2df2e995 | 1432 | initrd_gen_lvm() { |
94769f11 | 1433 | debug "Adding LVM support to initrd" |
1775ba37 | 1434 | inst /sbin/initrd-lvm /bin/lvm |
034fdd5d | 1435 | inst_d /etc /tmp /proc /newroot |
e8d178ff ER |
1436 | |
1437 | # always make /dev on tmpfs for LVM2 | |
7915c8b1 | 1438 | if [ "$LVMTOOLSVERSION" = "2" ]; then |
d07b92a4 | 1439 | initrd_gen_tmpfs_dev |
e8d178ff ER |
1440 | fi |
1441 | ||
b4d9d384 | 1442 | if ! is_yes "$tmpfs_dev"; then |
034fdd5d | 1443 | inst_d /dev/mapper |
afaefcb5 | 1444 | mknod $MNTIMAGE/dev/mapper/control c 10 63 |
b007399c | 1445 | for device in $PVDEVICES; do |
13b29c8f ER |
1446 | # if LVM on RAID then device might be copied already in gen_softraid |
1447 | [ -e "$MNTIMAGE/dev/$(basename $device)" ] && continue | |
1775ba37 | 1448 | inst $device /dev |
b007399c | 1449 | done |
afaefcb5 | 1450 | fi |
84670990 | 1451 | echo "mount -t proc none /proc" >> "$s" |
b78e6497 | 1452 | echo "mount -t tmpfs none /tmp" >> "$s" |
e0c502bb | 1453 | if [ "$LVMTOOLSVERSION" = "1" ] ; then |
cff3058d | 1454 | echo "lvm vgscan -T" >> "$s" |
90b5b05a | 1455 | echo "lvm vgchange -T -a y $VGVOLUME" >> "$s" |
4e1e40bd | 1456 | echo "umount /tmp" >> "$s" |
ac085800 | 1457 | # fail to umount |
ac085800 | 1458 | echo "umount /proc" >> "$s" |
cff3058d | 1459 | else |
ac085800 ER |
1460 | echo "cat /etc/lvm.conf > /tmp/lvm.conf" >> "$s" |
1461 | echo "global {" > "$MNTIMAGE/etc/lvm.conf" | |
f34c76a3 AM |
1462 | echo " locking_type = 0" >> "$MNTIMAGE/etc/lvm.conf" |
1463 | echo " locking_dir = \"/tmp\"" >> "$MNTIMAGE/etc/lvm.conf" | |
1464 | echo "}" >> "$MNTIMAGE/etc/lvm.conf" | |
ac085800 | 1465 | echo "devices {" >> "$MNTIMAGE/etc/lvm.conf" |
8fb0a4d2 | 1466 | echo " sysfs_scan=0" >> "$MNTIMAGE/etc/lvm.conf" |
f34c76a3 | 1467 | if is_yes "$raidfound"; then |
ac085800 | 1468 | echo " md_component_detection = 1" >> "$MNTIMAGE/etc/lvm.conf" |
f34c76a3 | 1469 | fi |
2cc3ae8b | 1470 | if [ "$dmraid_devices" ] || is_yes "$USE_MULTIPATH"; then |
3938fd10 | 1471 | echo ' types = [ "device-mapper", 254 ]' >> "$MNTIMAGE/etc/lvm.conf" |
2cc3ae8b ER |
1472 | fi |
1473 | if [ "$dmraid_devices" ]; then | |
bc0d6f2d | 1474 | # ignore /dev/sd* devices that dmraid consists |
2cc3ae8b ER |
1475 | echo ' filter = [' >> "$MNTIMAGE/etc/lvm.conf" |
1476 | for dev in $dmraid_devices; do | |
1477 | debug "dmraid: ignoring $dev from LVM" | |
1478 | printf ' "r|^%s.*|",\n' $dev | |
1479 | done >> "$MNTIMAGE/etc/lvm.conf" | |
1480 | echo ']' >> "$MNTIMAGE/etc/lvm.conf" | |
3938fd10 | 1481 | fi |
f34c76a3 AM |
1482 | lvm dumpconfig | awk '/filter=/' >> "$MNTIMAGE/etc/lvm.conf" |
1483 | echo "}" >> "$MNTIMAGE/etc/lvm.conf" | |
be2f3ecc | 1484 | |
2ffb1734 ER |
1485 | initrd_gen_devices |
1486 | ||
c79b26a6 | 1487 | cat <<-EOF >> "$s" |
e8d178ff | 1488 | |
dd87738f ER |
1489 | # disable noise from lvm accessing devices that aren't ready. |
1490 | printk=\$(cat /proc/sys/kernel/printk) | |
e8d178ff | 1491 | echo 0 > /proc/sys/kernel/printk |
dd87738f | 1492 | |
2cc3ae8b | 1493 | export LVM_SYSTEM_DIR=/tmp |
dd87738f | 1494 | : 'Scanning for Volume Groups' |
2cc3ae8b | 1495 | lvm vgscan --mknodes --ignorelockingfailure 2>/dev/null |
e8d178ff | 1496 | |
c79b26a6 | 1497 | : 'Activating Volume Groups' |
2cc3ae8b | 1498 | lvm vgchange --ignorelockingfailure -a y $VGVOLUME 2>/dev/null |
be2f3ecc | 1499 | |
dd87738f ER |
1500 | echo "\$printk" > /proc/sys/kernel/printk |
1501 | ||
91ed0242 | 1502 | # Find out major/minor |
2cc3ae8b | 1503 | majmin="\$(lvm lvdisplay --ignorelockingfailure -c $rootdev 2>/dev/null)" |
c79b26a6 ER |
1504 | majmin="\${majmin#*/}" |
1505 | majmin="\${majmin#*:*:*:*:*:*:*:*:*:*:*:*}" | |
1506 | major="\${majmin%:*}" | |
1507 | minor="\${majmin#*:}" | |
91ed0242 | 1508 | # Pass it to kernel |
c79b26a6 ER |
1509 | val=\$((256 * \$major + \$minor)) |
1510 | echo \$val > /proc/sys/kernel/real-root-dev | |
1511 | umount /tmp | |
1512 | umount /proc | |
1513 | EOF | |
cff3058d | 1514 | fi |
2df2e995 AM |
1515 | } |
1516 | ||
2b1a3707 | 1517 | initrd_gen_procdata() { |
94769f11 | 1518 | debug "Adding rootfs finding based on root= option support." |
034fdd5d | 1519 | inst_d /proc |
5a61a17c | 1520 | cat << 'EOF' >> "$s" |
2b1a3707 | 1521 | mount -t proc none /proc |
5a61a17c ER |
1522 | root="$(busybox awk ' /root=\/dev\// { gsub(/.*root=\/dev\//,NIL,$0); gsub(/ .*/,NIL,$0); print $0; } ' /proc/cmdline)" |
1523 | if [ -n "$root" ]; then | |
ac085800 ER |
1524 | rootnr="$(busybox awk -v root="$root" ' { if ($4 == root) { print 256*$1+$2; } } ' /proc/partitions)" |
1525 | if [ -n "$rootnr" ]; then | |
1526 | echo "$rootnr" > /proc/sys/kernel/real-root-dev | |
1527 | fi | |
2b1a3707 | 1528 | fi |
9d949203 | 1529 | umount /proc |
2b1a3707 AM |
1530 | EOF |
1531 | } | |
1532 | ||
2df2e995 | 1533 | # main generation |
1606e343 AM |
1534 | |
1535 | if is_yes "$USE_UDEV"; then | |
1536 | initrd_gen_udev | |
1537 | fi | |
1538 | ||
2ce7656a | 1539 | if is_yes "$USE_SUSPEND"; then |
22b0c9f4 AM |
1540 | initrd_gen_suspend |
1541 | fi | |
1542 | ||
1cd2aabd ER |
1543 | if is_yes "$USE_TUXONICE"; then |
1544 | initrd_gen_tuxonice | |
2df2e995 AM |
1545 | fi |
1546 | ||
f155a80b | 1547 | if [ "$dmraid_devices" ]; then |
882472ae ER |
1548 | initrd_gen_dmraid |
1549 | fi | |
1550 | ||
2cc3ae8b ER |
1551 | if [ "$USE_MULTIPATH" ]; then |
1552 | initrd_gen_multipath | |
1553 | fi | |
1554 | ||
2df2e995 AM |
1555 | if is_yes "$usenfs" ; then |
1556 | initrd_gen_nfs | |
1775ba37 | 1557 | elif is_yes "$USERAIDSTART" && is_yes "$raidfound"; then |
2df2e995 | 1558 | initrd_gen_softraid |
1775ba37 | 1559 | if is_yes "$uselvm"; then |
2df2e995 | 1560 | initrd_gen_lvm |
bfea009a AM |
1561 | else |
1562 | initrd_gen_procdata | |
2df2e995 | 1563 | fi |
1775ba37 | 1564 | elif is_yes "$uselvm"; then |
2df2e995 | 1565 | initrd_gen_lvm |
2b1a3707 AM |
1566 | else |
1567 | initrd_gen_procdata | |
7c38b114 AF |
1568 | fi |
1569 | ||
737d5a0e | 1570 | # finally umount /dev if it was on tmpfs |
661cd523 ER |
1571 | if is_yes "$tmpfs_dev"; then |
1572 | cat <<-EOF >> "$s" | |
1573 | umount /dev | |
1574 | EOF | |
1575 | tmpfs_dev=no | |
1576 | fi | |
1577 | ||
5101a385 | 1578 | # additional devs always needed |
1775ba37 | 1579 | [ ! -e "$MNTIMAGE/$rootdev_add" ] && inst $rootdev_add /dev |
5101a385 | 1580 | |
f8f9e56d | 1581 | if [ "$INITRDFS" = "initramfs" ]; then |
034fdd5d | 1582 | inst_d /newroot |
1775ba37 | 1583 | [ ! -e "$MNTIMAGE/$rootdev" ] && inst $rootdev /dev |
e4b07ddc | 1584 | # Parsing root parameter |
81d53704 | 1585 | # We support passing root as hda3 /dev/hda3 0303 0x0303 and 303 |
e4b07ddc | 1586 | cat << 'EOF' >> "$s" |
e4b07ddc | 1587 | mount -t proc none /proc |
df391e6f | 1588 | |
1589 | CMDLINE="$(busybox cat /proc/cmdline)" | |
1590 | eval "$(busybox awk -v c="$CMDLINE" ' | |
1591 | BEGIN { | |
92ed99b6 | 1592 | num_pattern_short = "[0-9a-f][0-9a-f][0-9a-f]"; |
1593 | num_pattern = "[0-9a-f]" num_pattern_short; | |
df391e6f | 1594 | dev_pattern = "[hms][a-z][a-z]([0-9])+"; |
1595 | partition = "no_partition_found"; | |
1596 | min = -1; maj = -1; | |
1597 | ||
1598 | gsub(/.*root=/,NIL,c); | |
1599 | gsub(/ .*/,NIL,c); | |
1600 | ||
1601 | sub("^0x", "", c); | |
1602 | if (c ~ "^" num_pattern_short "$") sub("^", "0", c); | |
1603 | if (c ~ "^" num_pattern "$") { | |
92ed99b6 | 1604 | maj = sprintf("%s",substr(c,1,2)); |
1605 | min = sprintf("%s",substr(c,3)); | |
df391e6f | 1606 | } |
1607 | if (c ~ "^\/dev\/" dev_pattern "$") sub("^/dev/","", c); | |
1608 | if (c ~ "^" dev_pattern "$") partition = c; | |
1609 | } | |
1610 | ||
1611 | $4 ~ partition { maj = $1; min = $2; } | |
1612 | $1 ~ maj && $2 ~ min { partition = $4; } | |
1613 | ||
1614 | END { | |
92ed99b6 | 1615 | print sprintf("device=/dev/%s\nmaj=%s\nmin=%s", |
df391e6f | 1616 | partition, maj, min); |
1617 | } | |
1618 | ' /proc/partitions)" | |
e620b426 | 1619 | if [ "$device" != '/dev/no_partition_found' -a ! -b $device ]; then |
e4b07ddc | 1620 | mknod $device b $maj $min |
1621 | fi | |
1622 | EOF | |
92a4990b ER |
1623 | |
1624 | busybox_applet switch_root | |
e4b07ddc | 1625 | cat << EOF >> "$s" |
e620b426 AG |
1626 | if [ "\$device" = '/dev/no_partition_found' ] ; then |
1627 | device="$rootdev" | |
1628 | fi | |
1629 | ||
51dc11ca | 1630 | mount -t $rootFs -r \$device /newroot |
a020063b | 1631 | init="\$(busybox awk ' /init=\// { gsub(/.*init=/,NIL,\$0); gsub(/ .*/,NIL,\$0); print \$0; } ' /proc/cmdline )" |
1632 | if [ -z "\$init" -o ! -x "/newroot\$init" ]; then | |
1633 | init=/sbin/init | |
1634 | fi | |
e4b07ddc | 1635 | umount /proc |
a020063b | 1636 | exec switch_root /newroot \$init |
f1a5a1b0 | 1637 | |
1638 | echo "Error ! initramfs should not reach this place." | |
1639 | echo "It probably means you've got old version of busybox, with broken" | |
1640 | echo "initramfs support. Trying to boot anyway, but won't promise anything." | |
1641 | ||
1642 | exec chroot /newroot \$init | |
1643 | ||
1644 | echo "Failed to chroot !" | |
e4b07ddc | 1645 | EOF |
f8f9e56d AM |
1646 | # we need real file, not symlink |
1647 | rm -f $MNTIMAGE/init | |
1648 | cp -a $MNTIMAGE/linuxrc $MNTIMAGE/init | |
1649 | fi | |
1650 | ||
35164381 | 1651 | chmod +x "$RCFILE" |
bb529f94 | 1652 | |
35164381 | 1653 | (cd "$MNTIMAGE"; tar cf - .) | (cd "$MNTPOINT"; tar xf -) |
bb529f94 | 1654 | |
2ad94d8a | 1655 | case "$INITRDFS" in |
8b1e4ac7 | 1656 | ext2) |
94d430a8 | 1657 | IMAGESIZE=$(du -ks $MNTPOINT | awk '{print int(($1+1023+512)/1024)*1024}') |
94769f11 | 1658 | debug "ext2 image size: $IMAGESIZE ($MNTPOINT)" |
73edc0c1 | 1659 | if [ "$IMAGESIZE" -gt 4096 ]; then |
7758e45c | 1660 | echo >&2 "$PROGRAM: Your image size is larger than 4096, Be sure to boot kernel with ramdisk_size=$IMAGESIZE!" |
73edc0c1 ER |
1661 | fi |
1662 | ||
1663 | dd if=/dev/zero of="$IMAGE" bs=1k count="$IMAGESIZE" 2> /dev/null | |
1664 | mke2fs -q -F -b 1024 -m 0 "$IMAGE" 2>/dev/null 1>&2 | |
1665 | tune2fs -i 0 "$IMAGE" >/dev/null 2>&1 | |
1666 | ||
1667 | tmpmnt="`mktemp -d /tmp/initrd.mnte2-XXXXXX`" | |
1668 | mount -o loop -t ext2 "$IMAGE" "$tmpmnt" | |
1669 | ||
1670 | (cd "$MNTPOINT"; tar cf - .) | (cd "$tmpmnt"; tar xf -) | |
1671 | ||
35164381 | 1672 | umount "$IMAGE" |
8b1e4ac7 AF |
1673 | ;; |
1674 | rom) | |
1675 | genromfs -f "$IMAGE" -d "$MNTPOINT" -V "PLD initrd for kernel $kernel" | |
cdf1e7c9 | 1676 | IMAGESIZE=$(stat -c %s $IMAGE | awk '{print int((($1/1024)+1023)/1024)*1024}') |
a8b63949 ER |
1677 | debug "romfs image size: $IMAGESIZE ($IMAGE)" |
1678 | if [ "$IMAGESIZE" -gt 4096 ]; then | |
7758e45c | 1679 | echo >&2 "$PROGRAM: Your image size is larger than 4096, Be sure to boot kernel with ramdisk_size=$IMAGESIZE!" |
a8b63949 | 1680 | fi |
8b1e4ac7 AF |
1681 | ;; |
1682 | cram) | |
1683 | mkcramfs "$MNTPOINT" "$IMAGE" | |
8b1e4ac7 | 1684 | ;; |
48413b7f | 1685 | initramfs) |
26939e7a | 1686 | (cd $MNTPOINT ; find . | cpio --quiet -H newc -o > "$IMAGE") |
48413b7f | 1687 | ;; |
8b1e4ac7 | 1688 | *) |
7758e45c | 1689 | echo "Filesystem $INITRDFS not supported by $PROGRAM"; |
c31050f3 | 1690 | esac |
bb529f94 JK |
1691 | |
1692 | if is_yes "$COMPRESS" ; then | |
7d2fc5eb | 1693 | gzip -9 < "$IMAGE" > "$target" |
bb529f94 | 1694 | else |
7d2fc5eb | 1695 | cp -a "$IMAGE" "$target" |
bb529f94 | 1696 | fi |
5b71959c AM |
1697 | |
1698 | if is_yes "$BOOT_SPLASH"; then | |
1699 | if [ ! -x /bin/splash.bin ]; then | |
94769f11 | 1700 | echo >&2 "Failed to execute /bin/splash.bin. Is bootsplash package installed?" |
5b71959c | 1701 | elif [ -z "$THEME" ]; then |
94769f11 ER |
1702 | echo >&2 "Please configure your /etc/sysconfig/bootsplash first." |
1703 | echo >&2 "Generating bootsplashes skipped." | |
5b71959c | 1704 | else |
ac085800 ER |
1705 | if [ -n "$BOOT_SPLASH_RESOLUTIONS" ]; then |
1706 | for res in $BOOT_SPLASH_RESOLUTIONS; do | |
1707 | if [ -f "/etc/bootsplash/themes/$THEME/config/bootsplash-$res.cfg" ]; then | |
1708 | /bin/splash.bin -s -f "/etc/bootsplash/themes/$THEME/config/bootsplash-$res.cfg" >> "$target" && \ | |
94769f11 | 1709 | debug "Added $res $THEME theme to initrd." |
ac085800 | 1710 | else |
94769f11 | 1711 | echo >&2 "/etc/bootsplash/themes/$THEME/config/bootsplash-$res.cfg doesn't exist, skipped" |
ac085800 ER |
1712 | fi |
1713 | done | |
1714 | else | |
94769f11 ER |
1715 | echo >&2 "No BOOT_SPLASH_RESOLUTIONS specified in /etc/sysconfig/bootsplash." |
1716 | echo >&2 "Not adding bootsplash to initrd." | |
ac085800 | 1717 | fi |
5b71959c AM |
1718 | fi |
1719 | fi | |
1720 | ||
e4b07ddc | 1721 | if is_yes "$FB_SPLASH"; then |
1722 | if [ ! -x /usr/bin/splash_geninitramfs ]; then | |
1723 | echo >&2 "Failed to execute /usr/bin/splash_geninitramfs. Is splashutils package installed?" | |
1724 | elif [ -z "$SPLASH_THEME" ]; then | |
1725 | echo >&2 "Please configure your /etc/sysconfig/fbsplash first." | |
1726 | echo >&2 "Generating fbsplashes skipped." | |
1727 | else | |
1728 | if [ -n "$FB_SPLASH_RESOLUTIONS" ]; then | |
1729 | for res in $FB_SPLASH_RESOLUTIONS; do | |
1730 | if [ -f "/etc/splash/$SPLASH_THEME/$res.cfg" ]; then | |
1731 | /usr/bin/splash_geninitramfs -a $target -r $res $SPLASH_THEME && \ | |
1732 | debug "Added $res $SPLASH_THEME theme to initramfs." | |
1733 | else | |
1734 | echo >&2 "/etc/splash/$SPLASH_THEME/$res.cfg doesn't exist, skipped" | |
1735 | fi | |
1736 | done | |
1737 | else | |
1738 | echo >&2 "No FB_SPLASH_RESOLUTIONS specified in /etc/sysconfig/fbsplash." | |
1739 | echo >&2 "Not adding fbsplash to initramfs." | |
1740 | fi | |
1741 | fi | |
1742 | fi | |
1743 | ||
35164381 | 1744 | rm -rf "$MNTIMAGE" "$MNTPOINT" "$IMAGE" |
ac085800 ER |
1745 | |
1746 | # vim:ts=4:sw=4:noet:fdm=marker |