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 set_verbose
() {
34 function is_verbose
() {
35 [ -n "$IF_verbose" ] && return 0
39 function get_verbose
() {
45 function get_numeric_dev
() {
48 if [ "$1" == "hex" ]; then
51 ls -lH "$2" |
awk '{ sub(/,/, "", $5); printf("'"$fmt"'", $5, $6); }'
61 is_verbose
&& echo "$@"
64 # module dep finding and installation functions
67 if [ "$1" == "--ignore-install" ]; then
68 MPARGS
="$MPARGS --ignore-install"
71 vecho
-n "Looking for deps of module $1"
73 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)
74 [ -n "$deps" ] && vecho
": $deps" || vecho
77 export MALLOC_PERTURB_
=204
79 PATH
=/sbin
:/usr
/sbin
:/bin
:/usr
/bin
:$PATH
82 # Set the umask. For iscsi, the initrd can contain plaintext
83 # password (chap secret), so only allow read by owner.
101 LD_SO_CONF
=/etc
/ld.so.conf
102 LD_SO_CONF_D
=/etc
/ld.so.conf.d
/
104 [ -e /etc
/sysconfig
/mkinitrd
] && .
/etc
/sysconfig
/mkinitrd
108 ARCH
=$
(uname
-m |
sed -e 's/s390x/s390/')
117 modulefile
=/etc
/modules.conf
118 [ "$ARCH" != "s390" ] && withusb
=1
131 if [ "$1" == "-n" ]; then
137 $cmd "usage: `basename $0` [--version] [--help] [-v] [-f]"
139 if [ "$1" == "-n" ]; then
148 pushd "$1" >/dev
/null
2>&1
160 resolve_device_name
() {
161 if [ -z "${1##UUID=*}" ]; then
162 real
=$
(freadlink
/dev
/disk
/by-uuid
/${1##UUID=})
163 [ -b $real ] && { echo $real; return; }
165 if [ -z "${1##LABEL=*}" ]; then
166 real
=$
(freadlink
/dev
/disk
/by-label
/${1##LABEL=})
167 [ -b $real ] && { echo $real; return; }
174 if [ -n "$majmin" ]; then
175 dev
=$
(for x
in /sys
/block
/* ; do find $x/ -name dev
; done |
while read device
; do \
176 echo "$majmin" |
cmp -s $device && echo $device ; done)
177 if [ -n "$dev" ]; then
187 finddevicedriverinsys
() {
188 if is_iscsi
$PWD; then
192 while [ "$PWD" != "/sys/devices" ]; do
194 if [ -f modalias
]; then
195 MODALIAS
=$
(cat modalias
)
196 if [ "${MODALIAS::7}" == "scsi:t-" ]; then
207 findstoragedriverinsys
() {
208 local sysfs
=$
(freadlink
"$1")
210 # if its a partition look at the device holding the partition
211 if [ -f "$sysfs/start" ]; then
212 sysfs
=$
(freadlink
${sysfs%/*})
215 if [[ ! "$sysfs" =~ ^
/sys
/.
*block
/.
*$
]]; then
216 #error "WARNING: $sysfs is a not a block sysfs path, skipping"
220 case " $handleddevices " in
223 *) handleddevices
="$handleddevices $sysfs" ;;
226 if [[ "$sysfs" =~ ^
/sys
/.
*block
/md
[0-9]+$
]]; then
227 local raid
=${sysfs##*/}
228 vecho
"Found MDRAID component $raid"
231 if [[ "$sysfs" =~ ^
/sys
/.
*block
/dm-
[0-9]+$
]]; then
232 vecho
"Found DeviceMapper component ${sysfs##*/}"
233 handledm $
(cat $sysfs/dev |cut
-d : -f 1) $
(cat $sysfs/dev |cut
-d : -f 2)
236 for slave
in $
(ls -d "$sysfs"/slaves
/* 2>/dev
/null
) ; do
237 findstoragedriverinsys
"$slave"
240 if [ -L "$sysfs/device" ]; then
241 qpushd $
(freadlink
"$sysfs/device")
242 finddevicedriverinsys
247 findstoragedriver
() {
250 if [ ! -b "$device" ]; then
251 #error "WARNING: $device is a not a block device, skipping"
255 local majmin
=$
(get_numeric_dev dec
"$device")
256 local sysfs
=$
(finddevnoinsys
"$majmin")
258 if [ -z "$sysfs" ]; then
259 #error "WARNING: $device major:minor $majmin not found, skipping"
263 vecho
"Looking for driver for $device in $sysfs"
264 findstoragedriverinsys
"$sysfs"
267 iscsi_get_rec_val
() {
269 # The open-iscsi 742 release changed to using flat files in
272 result
=$
(grep "^${2} = " "$1" |
sed -e s
'/.* = //')
275 iscsi_set_parameters
() {
277 vecho setting iscsi parameters
281 # Check once before getting explicit values, so we can output a decent
283 /sbin
/iscsiadm
--show -m session
-r $path > $tmpfile
284 if [ ! -s $tmpfile ]; then
285 echo Unable to
find iscsi record
for $path
289 nit_name
=$
(grep "^InitiatorName=" /etc
/iscsi
/initiatorname.iscsi | \
290 sed -e "s/^InitiatorName=//")
292 iscsi_get_rec_val
$tmpfile "node.name"
294 iscsi_get_rec_val
$tmpfile "node.tpgt"
296 # iscsistart wants node.conn[0].address / port
297 iscsi_get_rec_val
$tmpfile 'node.conn\[0\].address'
299 iscsi_get_rec_val
$tmpfile 'node.conn\[0\].port'
302 # Note: we get chap secrets (passwords) in plaintext, and also store
303 # them in the initrd.
305 iscsi_get_rec_val
$tmpfile "node.session.auth.username"
307 if [ -n "${chap}" -a "${chap}" != "<empty>" ]; then
309 iscsi_get_rec_val
$tmpfile "node.session.auth.password"
310 chap_pw
="-w ${result}"
315 iscsi_get_rec_val
$tmpfile "node.session.auth.username_in"
317 if [ -n "${chap_in}" -a "${chap_in}" != "<empty>" ]; then
318 chap_in
="-U ${chap_in}"
319 iscsi_get_rec_val
$tmpfile "node.session.auth.password_in"
320 chap_in_pw
="-W ${result}"
329 if [ -n "${iscsi_devs}" ]; then
330 for dev
in ${iscsi_devs}; do
331 iscsi_set_parameters
$dev
332 # recid is not really used, just use 0 for it
333 echo "/bin/iscsistart -t ${tgt_name} -i ${nit_name} \
334 -g ${tpgt} -a ${tgt_ipaddr} ${chap} ${chap_pw} \
335 ${chap_in} ${chap_in_pw}"
342 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
352 while read dmstart dmend dmtype r0 r1 r2 r3 r4 r5 r6 r7 r8 r9
; do
355 # this device is encrypted; find the slave device and see
356 # whether the encryption is LUKS; if not, bail.
357 slavedev
=$
(finddevnoinsys
$r3)
358 # get the basename, then s,!,/, in case it's a cciss device
359 slavedev
=$
(echo ${slavedev##*/} |
tr '!' '/')
360 cryptsetup isLuks
"/dev/$slavedev" 2>/dev
/null ||
continue
362 dmname
=$
(dmsetup info
-j $major -m $minor -c --noheadings -o name
)
363 # do the device resolution dance to get /dev/mapper/foo
364 # since 'lvm lvs' doesn't like dm-X device nodes
365 if [[ "$slavedev" =~ ^dm-
]]; then
366 majmin
=$
(get_numeric_dev dec
"/dev/$slavedev")
367 for dmdev
in /dev
/mapper
/* ; do
368 dmnum
=$
(get_numeric_dev dev
$dmdev)
369 if [ $dmnum = $majmin ]; then
370 slavedev
=${dmdev#/dev/}
376 # determine if $slavedev is an LV
377 # if so, add the device to latecryptodevs
378 # if not, add the device to cryptodevs
379 local vg
=$
(lvshow
/dev
/$slavedev)
380 if [ -n "$vg" ]; then
381 eval cryptolv
${ncryptolvs}='"'/dev
/$slavedev $dmname'"'
383 elif grep -q "^$slavedev :" /proc
/mdstat
; then
384 eval cryptoraid
${ncryptoraids}='"'/dev
/$slavedev $dmname'"'
387 eval cryptoparts
${ncryptoparts}='"'/dev
/$slavedev $dmname'"'
392 findstoragedriver
"/dev/$slavedev"
396 $(dmsetup table -j $major -m $minor 2>/dev/null)
398 local name
=$
(dmsetup info
--noheadings -c -j $major -m $minor -o name
)
399 local vg
=$
(lvshow
"/dev/mapper/$name")
400 local raids
=$
(/sbin
/dmraid
-s -craidname 2>/dev
/null |
grep -vi "no raid disks")
401 if [ -n "$vg" ]; then
402 vg
=`echo $vg` # strip whitespace
405 *) vg_list
="$vg_list $vg"
406 [ -z "$nolvm" ] && find_base_dm_mods
410 for raid
in $raids ; do
411 if [ "$raid" == "$name" ]; then
414 *) DMRAIDS
="$DMRAIDS $raid"
415 [ -z "$nodmraid" ] && find_base_dm_mods
424 vecho
"Found iscsi component $1"
426 # We call iscsi_set_parameters once here to figure out what network to
427 # use (it sets tgt_ipaddr), and once again to emit iscsi values,
428 # not very efficient.
429 iscsi_set_parameters
$1
430 iscsi_devs
="$iscsi_devs $1"
431 netdev
=$
(/sbin
/ip route get to
$tgt_ipaddr | \
432 sed 's|.*dev \(.*\).*|\1|g' |
awk '{ print $1; exit }')
439 if [ -n "$noraid" -o ! -f /proc
/mdstat
]; then
443 levels
=$
(awk "/^$1[ ]*:/ { print\$4 }" /proc
/mdstat
)
445 for level
in $levels ; do
460 error
"raid level $level (in /proc/mdstat) not recognized"
464 if [ "$start" = 1 ]; then
465 raiddevices
="$raiddevices $1"
471 lvm lvs
--ignorelockingfailure --noheadings -o vg_name \
472 $1 2>/dev
/null |
egrep -v '^ *(WARNING:|Volume Groups with)'
476 lvm vgdisplay
--ignorelockingfailure -v $1 2>/dev
/null |
477 sed -n 's/PV Name//p'
483 [ "$dmmods_found" == "n" ] ||
return
488 while [ $# -gt 0 ]; do
491 if [ "$1" != "${1##--fstab=}" ]; then
504 if [ "$1" != "${1##--net-dev=}" ]; then
505 net_list
="$net_list ${1##--net-dev=}"
507 net_list
="$net_list $2"
512 if [ "$1" != "${1##--rootdev=}" ]; then
513 rootdev
="${1##--rootdev=}"
520 if [ "$1" != "${1##--thawdev=}" ]; then
521 thawdev
="${1##--thawdev=}"
528 if [ "$1" != "${1##--rootfs=}" ]; then
529 rootfs
="${1##--rootfs=}"
536 if [ "$1" != "${1##--rootopts=}" ]; then
537 rootopts
="${1##--rootopts=}"
544 if [ "$1" != "${1##--root=}" ]; then
552 if [ "$1" != "${1##--loopdev=}" ]; then
553 loopdev
="${1##--loopdev=}"
560 if [ "$1" != "${1##--loopfs=}" ]; then
561 loopfs
="${1##--loopfs=}"
568 if [ "$1" != "${1##--loopopts=}" ]; then
569 loopopts
="${1##--loopopts=}"
576 if [ "$1" != "${1##--looppath=}" ]; then
577 looppath
="${1##--looppath=}"
587 if [ -z "$target" ]; then
589 elif [ -z "$kernel" ]; then
600 [ -z "$rootfs" ] && rootfs
=$
(awk '{ if ($1 !~ /^[ \t]*#/ && $2 == "/") { print $3; }}' $fstab)
601 [ -z "$rootopts" ] && rootopts
=$
(awk '{ if ($1 !~ /^[ \t]*#/ && $2 == "/") { print $4; }}' $fstab)
602 [ -z "$rootopts" ] && rootopts
="defaults"
605 [ -z "$rootdev" ] && rootdev
=$
(awk '/^[ \t]*[^#]/ { if ($2 == "/") { print $1; }}' $fstab)
606 # check if it's nfsroot
608 if [ "$rootfs" == "nfs" ]; then
609 if [ "x$net_list" == "x" ]; then
613 # check if it's root by label
615 rdev
=$
(resolve_device_name
"$rdev")
616 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/')
617 findstoragedriver
"$rdev"
620 # find the first swap dev which would get used for swsusp
621 [ -z "$thawdev" ] && thawdev
=$
(awk '/^[ \t]*[^#]/ { if ($3 == "swap") { print $1; exit }}' $fstab)
623 if [ -n "$swsuspdev" ]; then
624 swsuspdev
=$
(resolve_device_name
"$swsuspdev")
625 findstoragedriver
"$swsuspdev"
637 if [ "$1" == "-n" ]; then
646 if [ -z "$nodmraid" -a -n "$DMRAIDS" ]; then
647 for raid
in $DMRAIDS; do
648 echo -n "rd_DM_UUID=$raid "
654 # HACK: module loading + device creation isn't necessarily synchronous...
655 # this will make sure that we have all of our devices before trying
656 # things like RAID or LVM
661 local luksuuid
=$
(grep "^$2 " /etc
/crypttab
2>/dev
/null|
awk '{ print $2 }')
662 if [ -z "$luksuuid" ]; then
665 luksuuid
=${luksuuid##UUID=}
666 echo -n "rd_LUKS_UUID=$luksuuid "
669 if [ -n "$raiddevices" ]; then
670 for dev
in $raiddevices; do
671 uid
=$
(udevadm info
--query=env
--name /dev
/${dev}|
grep MD_UUID
)
673 [ -n "$uid" ] && echo -n "rd_MD_UUID=$uid "
679 if [ -z "$nolvm" -a -n "$vg_list" ]; then
680 for vg
in $vg_list; do
681 echo -n "rd_LVM_VG=$vg "
687 cryptdevs
="$(echo ${!cryptoraid@} ${!cryptopart@} ${!cryptolv@})"
689 if [ -z "$cryptdevs" ]; then
690 echo -n "rd_NO_LUKS "
692 for cryptdev
in ${!cryptoraid@} ${!cryptopart@} ${!cryptolv@} ; do
693 emitcrypto
`eval echo '$'$cryptdev`
697 # output local keyboard/18n settings
698 [ -e /etc
/sysconfig
/keyboard
] && .
/etc
/sysconfig
/keyboard
699 [ -e /etc
/sysconfig
/i18n
] && .
/etc
/sysconfig
/i18n
701 for i
in KEYTABLE SYSFONT SYSFONTACM UNIMAP LANG
; do
702 val
=$
(eval echo \$
$i)
703 [[ $val ]] && echo -n "$i=$val "
706 if [ -n "$KEYBOARDTYPE" -a "$KEYBOARDTYPE" != "pc" ]; then
707 echo -n "KEYBOARDTYPE=$KEYBOARDTYPE "
710 if [ -n "$rootdev" ]; then
711 echo -n "root=$rootdev "
715 # vim:ts=8:sw=4:sts=4:et