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
25 if [ "$1" == "-n" ]; then
35 if [ "$1" == "-n" ]; then
39 is_verbose
&& echo $NONL "$@"
42 # module dep finding and installation functions
45 if [ "$1" == "--ignore-install" ]; then
46 MPARGS
="$MPARGS --ignore-install"
49 vecho
-n "Looking for deps of module $1"
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."
60 export MALLOC_PERTURB_
=204
62 PATH
=/sbin
:/usr
/sbin
:/bin
:/usr
/bin
:$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.
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
93 ARCH
=$
(uname
-m |
sed -e 's/s390x/s390/')
102 modulefile
=/etc
/modules.conf
103 [ "$ARCH" != "s390" ] && withusb
=1
116 if [ "$1" == "-n" ]; then
122 $cmd "usage: `basename $0` [--version] [--help] [-v] [-f]"
124 if [ "$1" == "-n" ]; then
133 pushd "$1" >/dev
/null
2>&1
140 resolve_device_name
() {
142 # echo "resolve_device_name $1" 1>&2
146 /usr
/bin
/readlink
-f "$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
164 finddevicedriverinsys
() {
165 if is_iscsi
$PWD; then
169 while [ "$PWD" != "/sys/devices" ]; do
171 if [ -f modalias
]; then
172 MODALIAS
=$
(cat modalias
)
173 if [ "${MODALIAS::7}" == "scsi:t-" ]; then
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"
197 case " $handleddevices " in
200 *) handleddevices
="$handleddevices $sysfs" ;;
203 if [[ "$sysfs" =~
'^/sys/.*block/md[0-9]+$' ]]; then
204 local raid
=${sysfs##*/}
205 vecho
"Found MDRAID component $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"
217 if [ -L "$sysfs/device" ]; then
218 qpushd $
(freadlink
"$sysfs/device")
219 finddevicedriverinsys
224 findstoragedriver
() {
227 if [ ! -b "$device" ]; then
228 #error "WARNING: $device is a not a block device, skipping"
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"
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
249 result
=$
(grep "^${2} = " "$1" |
sed -e s
'/.* = //')
252 iscsi_set_parameters
() {
254 vecho setting iscsi parameters
258 # Check once before getting explicit values, so we can output a decent
260 /sbin
/iscsiadm
--show -m session
-r $path > $tmpfile
261 if [ ! -s $tmpfile ]; then
262 echo Unable to
find iscsi record
for $path
266 nit_name
=$
(grep "^InitiatorName=" /etc
/iscsi
/initiatorname.iscsi | \
267 sed -e "s/^InitiatorName=//")
269 iscsi_get_rec_val
$tmpfile "node.name"
271 iscsi_get_rec_val
$tmpfile "node.tpgt"
273 # iscsistart wants node.conn[0].address / port
274 iscsi_get_rec_val
$tmpfile 'node.conn\[0\].address'
276 iscsi_get_rec_val
$tmpfile 'node.conn\[0\].port'
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"
284 if [ -n "${chap}" -a "${chap}" != "<empty>" ]; then
286 iscsi_get_rec_val
$tmpfile "node.session.auth.password"
287 chap_pw
="-w ${result}"
292 iscsi_get_rec_val
$tmpfile "node.session.auth.username_in"
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}"
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}"
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
329 while read dmstart dmend dmtype r0 r1 r2 r3 r4 r5 r6 r7 r8 r9
; do
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
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/}
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'"'
360 elif grep -q "^$slavedev :" /proc
/mdstat
; then
361 eval cryptoraid
${ncryptoraids}='"'/dev
/$slavedev $dmname'"'
364 eval cryptoparts
${ncryptoparts}='"'/dev
/$slavedev $dmname'"'
369 findstoragedriver
"/dev/$slavedev"
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
382 *) vg_list
="$vg_list $vg"
383 [ -z "$nolvm" ] && find_base_dm_mods
387 for raid
in $raids ; do
388 if [ "$raid" == "$name" ]; then
391 *) DMRAIDS
="$DMRAIDS $raid"
392 [ -z "$nodmraid" ] && find_base_dm_mods
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 }')
416 if [ -n "$noraid" -o ! -f /proc
/mdstat
]; then
420 levels
=$
(awk "/^$1[ ]*:/ { print\$4 }" /proc
/mdstat
)
422 for level
in $levels ; do
437 error
"raid level $level (in /proc/mdstat) not recognized"
441 if [ "$start" = 1 ]; then
442 raiddevices
="$raiddevices $1"
448 lvm lvs
--ignorelockingfailure --noheadings -o vg_name \
449 $1 2>/dev
/null |
egrep -v '^ *(WARNING:|Volume Groups with)'
453 lvm vgdisplay
--ignorelockingfailure -v $1 2>/dev
/null |
454 sed -n 's/PV Name//p'
460 [ "$dmmods_found" == "n" ] ||
return
465 while [ $# -gt 0 ]; do
468 if [ "$1" != "${1##--fstab=}" ]; then
481 if [ "$1" != "${1##--net-dev=}" ]; then
482 net_list
="$net_list ${1##--net-dev=}"
484 net_list
="$net_list $2"
489 if [ "$1" != "${1##--rootdev=}" ]; then
490 rootdev
="${1##--rootdev=}"
497 if [ "$1" != "${1##--thawdev=}" ]; then
498 thawdev
="${1##--thawdev=}"
505 if [ "$1" != "${1##--rootfs=}" ]; then
506 rootfs
="${1##--rootfs=}"
513 if [ "$1" != "${1##--rootopts=}" ]; then
514 rootopts
="${1##--rootopts=}"
521 if [ "$1" != "${1##--root=}" ]; then
529 if [ "$1" != "${1##--loopdev=}" ]; then
530 loopdev
="${1##--loopdev=}"
537 if [ "$1" != "${1##--loopfs=}" ]; then
538 loopfs
="${1##--loopfs=}"
545 if [ "$1" != "${1##--loopopts=}" ]; then
546 loopopts
="${1##--loopopts=}"
553 if [ "$1" != "${1##--looppath=}" ]; then
554 looppath
="${1##--looppath=}"
564 if [ -z "$target" ]; then
566 elif [ -z "$kernel" ]; then
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
585 if [ "$rootfs" == "nfs" ]; then
586 if [ "x$net_list" == "x" ]; then
590 # check if it's root by label
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)
602 if [ -n "$swsuspdev" ]; then
603 if [[ "$swsuspdev" =~ ^
(UUID
=|LABEL
=) ]]; then
604 swsuspdev
=$
(resolve_device_name
"$swsuspdev")
606 findstoragedriver
"$swsuspdev"
618 if [ "$1" == "-n" ]; then
627 if [ -z "$nodmraid" -a -n "$DMRAIDS" ]; then
628 for raid
in $DMRAIDS; do
629 echo -n "rd_DM_UUID=$raid "
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
642 local luksuuid
=$
(grep "^$2 " /etc
/crypttab
2>/dev
/null|
awk '{ print $2 }')
643 if [ -z "$luksuuid" ]; then
646 echo -n "rd_LUKS_UUID=$luksuuid "
649 for cryptdev
in ${!cryptopart@} ; do
650 emitcrypto
`eval echo '$'$cryptdev`
653 if [ -n "$raiddevices" ]; then
654 for dev
in $raiddevices; do
655 echo -n "rd_MD_UUID=${dev} "
659 for cryptdev
in ${!cryptoraid@} ; do
660 emitcrypto
`eval echo '$'$cryptdev`
663 if [ -z "$nolvm" -a -n "$vg_list" ]; then
664 for vg
in $vg_list; do
665 echo -n "rd_LVM_VG=$vg "
669 for cryptdev
in ${!cryptolv@} ; do
670 emitcrypto
`eval echo '$'$cryptdev`
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 "
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
694 /usr
/share
/plymouth
/themes
/default.plymouth
)))
695 [ -n "$theme" ] && echo -n "rd_plytheme=$theme "
699 # vim:ts=8:sw=4:sts=4:et