1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652
|
#! /bin/bash
# Copyright (c) 2004 International Business Machines
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# bootlist - command to display and/or update the bootlist in nvram.
#
# author Nathan Fontenot <nfont@linux.vnet.ibm.com>
#
OFPATHNAME=/usr/sbin/ofpathname
NVRAM=/usr/sbin/nvram
FIND=/usr/bin/find
PSERIES_PLATFORM=$(dirname $0)/pseries_platform
#
# usage
#
usage()
{
echo "Usage: $0 -m {normal|service|both} -o | -r"
echo " $0 -m {normal|service|both} [-o | -r] -f <file>"
echo " $0 -m {normal|service|both} [-o | -r] <device_list>"
echo "View and update the system boot lists"
echo ""
echo " -m {normal|service|both}"
echo " Specify the boot mode for boolist manipulation"
echo " -o Display bootlist entries as logical device names"
echo " -r Display bootlist entries as Open Firmware device"
echo " path names"
echo " -f file Read the boolist device names from file"
echo " -?, --help display this help information and exit"
echo " <device_list> a space-separated list of devices, specified as"
echo " logical device names or OF device path names,"
echo " depending on whether the -o or -r option is specified"
echo ""
echo "Additional optional arguments for ethernet devices:"
echo " bserver=<IP address of BOOTP server>"
echo " gateway=<IP address of gateway>"
echo " client=<IP address of the client>"
echo " speed=<Network adapter speed>, default=auto"
echo " duplex=<mode of the network adapter>, default=auto"
echo ""
}
#
# update_eth_dev
# When specifying an ethernet device for the bootlist we need to also get
# the additional parameters for ethernet devices (i.e gateway, speed, ...)
#
# Please NOTE: this routine does depend on global variables
#
update_eth_dev()
{
local speed=auto
local duplex=auto
local bserver=0.0.0.0
local gateway=0.0.0.0
local client=0.0.0.0
local eth_index=$[$ctr]
local index=$[$ctr + 1]
local found=1
while [[ $found -eq 1 ]]; do
found=0
case ${LOGICAL_NAMES[$index]} in
speed*) speed=${LOGICAL_NAMES[$index]##*=}
found=1 ;;
duplex*) duplex=${LOGICAL_NAMES[$index]##*=}
found=1 ;;
bserver*) bserver=${LOGICAL_NAMES[$index]##*=}
found=1 ;;
gateway*) gateway=${LOGICAL_NAMES[$index]##*=}
found=1 ;;
client*) client=${LOGICAL_NAMES[$index]##*=}
found=1 ;;
esac
if [[ $found -eq 1 ]]; then
index=$[$index + 1]
ctr=$[$ctr + 1]
fi
done
# update the ethernet device
OF_DEVPATH[$eth_index]=${OF_DEVPATH[$eth_index]}:speed=$speed,duplex=$duplex,$bserver,,$client,$gateway
}
#
# parse_eth_info
# Ethernet read from nvram (possibly) have additional data appended to
# them specifying the gateway, speed, ...
#
# $1 ethernet device name
# $2 ethernet device data
#
parse_eth_info()
{
local eth_name=$1
local eth_info=${2##*:}
echo $eth_name
# first the speed
local item=${eth_info%%,*}
if [[ -n $item ]]; then
echo " speed = ${item##*=}"
fi
# then the duplex
eth_info=${eth_info#*,}
item=${eth_info%%,*}
if [[ -n $item ]]; then
echo " duplex = ${item##*=}"
fi
# then the BOOTP server
eth_info=${eth_info#*,}
item=${eth_info%%,*}
if [[ -n $item ]]; then
echo " BOOTP Server: $item"
fi
# then the Mask
eth_info=${eth_info#*,}
item=${eth_info%%,*}
if [[ -n $item ]]; then
echo " Mask: $item"
fi
# then the client
eth_info=${eth_info#*,}
item=${eth_info%%,*}
if [[ -n $item ]]; then
echo " Client: $item"
fi
# then the Gateway
eth_info=${eth_info#*,}
item=${eth_info%%,*}
if [[ -n $item ]]; then
echo " Gateway: $item"
fi
}
#
# get_logical_device_name
# Translate the provided boot device to its logical device name
#
# $1 device name to convert
#
get_logical_device_name()
{
local devname=$1
local logical_name
logical_name=`$OFPATHNAME -l $devname 2>/dev/null`
if [[ $? -ne 0 ]]; then
echo ""
else
echo $logical_name | tr -d '\000'
fi
}
#
# get_of_device_name
# Translate the provided boot device to its OF device name
#
# $1 device name to convert
#
get_of_device_name()
{
local devname=$1
local of_name
of_name=`$OFPATHNAME $devname 2>/dev/null`
if [[ $? -ne 0 ]]; then
echo ""
else
echo $of_name
fi
}
#
# show_bootlist
# Retrieve a bootlist from nvram and print its contents
#
# $1 bootlist to print
#
show_bootlist()
{
local devlist=$1
local i
for i in `$NVRAM --print-config=${devlist} 2> /dev/null | sed 's/ /\n/g'`; do
if [[ $TRANSLATE_NAMES = "yes" ]]; then
name=`get_logical_device_name $i`
if [[ -z $name ]]; then
echo "Could not translate $i to logical device name" >&2
else
case $name in
eth*) parse_eth_info $name $i ;;
*) echo $name ;;
esac
fi
else
echo $i
fi
done
}
#
# Main
#
. $PSERIES_PLATFORM
if [[ $platform != $PLATFORM_PSERIES_LPAR ]]; then
echo "bootlist: is not supported on the $platform_name platform" >&2
exit 1
fi
# make sure we can parse names
if [[ ! -a $OFPATHNAME ]]; then
echo "no $OFPATHNAME!!!"
fi
# make sure we can update nvram
if [[ ! -a $NVRAM ]]; then
echo "no $NVRAM!!!"
fi
BOOTLIST_MODE=unknown
dm_to_part()
{
local dmp=$1
local dmdev=$2
local sddev=$3
local dmmapper
partname=$(cat "/sys/block/$dmp/dm/name" 2>/dev/null | sed 's/[0-9]*$//g')
diskname=$(cat "/sys/block/$dmdev/dm/name" 2>/dev/null)
delim=${partname##$diskname}
dmpmajmin=$(cat "/sys/block/$dmp/dev" 2>/dev/null)
dmdevmajmin=$(cat "/sys/block/$dmdev/dev" 2>/dev/null)
for dmapper in /dev/mapper/* ; do
dmajor=$(stat -L --format="%t" $dmapper 2>/dev/null)
dminor=$(stat -L --format="%T" $dmapper 2>/dev/null)
dmajmin=$(printf "%d:%d" 0x$dmajor 0x$dminor)
if [[ "$dmajmin" = "$dmdevmajmin" ]]; then
dmmapper=$dmapper;
break;
fi
done
kpartx -p "$delim" -l "$dmmapper" | while read kp ; do
kpname=${kp%% *}
tmajor=$(stat -L --format="%t" /dev/mapper/$kpname 2>/dev/null)
tminor=$(stat -L --format="%T" /dev/mapper/$kpname 2>/dev/null)
tmajmin=$(printf "%d:%d" 0x$tmajor 0x$tminor)
if [[ "$tmajmin" = "$dmpmajmin" ]]; then
partstart=${kp##* }
for part in `ls -1d /sys/block/$sddev/$sddev* 2>/dev/null`; do
pstart=$(cat $part/start 2>/dev/null)
if [[ "$pstart" -eq "$partstart" ]] ; then
echo "${part##*/}"
return
fi
done
fi
done
}
# is_nvmf_device
# Check to see if this is a nvmf device
#
is_nvmf_device()
{
local res
res=`$FIND /sys/devices/virtual/nvme-fabrics -name $1 2>/dev/null`
if [[ ${#res} = 0 ]]; then
echo "no"
else
echo "yes"
fi
}
# is_multipath_nvme_device
# Check to see if this is a multipath nvme device
#
is_multipath_nvme_device()
{
local res
res=`$FIND /sys/devices/virtual/nvme-subsystem -name $1 2>/dev/null`
if [[ ${#res} = 0 ]]; then
echo "no"
else
echo "yes"
fi
}
# get_link
# return the directory path that a link points to.
# The only parameter is the link name.
#
get_link()
{
local ln_name=$1;
echo `ls -l $ln_name 2>/dev/null | awk -F"->" '{print $2}'`
}
add_nvmf()
{
local DEVNAME=$1
ctrl_name=$DEVNAME
local startctr=$ctr
local dir
for dir in `$FIND /sys/devices/virtual/nvme-fabrics -name "$ctrl_name"`; do
cd $dir
link=`get_link "device"`
cd $link
for slave in `ls -d $PWD/nvme*`; do
slavedev=${slave##*/}
LOGICAL_NAMES[$ctr]=${slavedev}
ctr=$[$ctr + 1]
done
done
if [[ "$startctr" = "$ctr" ]] ; then
LOGICAL_NAMES[$ctr]=$1
ctr=$[$ctr + 1]
fi
}
add_multipath_nvme()
{
local DEVNAME=$1
ctrl_name=$DEVNAME
local startctr=$ctr
local dir
for dir in `$FIND /sys/devices/virtual/nvme-subsystem -name "$ctrl_name"`; do
cd $dir
cd ..
for slave in `ls -d $PWD/nvme*`; do
slavedev=${slave##*/}
if [[ "$slavedev" != *nvme*n* ]] ; then
LOGICAL_NAMES[$ctr]=${slavedev}
ctr=$[$ctr + 1]
fi
done
done
if [[ "$startctr" = "$ctr" ]] ; then
LOGICAL_NAMES[$ctr]=$1
ctr=$[$ctr + 1]
fi
}
add_logical()
{
local DEVNAME=$1
local major minor majmin devno
local startctr=$ctr
if [[ ! -e $DEVNAME ]]; then
DEVNAME=/dev/$DEVNAME
fi
if [[ ! -e $DEVNAME ]]; then
LOGICAL_NAMES[$ctr]=$1
ctr=$[$ctr + 1]
return
fi
major=$(stat -L --format="%t" $DEVNAME 2>/dev/null)
minor=$(stat -L --format="%T" $DEVNAME 2>/dev/null)
majmin=$(printf "%d:%d" 0x$major 0x$minor)
# Look for a matching multipath device
for dm in /sys/block/dm*; do
dmdev=${dm##*/}
devno=$(cat $dm/dev 2>/dev/null)
devmaj=${devno%:*}
devmin=${devno#*:}
if [[ ! -d $dm/slaves ]] ; then
# Old kernel for which there is no good way to reliably map
# a kpartx device with its parent
break;
fi
if [[ ! -d $dm/dm ]] ; then
# Old kernel for which there is no good way to reliably map
# a kpartx device with its parent
break;
fi
if [[ "$devno" = "$majmin" ]]; then
for slave in $dm/slaves/*; do
slavedev=${slave##*/}
if [[ "$slavedev" == dm-* ]] ; then
for slave2 in $slave/slaves/*; do
slavedev2=${slave2##*/}
if [[ "$slavedev2" == dm-* ]] ; then
# dmdev is an LV on physical multipath partition
for slave3 in $slave2/slaves/*; do
slavedev3=${slave3##*/}
partdev=$(dm_to_part $slavedev $slavedev2 $slavedev3)
if [[ ! -z "$partdev" ]] ; then
LOGICAL_NAMES[$ctr]=$partdev
ctr=$[$ctr + 1]
fi
done
else
# /sys/block/dm-2/slave/dm-0/slaves/sdb
kp=$(kpartx -l /dev/$slavedev)
if [[ -z "$kp" ]] ; then
# dmdev is an LV on physical multipath
# disk LV->DMDEV->DEV
LOGICAL_NAMES[$ctr]=$slavedev2
ctr=$[$ctr + 1]
else
# dmdev is multipath partition of slave
# DMP->DMDEV->DEV
partdev=$(dm_to_part $dmdev $slavedev $slavedev2)
if [[ ! -z "$partdev" ]] ; then
LOGICAL_NAMES[$ctr]=$partdev
ctr=$[$ctr + 1]
fi
fi
fi
done
else
# DMDEV is a multipath device on a physical device or
# a LV on a disk partition
LOGICAL_NAMES[$ctr]=$slavedev
ctr=$[$ctr + 1]
fi
done
fi
done
if [[ "$startctr" = "$ctr" ]] ; then
LOGICAL_NAMES[$ctr]=$1
ctr=$[$ctr + 1]
fi
}
#
# Parse the command line arguements and put them into two parallel
# arrays, one to hold the logical device name and one to hold the
# corresponding open firmware device path.
#
typeset -i ctr=0
while [[ -n $1 ]]; do
if [[ $1 = "-o" ]]; then
DISPLAY_BOOTLIST=yes
TRANSLATE_NAMES=yes
elif [[ $1 = "-r" ]]; then
DISPLAY_BOOTLIST=yes
elif [[ $1 = "-m" ]]; then
shift
if [[ ! -n $1 ]]; then
echo "did not specify \"normal\" or \"service\" mode with -m" >&2
usage
exit -1
fi
if [[ $1 = "normal" ]]; then
BOOTLIST_MODE=boot-device
elif [[ $1 = "service" ]]; then
BOOTLIST_MODE=diag-device
elif [[ $1 = "both" ]]; then
BOOTLIST_MODE=$1
else
echo "invalid mode specified with -m; must be \"normal\", \"service\" or \"both\"" >&2
usage
exit -1
fi
elif [[ $1 = "-f" ]]; then
# get bootlist names from specified file
if [[ ! -a $2 ]]; then
echo "file $2 does not exist" >&2
fi
for i in `cat $2 2>/dev/null`; do
add_logical $i
done
shift
elif [[ $1 = "--help" ]]; then
# display bootlist command help message
usage
exit 0
elif [[ $1 = -* ]]; then
# catch any illegal flags here
usage
exit -1
else
# add this element to the array
if [[ "$1" == *"dm-"* ]] ; then
add_logical $1
else
if [[ "$1" == *"nvme-of"* ]] || [[ "$1" == *"namespace"* ]]; then
ctrl_name=`get_logical_device_name $1`
master_of_path=$1
else
ctrl_name=$1
ctrl_name=${ctrl_name##*/}
master_of_path=`get_of_device_name $1`
fi
if [[ -z $master_of_path ]]; then
echo "Device $1 does not appear to be valid." >&2
exit 1
fi
ctrl_name="${ctrl_name%n[0-9]*}"
is_nvmf=$(is_nvmf_device $ctrl_name)
if [[ $is_nvmf = "yes" ]]; then
namespace_base=${master_of_path##*/}
DEVTYPE="nvme-of"
add_nvmf $ctrl_name
else
is_multipath_nvme=$(is_multipath_nvme_device $ctrl_name)
if [[ $is_multipath_nvme = "yes" ]]; then
if [[ "$master_of_path" == *namespace* ]] ; then
namespace_base=${master_of_path##*/}
else
echo "Device $1 does not appear to be valid." >&2
exit 1
fi
DEVTYPE="multi-nvme"
add_multipath_nvme $ctrl_name
else
add_logical $1
fi
fi
fi
fi
shift
done
if [[ ${BOOTLIST_MODE} = "unknown" ]]; then
echo "The boot mode must be specified with the -m option" >&2
usage
exit -1
fi
# Now we need to convert all of the logical device names to
# open firmware device paths.
if [[ ${#LOGICAL_NAMES[*]} -ne 0 ]]; then
ctr=0
while [[ $ctr -lt ${#LOGICAL_NAMES[*]} ]] && [[ $ctr -lt 5 ]]; do
OF_DEVPATH[$ctr]=`get_logical_device_name ${LOGICAL_NAMES[$ctr]}`
if [[ -z ${OF_DEVPATH[$ctr]} ]]; then
# See if this is an OF pathname
OF_DEVPATH[$ctr]=`get_of_device_name ${LOGICAL_NAMES[$ctr]}`
if [[ $DEVTYPE = "nvme-of" ]] || [[ $DEVTYPE = "multi-nvme" ]]; then
OF_DEVPATH[$ctr]=${OF_DEVPATH[$ctr]}/$namespace_base
else
OF_DEVPATH[$ctr]=${OF_DEVPATH[$ctr]}
fi
else
OF_DEVPATH[$ctr]=${LOGICAL_NAMES[$ctr]}
fi
if [[ -z ${OF_DEVPATH[$ctr]} ]]; then
echo "Device ${LOGICAL_NAMES[$ctr]} does not appear to be valid." >&2
exit 1
else
# See if this is an ethernet adapter. If so, the next entries
# may be parameters for the bootlist entry.
ethdev=`get_logical_device_name ${OF_DEVPATH[$ctr]}`
ethdev=${ethdev%%[0-9]*}
if [[ $ethdev = "eth" ]]; then
update_eth_dev
fi
# bootlist entries cannot exceed more than 255 chars
if [[ ${#OF_DEVPATH[$ctr]} -gt 255 ]]; then
echo "Bootlist entries cannot exceed 255 characters" >&2
echo "${OF_DEVPATH[$ctr]}" >&2
exit -1
fi
fi
ctr=$[$ctr + 1]
done
# We cannot have a bootlist with more than five entries
if [[ ${#OF_DEVPATH[*]} -gt 5 ]]; then
echo "More than five entries cannot be specified in the bootlist" >&2
exit -1
fi
# update the bootlist in nvram
if [[ $BOOTLIST_MODE = "both" ]]; then
$NVRAM --update-config "boot-device=${OF_DEVPATH[*]}" -pcommon
if [[ $? -ne 0 ]]; then
echo "Could not update service-mode bootlist" >&2
fi
$NVRAM --update-config "diag-device=${OF_DEVPATH[*]}" -pcommon
if [[ $? -ne 0 ]]; then
echo "Could not update normal-mode bootlist" >&2
fi
else
$NVRAM --update-config "${BOOTLIST_MODE}=${OF_DEVPATH[*]}" -pcommon
if [[ $? -ne 0 ]]; then
echo "Could not update bootlist!" >&2
fi
fi
fi
# Display the bootlist if desired
if [[ $DISPLAY_BOOTLIST = "yes" ]]; then
if [[ $BOOTLIST_MODE = "both" ]]; then
show_bootlist "boot-device"
show_bootlist "diag-device"
else
show_bootlist $BOOTLIST_MODE
fi
fi
|