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