plymouth-populate-initrd: do not install label.so
[dracut/plouj.git] / dracut-gencmdline
blob269560a381209a144ade6775ed511ca588a244bf
1 #!/bin/bash --norc
3 # Copyright 2005-2009 Red Hat, Inc. All rights reserved.
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 # code taken from mkinitrd
20 #. /usr/libexec/initrd-functions
23 function error() {
24 local NONL=""
25 if [ "$1" == "-n" ]; then
26 NONL="-n"
27 shift
29 echo $NONL "$@" >&2
32 function vecho() {
33 return
34 local NONL=""
35 if [ "$1" == "-n" ]; then
36 NONL="-n"
37 shift
39 is_verbose && echo $NONL "$@"
42 # module dep finding and installation functions
43 moduledep() {
44 MPARGS=""
45 if [ "$1" == "--ignore-install" ]; then
46 MPARGS="$MPARGS --ignore-install"
47 shift
49 vecho -n "Looking for deps of module $1"
50 deps=""
51 deps=$(modprobe $MPARGS --set-version $kernel --show-depends $1 2>/dev/null| awk '/^insmod / { print gensub(".*/","","g",$2) }' | while read foo ; do [ "${foo%%.ko}" != "$1" ] && echo -n "${foo%%.ko} " ; done)
52 [ -n "$deps" ] && vecho ": $deps" || vecho
55 if [ $UID != 0 ]; then
56 error "$0 must be run as root."
57 exit 1
60 export MALLOC_PERTURB_=204
62 PATH=/sbin:/usr/sbin:/bin:/usr/bin:$PATH
63 export PATH
65 . /etc/rc.d/init.d/functions
67 # Set the umask. For iscsi, the initrd can contain plaintext
68 # password (chap secret), so only allow read by owner.
69 umask 077
71 VERSION=6.0.87
73 PROBE="yes"
74 MODULES=""
75 GRAPHICSMODS=""
76 PREMODS=""
77 DMRAIDS=""
78 ncryptodevs=0
79 ncryptoparts=0
80 ncryptolvs=0
81 ncryptoraids=0
82 root=""
83 scsi_wait_scan="no"
85 NET_LIST=""
86 LD_SO_CONF=/etc/ld.so.conf
87 LD_SO_CONF_D=/etc/ld.so.conf.d/
89 [ -e /etc/sysconfig/mkinitrd ] && . /etc/sysconfig/mkinitrd
91 CONFMODS="$MODULES"
92 MODULES=""
93 ARCH=$(uname -m | sed -e 's/s390x/s390/')
95 compress=1
96 allowmissing=""
97 target=""
98 kernel=""
99 force=""
100 img_vers=""
101 builtins=""
102 modulefile=/etc/modules.conf
103 [ "$ARCH" != "s390" ] && withusb=1
104 rc=0
105 nolvm=""
106 nodmraid=""
108 IMAGESIZE=8000
109 PRESCSIMODS=""
110 fstab="/etc/fstab"
112 vg_list=""
113 net_list="$NET_LIST"
115 usage () {
116 if [ "$1" == "-n" ]; then
117 cmd=echo
118 else
119 cmd=error
122 $cmd "usage: `basename $0` [--version] [--help] [-v] [-f]"
124 if [ "$1" == "-n" ]; then
125 exit 0
126 else
127 exit 1
132 qpushd() {
133 pushd "$1" >/dev/null 2>&1
136 qpopd() {
137 popd >/dev/null 2>&1
140 resolve_device_name() {
141 echo "$1"
142 # echo "resolve_device_name $1" 1>&2
145 freadlink() {
146 /usr/bin/readlink -f "$1"
149 finddevnoinsys() {
150 majmin="$1"
151 if [ -n "$majmin" ]; then
152 dev=$(for x in /sys/block/* ; do find $x/ -name dev ; done | while read device ; do \
153 echo "$majmin" | cmp -s $device && echo $device ; done)
154 if [ -n "$dev" ]; then
155 dev=${dev%%/dev}
156 dev=${dev%%/}
157 echo "$dev"
158 return 0
161 return 1
164 finddevicedriverinsys () {
165 if is_iscsi $PWD; then
166 handleiscsi "$PWD"
167 return
169 while [ "$PWD" != "/sys/devices" ]; do
170 deps=
171 if [ -f modalias ]; then
172 MODALIAS=$(cat modalias)
173 if [ "${MODALIAS::7}" == "scsi:t-" ]; then
174 scsi_wait_scan=yes
176 moduledep $MODALIAS
177 unset MODALIAS
180 cd ..
181 done
184 findstoragedriverinsys () {
185 local sysfs=$(freadlink "$1")
187 # if its a partition look at the device holding the partition
188 if [ -f "$sysfs/start" ]; then
189 sysfs=$(freadlink ${sysfs%/*})
192 if [[ ! "$sysfs" =~ '^/sys/.*block/.*$' ]]; then
193 #error "WARNING: $sysfs is a not a block sysfs path, skipping"
194 return
197 case " $handleddevices " in
198 *" $sysfs "*)
199 return ;;
200 *) handleddevices="$handleddevices $sysfs" ;;
201 esac
203 if [[ "$sysfs" =~ '^/sys/.*block/md[0-9]+$' ]]; then
204 local raid=${sysfs##*/}
205 vecho "Found MDRAID component $raid"
206 handleraid $raid
208 if [[ "$sysfs" =~ '^/sys/.*block/dm-[0-9]+$' ]]; then
209 vecho "Found DeviceMapper component ${sysfs##*/}"
210 handledm $(cat $sysfs/dev |cut -d : -f 1) $(cat $sysfs/dev |cut -d : -f 2)
213 for slave in $(ls -d "$sysfs"/slaves/* 2>/dev/null) ; do
214 findstoragedriverinsys "$slave"
215 done
217 if [ -L "$sysfs/device" ]; then
218 qpushd $(freadlink "$sysfs/device")
219 finddevicedriverinsys
220 qpopd
224 findstoragedriver () {
225 local device="$1"
227 if [ ! -b "$device" ]; then
228 #error "WARNING: $device is a not a block device, skipping"
229 return
232 local majmin=$(get_numeric_dev dec "$device")
233 local sysfs=$(finddevnoinsys "$majmin")
235 if [ -z "$sysfs" ]; then
236 #error "WARNING: $device major:minor $majmin not found, skipping"
237 return
240 vecho "Looking for driver for $device in $sysfs"
241 findstoragedriverinsys "$sysfs"
244 iscsi_get_rec_val() {
246 # The open-iscsi 742 release changed to using flat files in
247 # /var/lib/iscsi.
249 result=$(grep "^${2} = " "$1" | sed -e s'/.* = //')
252 iscsi_set_parameters() {
253 path=$1
254 vecho setting iscsi parameters
256 tmpfile=$(mktemp)
258 # Check once before getting explicit values, so we can output a decent
259 # error message.
260 /sbin/iscsiadm --show -m session -r $path > $tmpfile
261 if [ ! -s $tmpfile ]; then
262 echo Unable to find iscsi record for $path
263 exit 1
266 nit_name=$(grep "^InitiatorName=" /etc/iscsi/initiatorname.iscsi | \
267 sed -e "s/^InitiatorName=//")
269 iscsi_get_rec_val $tmpfile "node.name"
270 tgt_name=${result}
271 iscsi_get_rec_val $tmpfile "node.tpgt"
272 tpgt=${result}
273 # iscsistart wants node.conn[0].address / port
274 iscsi_get_rec_val $tmpfile 'node.conn\[0\].address'
275 tgt_ipaddr=${result}
276 iscsi_get_rec_val $tmpfile 'node.conn\[0\].port'
277 tgt_port=${result}
279 # Note: we get chap secrets (passwords) in plaintext, and also store
280 # them in the initrd.
282 iscsi_get_rec_val $tmpfile "node.session.auth.username"
283 chap=${result}
284 if [ -n "${chap}" -a "${chap}" != "<empty>" ]; then
285 chap="-u ${chap}"
286 iscsi_get_rec_val $tmpfile "node.session.auth.password"
287 chap_pw="-w ${result}"
288 else
289 chap=""
292 iscsi_get_rec_val $tmpfile "node.session.auth.username_in"
293 chap_in=${result}
294 if [ -n "${chap_in}" -a "${chap_in}" != "<empty>" ]; then
295 chap_in="-U ${chap_in}"
296 iscsi_get_rec_val $tmpfile "node.session.auth.password_in"
297 chap_in_pw="-W ${result}"
298 else
299 chap_in=""
302 rm $tmpfile
305 emit_iscsi () {
306 if [ -n "${iscsi_devs}" ]; then
307 for dev in ${iscsi_devs}; do
308 iscsi_set_parameters $dev
309 # recid is not really used, just use 0 for it
310 echo "/bin/iscsistart -t ${tgt_name} -i ${nit_name} \
311 -g ${tpgt} -a ${tgt_ipaddr} ${chap} ${chap_pw} \
312 ${chap_in} ${chap_in_pw}"
313 done
317 is_iscsi() {
318 path=$1
319 if echo $path | grep -q "/platform/host[0-9]*/session[0-9]*/target[0-9]*:[0-9]*:[0-9]*/[0-9]*:[0-9]*:[0-9]*:[0-9]*"; then
320 return 0
321 else
322 return 1
326 handledm() {
327 major=$1
328 minor=$2
329 while read dmstart dmend dmtype r0 r1 r2 r3 r4 r5 r6 r7 r8 r9 ; do
330 case "$dmtype" in
331 crypt)
332 # this device is encrypted; find the slave device and see
333 # whether the encryption is LUKS; if not, bail.
334 slavedev=$(finddevnoinsys $r3)
335 # get the basename, then s,!,/, in case it's a cciss device
336 slavedev=$(echo ${slavedev##*/} | tr '!' '/')
337 cryptsetup isLuks "/dev/$slavedev" 2>/dev/null || continue
338 find_base_dm_mods
339 dmname=$(dmsetup info -j $major -m $minor -c --noheadings -o name)
340 # do the device resolution dance to get /dev/mapper/foo
341 # since 'lvm lvs' doesn't like dm-X device nodes
342 if [[ "$slavedev" =~ ^dm- ]]; then
343 majmin=$(get_numeric_dev dec "/dev/$slavedev")
344 for dmdev in /dev/mapper/* ; do
345 dmnum=$(get_numeric_dev dev $dmdev)
346 if [ $dmnum = $majmin ]; then
347 slavedev=${dmdev#/dev/}
348 break
350 done
353 # determine if $slavedev is an LV
354 # if so, add the device to latecryptodevs
355 # if not, add the device to cryptodevs
356 local vg=$(lvshow /dev/$slavedev)
357 if [ -n "$vg" ]; then
358 eval cryptolv${ncryptolvs}='"'/dev/$slavedev $dmname'"'
359 let ncryptolvs++
360 elif grep -q "^$slavedev :" /proc/mdstat ; then
361 eval cryptoraid${ncryptoraids}='"'/dev/$slavedev $dmname'"'
362 let ncryptoraids++
363 else
364 eval cryptoparts${ncryptoparts}='"'/dev/$slavedev $dmname'"'
365 let ncryptoparts++
368 let ncryptodevs++
369 findstoragedriver "/dev/$slavedev"
371 esac
372 done << EOF
373 $(dmsetup table -j $major -m $minor 2>/dev/null)
375 local name=$(dmsetup info --noheadings -c -j $major -m $minor -o name)
376 local vg=$(lvshow "/dev/mapper/$name")
377 local raids=$(/sbin/dmraid -s -craidname 2>/dev/null | grep -vi "no raid disks")
378 if [ -n "$vg" ]; then
379 vg=`echo $vg` # strip whitespace
380 case " $vg_list " in
381 *" $vg "*) ;;
382 *) vg_list="$vg_list $vg"
383 [ -z "$nolvm" ] && find_base_dm_mods
385 esac
387 for raid in $raids ; do
388 if [ "$raid" == "$name" ]; then
389 case " $DMRAIDS " in
390 *" $raid "*) ;;
391 *) DMRAIDS="$DMRAIDS $raid"
392 [ -z "$nodmraid" ] && find_base_dm_mods
394 esac
395 break
397 done
400 handleiscsi() {
401 vecho "Found iscsi component $1"
403 # We call iscsi_set_parameters once here to figure out what network to
404 # use (it sets tgt_ipaddr), and once again to emit iscsi values,
405 # not very efficient.
406 iscsi_set_parameters $1
407 iscsi_devs="$iscsi_devs $1"
408 netdev=$(/sbin/ip route get to $tgt_ipaddr | \
409 sed 's|.*dev \(.*\).*|\1|g' | awk '{ print $1; exit }')
410 addnetdev $netdev
413 handleraid() {
414 local start=0
416 if [ -n "$noraid" -o ! -f /proc/mdstat ]; then
417 return 0
420 levels=$(awk "/^$1[ ]*:/ { print\$4 }" /proc/mdstat)
422 for level in $levels ; do
423 case $level in
424 linear)
425 start=1
427 multipath)
428 start=1
430 raid[01] | raid10)
431 start=1
433 raid[456])
434 start=1
437 error "raid level $level (in /proc/mdstat) not recognized"
439 esac
440 done
441 if [ "$start" = 1 ]; then
442 raiddevices="$raiddevices $1"
444 return $start
447 lvshow() {
448 lvm lvs --ignorelockingfailure --noheadings -o vg_name \
449 $1 2>/dev/null | egrep -v '^ *(WARNING:|Volume Groups with)'
452 vgdisplay() {
453 lvm vgdisplay --ignorelockingfailure -v $1 2>/dev/null |
454 sed -n 's/PV Name//p'
457 dmmods_found="n"
458 find_base_dm_mods()
460 [ "$dmmods_found" == "n" ] || return
461 dmmods_found="y"
464 savedargs=$*
465 while [ $# -gt 0 ]; do
466 case $1 in
467 --fstab*)
468 if [ "$1" != "${1##--fstab=}" ]; then
469 fstab=${1##--fstab=}
470 else
471 fstab=$2
472 shift
477 -v|--verbose)
478 set_verbose true
480 --net-dev*)
481 if [ "$1" != "${1##--net-dev=}" ]; then
482 net_list="$net_list ${1##--net-dev=}"
483 else
484 net_list="$net_list $2"
485 shift
488 --rootdev*)
489 if [ "$1" != "${1##--rootdev=}" ]; then
490 rootdev="${1##--rootdev=}"
491 else
492 rootdev="$2"
493 shift
496 --thawdev*)
497 if [ "$1" != "${1##--thawdev=}" ]; then
498 thawdev="${1##--thawdev=}"
499 else
500 thawdev="$2"
501 shift
504 --rootfs*)
505 if [ "$1" != "${1##--rootfs=}" ]; then
506 rootfs="${1##--rootfs=}"
507 else
508 rootfs="$2"
509 shift
512 --rootopts*)
513 if [ "$1" != "${1##--rootopts=}" ]; then
514 rootopts="${1##--rootopts=}"
515 else
516 rootopts="$2"
517 shift
520 --root*)
521 if [ "$1" != "${1##--root=}" ]; then
522 root="${1##--root=}"
523 else
524 root="$2"
525 shift
528 --loopdev*)
529 if [ "$1" != "${1##--loopdev=}" ]; then
530 loopdev="${1##--loopdev=}"
531 else
532 loopdev="$2"
533 shift
536 --loopfs*)
537 if [ "$1" != "${1##--loopfs=}" ]; then
538 loopfs="${1##--loopfs=}"
539 else
540 loopfs="$2"
541 shift
544 --loopopts*)
545 if [ "$1" != "${1##--loopopts=}" ]; then
546 loopopts="${1##--loopopts=}"
547 else
548 loopopts="$2"
549 shift
552 --looppath*)
553 if [ "$1" != "${1##--looppath=}" ]; then
554 looppath="${1##--looppath=}"
555 else
556 looppath="$2"
557 shift
560 --help)
561 usage -n
564 if [ -z "$target" ]; then
565 target=$1
566 elif [ -z "$kernel" ]; then
567 kernel=$1
568 else
569 usage
572 esac
574 shift
575 done
577 [ -z "$rootfs" ] && rootfs=$(awk '{ if ($1 !~ /^[ \t]*#/ && $2 == "/") { print $3; }}' $fstab)
578 [ -z "$rootopts" ] && rootopts=$(awk '{ if ($1 !~ /^[ \t]*#/ && $2 == "/") { print $4; }}' $fstab)
579 [ -z "$rootopts" ] && rootopts="defaults"
582 [ -z "$rootdev" ] && rootdev=$(awk '/^[ \t]*[^#]/ { if ($2 == "/") { print $1; }}' $fstab)
583 # check if it's nfsroot
584 physdev=""
585 if [ "$rootfs" == "nfs" ]; then
586 if [ "x$net_list" == "x" ]; then
587 handlenfs $rootdev
589 else
590 # check if it's root by label
591 rdev=$rootdev
592 if [[ "$rdev" =~ ^(UUID=|LABEL=) ]]; then
593 rdev=$(resolve_device_name "$rdev")
595 rootopts=$(echo $rootopts | sed -e 's/^r[ow],//' -e 's/,_netdev//' -e 's/_netdev//' -e 's/,r[ow],$//' -e 's/,r[ow],/,/' -e 's/^r[ow]$/defaults/' -e 's/$/,ro/')
596 findstoragedriver "$rdev"
599 # find the first swap dev which would get used for swsusp
600 [ -z "$thawdev" ] && thawdev=$(awk '/^[ \t]*[^#]/ { if ($3 == "swap") { print $1; exit }}' $fstab)
601 swsuspdev="$thawdev"
602 if [ -n "$swsuspdev" ]; then
603 if [[ "$swsuspdev" =~ ^(UUID=|LABEL=) ]]; then
604 swsuspdev=$(resolve_device_name "$swsuspdev")
606 findstoragedriver "$swsuspdev"
610 cemit()
612 cat
615 emit()
617 NONL=""
618 if [ "$1" == "-n" ]; then
619 NONL="-n"
620 shift
622 echo $NONL "$@"
625 emitdmraids()
627 if [ -z "$nodmraid" -a -n "$DMRAIDS" ]; then
628 for raid in $DMRAIDS; do
629 echo -n "rd_DM_UUID=$raid "
630 done
635 # HACK: module loading + device creation isn't necessarily synchronous...
636 # this will make sure that we have all of our devices before trying
637 # things like RAID or LVM
638 emitdmraids
640 emitcrypto()
642 local luksuuid=$(grep "^$2 " /etc/crypttab 2>/dev/null| awk '{ print $2 }')
643 if [ -z "$luksuuid" ]; then
644 luksuuid="$2"
646 echo -n "rd_LUKS_UUID=$luksuuid "
649 for cryptdev in ${!cryptopart@} ; do
650 emitcrypto `eval echo '$'$cryptdev`
651 done
653 if [ -n "$raiddevices" ]; then
654 for dev in $raiddevices; do
655 echo -n "rd_MD_UUID=${dev} "
656 done
659 for cryptdev in ${!cryptoraid@} ; do
660 emitcrypto `eval echo '$'$cryptdev`
661 done
663 if [ -z "$nolvm" -a -n "$vg_list" ]; then
664 for vg in $vg_list; do
665 echo -n "rd_LVM_VG=$vg "
666 done
669 for cryptdev in ${!cryptolv@} ; do
670 emitcrypto `eval echo '$'$cryptdev`
671 done
673 # output local keyboard/18n settings
674 . /etc/sysconfig/keyboard
675 . /etc/sysconfig/i18n
677 for i in KEYTABLE SYSFONT SYSFONTACM UNIMAP LANG; do
678 val=$(eval echo \$$i)
679 [[ $val ]] && echo -n "$i=$val "
680 done
682 if [ -n "$KEYBOARDTYPE" -a "$KEYBOARDTYPE" != "pc" ]; then
683 echo -n "KEYBOARDTYPE=$KEYBOARDTYPE "
686 if [ -n "$rootdev" ]; then
687 echo -n "root=$rootdev "
690 if [ -L /usr/share/plymouth/themes/default.plymouth ]; then
691 theme=$(basename \
692 $(dirname \
693 $(readlink -f \
694 /usr/share/plymouth/themes/default.plymouth)))
695 [ -n "$theme" ] && echo -n "rd_plytheme=$theme "
698 echo
699 # vim:ts=8:sw=4:sts=4:et