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