4 # Copyright 2005-2008 Red Hat, Inc. All rights reserved.
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 # code taken from mkinitrd
21 #. /usr/libexec/initrd-functions
26 if [ "$1" == "-n" ]; then
36 if [ "$1" == "-n" ]; then
40 is_verbose
&& echo $NONL "$@"
43 # module dep finding and installation functions
46 if [ "$1" == "--ignore-install" ]; then
47 MPARGS
="$MPARGS --ignore-install"
50 vecho
-n "Looking for deps of module $1"
52 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)
53 [ -n "$deps" ] && vecho
": $deps" || vecho
56 if [ $UID != 0 ]; then
57 error
"$0 must be run as root."
61 export MALLOC_PERTURB_
=204
63 PATH
=/sbin
:/usr
/sbin
:/bin
:/usr
/bin
:$PATH
66 .
/etc
/rc.d
/init.d
/functions
68 # Set the umask. For iscsi, the initrd can contain plaintext
69 # password (chap secret), so only allow read by owner.
87 LD_SO_CONF
=/etc
/ld.so.conf
88 LD_SO_CONF_D
=/etc
/ld.so.conf.d
/
90 [ -e /etc
/sysconfig
/mkinitrd
] && .
/etc
/sysconfig
/mkinitrd
94 ARCH
=$
(uname
-m |
sed -e 's/s390x/s390/')
103 modulefile
=/etc
/modules.conf
104 [ "$ARCH" != "s390" ] && withusb
=1
117 if [ "$1" == "-n" ]; then
123 $cmd "usage: `basename $0` [--version] [--help] [-v] [-f]"
125 if [ "$1" == "-n" ]; then
134 pushd "$1" >/dev
/null
2>&1
141 resolve_device_name
() {
143 # echo "resolve_device_name $1" 1>&2
147 /usr
/bin
/readlink
-f "$1"
152 if [ -n "$majmin" ]; then
153 dev
=$
(for x
in /sys
/block
/* ; do find $x/ -name dev
; done |
while read device
; do \
154 echo "$majmin" |
cmp -s $device && echo $device ; done)
155 if [ -n "$dev" ]; then
165 finddevicedriverinsys
() {
166 if is_iscsi
$PWD; then
170 while [ "$PWD" != "/sys/devices" ]; do
172 if [ -f modalias
]; then
173 MODALIAS
=$
(cat modalias
)
174 if [ "${MODALIAS::7}" == "scsi:t-" ]; then
185 findstoragedriverinsys
() {
186 local sysfs
=$
(readlink
"$1")
188 # if its a partition look at the device holding the partition
189 if [ -f "$sysfs/start" ]; then
190 sysfs
=$
(readlink
${sysfs%/*})
193 if [[ ! "$sysfs" =~
'^/sys/.*block/.*$' ]]; then
194 #error "WARNING: $sysfs is a not a block sysfs path, skipping"
198 case " $handleddevices " in
201 *) handleddevices
="$handleddevices $sysfs" ;;
204 if [[ "$sysfs" =~
'^/sys/.*block/md[0-9]+$' ]]; then
205 local raid
=${sysfs##*/}
206 vecho
"Found MDRAID component $raid"
209 if [[ "$sysfs" =~
'^/sys/.*block/dm-[0-9]+$' ]]; then
210 vecho
"Found DeviceMapper component ${sysfs##*/}"
211 handledm $
(cat $sysfs/dev |cut
-d : -f 1) $
(cat $sysfs/dev |cut
-d : -f 2)
214 for slave
in $
(ls -d "$sysfs"/slaves
/* 2>/dev
/null
) ; do
215 findstoragedriverinsys
"$slave"
218 if [ -L "$sysfs/device" ]; then
219 qpushd $
(readlink
"$sysfs/device")
220 finddevicedriverinsys
225 findstoragedriver
() {
228 if [ ! -b "$device" ]; then
229 #error "WARNING: $device is a not a block device, skipping"
233 local majmin
=$
(get_numeric_dev dec
"$device")
234 local sysfs
=$
(finddevnoinsys
"$majmin")
236 if [ -z "$sysfs" ]; then
237 #error "WARNING: $device major:minor $majmin not found, skipping"
241 vecho
"Looking for driver for $device in $sysfs"
242 findstoragedriverinsys
"$sysfs"
245 iscsi_get_rec_val
() {
247 # The open-iscsi 742 release changed to using flat files in
250 result
=$
(grep "^${2} = " "$1" |
sed -e s
'/.* = //')
253 iscsi_set_parameters
() {
255 vecho setting iscsi parameters
259 # Check once before getting explicit values, so we can output a decent
261 /sbin
/iscsiadm
--show -m session
-r $path > $tmpfile
262 if [ ! -s $tmpfile ]; then
263 echo Unable to
find iscsi record
for $path
267 nit_name
=$
(grep "^InitiatorName=" /etc
/iscsi
/initiatorname.iscsi | \
268 sed -e "s/^InitiatorName=//")
270 iscsi_get_rec_val
$tmpfile "node.name"
272 iscsi_get_rec_val
$tmpfile "node.tpgt"
274 # iscsistart wants node.conn[0].address / port
275 iscsi_get_rec_val
$tmpfile 'node.conn\[0\].address'
277 iscsi_get_rec_val
$tmpfile 'node.conn\[0\].port'
280 # Note: we get chap secrets (passwords) in plaintext, and also store
281 # them in the initrd.
283 iscsi_get_rec_val
$tmpfile "node.session.auth.username"
285 if [ -n "${chap}" -a "${chap}" != "<empty>" ]; then
287 iscsi_get_rec_val
$tmpfile "node.session.auth.password"
288 chap_pw
="-w ${result}"
293 iscsi_get_rec_val
$tmpfile "node.session.auth.username_in"
295 if [ -n "${chap_in}" -a "${chap_in}" != "<empty>" ]; then
296 chap_in
="-U ${chap_in}"
297 iscsi_get_rec_val
$tmpfile "node.session.auth.password_in"
298 chap_in_pw
="-W ${result}"
307 if [ -n "${iscsi_devs}" ]; then
308 for dev
in ${iscsi_devs}; do
309 iscsi_set_parameters
$dev
310 # recid is not really used, just use 0 for it
311 echo "/bin/iscsistart -t ${tgt_name} -i ${nit_name} \
312 -g ${tpgt} -a ${tgt_ipaddr} ${chap} ${chap_pw} \
313 ${chap_in} ${chap_in_pw}"
320 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
330 while read dmstart dmend dmtype r0 r1 r2 r3 r4 r5 r6 r7 r8 r9
; do
333 # this device is encrypted; find the slave device and see
334 # whether the encryption is LUKS; if not, bail.
335 slavedev
=$
(finddevnoinsys
$r3)
336 # get the basename, then s,!,/, in case it's a cciss device
337 slavedev
=$
(echo ${slavedev##*/} |
tr '!' '/')
338 cryptsetup isLuks
"/dev/$slavedev" 2>/dev
/null ||
continue
340 dmname
=$
(dmsetup info
-j $major -m $minor -c --noheadings -o name
)
341 # do the device resolution dance to get /dev/mapper/foo
342 # since 'lvm lvs' doesn't like dm-X device nodes
343 if [[ "$slavedev" =~ ^dm-
]]; then
344 majmin
=$
(get_numeric_dev dec
"/dev/$slavedev")
345 for dmdev
in /dev
/mapper
/* ; do
346 dmnum
=$
(get_numeric_dev dev
$dmdev)
347 if [ $dmnum = $majmin ]; then
348 slavedev
=${dmdev#/dev/}
354 # determine if $slavedev is an LV
355 # if so, add the device to latecryptodevs
356 # if not, add the device to cryptodevs
357 local vg
=$
(lvshow
/dev
/$slavedev)
358 if [ -n "$vg" ]; then
359 eval cryptolv
${ncryptolvs}='"'/dev
/$slavedev $dmname'"'
361 elif grep -q "^$slavedev :" /proc
/mdstat
; then
362 eval cryptoraid
${ncryptoraids}='"'/dev
/$slavedev $dmname'"'
365 eval cryptoparts
${ncryptoparts}='"'/dev
/$slavedev $dmname'"'
370 findstoragedriver
"/dev/$slavedev"
374 $(dmsetup table -j $major -m $minor 2>/dev/null)
376 local name
=$
(dmsetup info
--noheadings -c -j $major -m $minor -o name
)
377 local vg
=$
(lvshow
"/dev/mapper/$name")
378 local raids
=$
(/sbin
/dmraid
-s -craidname 2>/dev
/null |
grep -vi "no raid disks")
379 if [ -n "$vg" ]; then
380 vg
=`echo $vg` # strip whitespace
383 *) vg_list
="$vg_list $vg"
384 [ -z "$nolvm" ] && find_base_dm_mods
388 for raid
in $raids ; do
389 if [ "$raid" == "$name" ]; then
392 *) DMRAIDS
="$DMRAIDS $raid"
393 [ -z "$nodmraid" ] && find_base_dm_mods
402 vecho
"Found iscsi component $1"
404 # We call iscsi_set_parameters once here to figure out what network to
405 # use (it sets tgt_ipaddr), and once again to emit iscsi values,
406 # not very efficient.
407 iscsi_set_parameters
$1
408 iscsi_devs
="$iscsi_devs $1"
409 netdev
=$
(/sbin
/ip route get to
$tgt_ipaddr | \
410 sed 's|.*dev \(.*\).*|\1|g' |
awk '{ print $1; exit }')
417 if [ -n "$noraid" -o ! -f /proc
/mdstat
]; then
421 levels
=$
(awk "/^$1[ ]*:/ { print\$4 }" /proc
/mdstat
)
423 for level
in $levels ; do
438 error
"raid level $level (in /proc/mdstat) not recognized"
442 if [ "$start" = 1 ]; then
443 raiddevices
="$raiddevices $1"
449 lvm lvs
--ignorelockingfailure --noheadings -o vg_name \
450 $1 2>/dev
/null |
egrep -v '^ *(WARNING:|Volume Groups with)'
454 lvm vgdisplay
--ignorelockingfailure -v $1 2>/dev
/null |
455 sed -n 's/PV Name//p'
461 [ "$dmmods_found" == "n" ] ||
return
466 while [ $# -gt 0 ]; do
469 if [ "$1" != "${1##--fstab=}" ]; then
482 if [ "$1" != "${1##--net-dev=}" ]; then
483 net_list
="$net_list ${1##--net-dev=}"
485 net_list
="$net_list $2"
490 if [ "$1" != "${1##--rootdev=}" ]; then
491 rootdev
="${1##--rootdev=}"
498 if [ "$1" != "${1##--thawdev=}" ]; then
499 thawdev
="${1##--thawdev=}"
506 if [ "$1" != "${1##--rootfs=}" ]; then
507 rootfs
="${1##--rootfs=}"
514 if [ "$1" != "${1##--rootopts=}" ]; then
515 rootopts
="${1##--rootopts=}"
522 if [ "$1" != "${1##--root=}" ]; then
530 if [ "$1" != "${1##--loopdev=}" ]; then
531 loopdev
="${1##--loopdev=}"
538 if [ "$1" != "${1##--loopfs=}" ]; then
539 loopfs
="${1##--loopfs=}"
546 if [ "$1" != "${1##--loopopts=}" ]; then
547 loopopts
="${1##--loopopts=}"
554 if [ "$1" != "${1##--looppath=}" ]; then
555 looppath
="${1##--looppath=}"
565 if [ -z "$target" ]; then
567 elif [ -z "$kernel" ]; then
578 [ -z "$rootfs" ] && rootfs
=$
(awk '{ if ($1 !~ /^[ \t]*#/ && $2 == "/") { print $3; }}' $fstab)
579 [ -z "$rootopts" ] && rootopts
=$
(awk '{ if ($1 !~ /^[ \t]*#/ && $2 == "/") { print $4; }}' $fstab)
580 [ -z "$rootopts" ] && rootopts
="defaults"
583 [ -z "$rootdev" ] && rootdev
=$
(awk '/^[ \t]*[^#]/ { if ($2 == "/") { print $1; }}' $fstab)
584 # check if it's nfsroot
586 if [ "$rootfs" == "nfs" ]; then
587 if [ "x$net_list" == "x" ]; then
591 # check if it's root by label
593 if [[ "$rdev" =~ ^
(UUID
=|LABEL
=) ]]; then
594 rdev
=$
(resolve_device_name
"$rdev")
596 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/')
597 findstoragedriver
"$rdev"
600 # find the first swap dev which would get used for swsusp
601 [ -z "$thawdev" ] && thawdev
=$
(awk '/^[ \t]*[^#]/ { if ($3 == "swap") { print $1; exit }}' $fstab)
603 if [ -n "$swsuspdev" ]; then
604 if [[ "$swsuspdev" =~ ^
(UUID
=|LABEL
=) ]]; then
605 swsuspdev
=$
(resolve_device_name
"$swsuspdev")
607 findstoragedriver
"$swsuspdev"
619 if [ "$1" == "-n" ]; then
628 if [ -z "$nodmraid" -a -n "$DMRAIDS" ]; then
629 for raid
in $DMRAIDS; do
630 echo -n "rd_DM_UUID=$raid "
636 # HACK: module loading + device creation isn't necessarily synchronous...
637 # this will make sure that we have all of our devices before trying
638 # things like RAID or LVM
643 local luksuuid
=$
(grep "^$2 " /etc
/crypttab
2>/dev
/null|
awk '{ print $2 }')
644 if [ -z "$luksuuid" ]; then
647 echo -n "rd_LUKS_UUID=$luksuuid "
650 for cryptdev
in ${!cryptopart@} ; do
651 emitcrypto
`eval echo '$'$cryptdev`
654 if [ -n "$raiddevices" ]; then
655 for dev
in $raiddevices; do
656 echo -n "rd_MD_UUID=${dev} "
660 for cryptdev
in ${!cryptoraid@} ; do
661 emitcrypto
`eval echo '$'$cryptdev`
664 if [ -z "$nolvm" -a -n "$vg_list" ]; then
665 for vg
in $vg_list; do
666 echo -n "rd_LVM_VG=$vg "
670 for cryptdev
in ${!cryptolv@} ; do
671 emitcrypto
`eval echo '$'$cryptdev`
674 # output local keyboard/18n settings
675 .
/etc
/sysconfig
/keyboard
676 .
/etc
/sysconfig
/i18n
678 for i
in KEYBOARDTYPE KEYTABLE SYSFONT SYSFONTACM UNIMAP LANG
; do
679 val
=$
(eval echo \$
$i)
680 [[ $val ]] && echo -n "$i=$val "
684 # vim:ts=8:sw=4:sts=4:et