[arch-releng] [PATCH] Reworte finddisks and findblockdevices. Renamed findblockdevices to find_usable_devs
Matthew Gyurgyik
pyther at pyther.net
Sun Feb 20 15:09:38 EST 2011
On 02/20/2011 01:37 PM, Dieter Plaetinck wrote:
> From what I can tell in my mail client, it seems like this will be a nice cleanup of some very old code :)
> thanks.
>
Here is a diff of the changes after implementing your suggestions.
The most notable change is that I now check to see if the root block
device (sda, sdb) is part of a raid or lvm setup.
I attempted to fix the commit message:
Reworte finddisks and findblockdevices. Renamed findblockdevices to
find_usable_devs
find_usable_devs returns a list of partitioned and non-partitioned block
devices. These devices include SCSI/Sata, CCISS, IDA, LVM, SOFT RAID
devices. Devices in LVM and SOFT RAID configurations are excluded from
this list.
diff --git a/src/core/libs/lib-blockdevices-filesystems.sh
b/src/core/libs/lib-blockdevices-filesystems.sh
index 1b10927..d9c28ff 100644
--- a/src/core/libs/lib-blockdevices-filesystems.sh
+++ b/src/core/libs/lib-blockdevices-filesystems.sh
@@ -209,53 +209,49 @@ finddisks() {
shopt -s nullglob
# Block Devices
- if [[ -d /sys/block ]]; then
- for dev in /sys/block/*; do
- if [[ -f $dev/device/type ]]; then
- local type
- read type <
/sys/block/${dev##*/}/device/type
- read size < /sys/block/${dev##*/}/size
- # Type 5 is a ROM Device
- if [[ $type != 5 ]] && (( $size > 0 )); then
- source "$dev/uevent"
- echo -ne "/dev/$DEVNAME $1"
- unset DEVNAME
- fi
+ for dev in /sys/block/*; do
+ if [[ -f $dev/device/type ]]; then
+ local type
+ read type < /sys/block/${dev##*/}/device/type
+ # Block Devices with size =< 0 may be an empty
card reader
+ read size < /sys/block/${dev##*/}/size
+ # Type 5 is a ROM Device - Optical Drives
+ if [[ $type != 5 ]] && (( $size > 0 )); then
+ source "$dev/uevent"
+ echo -ne "/dev/$DEVNAME $1"
+ unset DEVNAME
fi
- done
- fi
+ fi
+ done
# cciss controllers
- if [[ -d /dev/cciss ]]; then
- for dev in /dev/cciss/*; do
- if [[ $dev != *[[:digit:]]p[[:digit:]]* ]]; then
- echo "$dev $1"
- fi
- done
- fi
+ for dev in /dev/cciss/*; do
+ if [[ $dev != *[[:digit:]]p[[:digit:]]* ]]; then
+ echo "$dev $1"
+ fi
+ done
+
# Smart 2 Controller
- if [[ -d /dev/ida ]]; then
- for dev in /dev/ida/*; do
- if [[ $dev != *[[:digit:]]p[[:digit:]]* ]]; then
- echo "$dev $1"
- fi
- done
- fi
+ for dev in /dev/ida/*; do
+ if [[ $dev != *[[:digit:]]p[[:digit:]]* ]]; then
+ echo "$dev $1"
+ fi
+ done
+
shopt -u nullglob
}
-# find block devices, both partionable or not (i.e. partitions themselves)
+# find usable devices, both partionable or not (i.e. partitions themselves)
# $1 extra things to echo for each partition (optional) (backslash
escapes will get interpreted)
-# find usable block devices
-find_usable_bdevs() {
+find_usable_blockdevices() {
shopt -s nullglob
local parts
- # Cycle through all non-partitional block devices (sda, sdb, etc...)
+ # Cycle through all root block devices (sda, sdb, etc...)
# Look for partitions and include them only if they are not
part of a
- # RAID or LVM. Also, exclude the extended partition
+ # RAID or LVM configuration. Also, exclude extended partitions
for devpath in $(finddisks); do
hidebldev=
unset parts
@@ -268,7 +264,7 @@ find_usable_bdevs() {
local partnum="${dev##*[[:alpha:]]}"
# Don't display extened partition (not logical
parts)
- sfdisk -c "$disk" "$partnum" 2>/dev/null | grep
-q '5' && continue;
+ [ "$(sfdisk -c "$disk" "$partnum" 2>/dev/null)"
= 5 ] && continue;
# Don't list parts that are part of RAID or LVM
volumes
+ # Although we strongly encourage users to setup
LVM in AIF, we want to make
+ # life a bit easier for those who have setup
LVM/softraid before running AIF
if grep -qsw "${dev##*/}" /proc/mdstat || {
pvscan -s 2>/dev/null | grep -q "$dev"; }; then
@@ -278,10 +274,13 @@ find_usable_bdevs() {
fi
done
- # If we have no partitions then print the root of the
block device
- # Otherwise print the partitions
- if [[ -z $hidebldev ]] && (( ${#parts[@]} < 1 )); then
- echo -ne "$devpath $1"
+ # If hidebldev is not set and we have no partitions then
+ # Echo root block device if root block device is not
part of a LVM or RAID configuration
+ # Otherwise echo the partitions
+ if [[ -z $hidebldev ]] && (( ! ${#parts[@]} )); then
+ if ! grep -qsw "${devpath##*/}" /proc/mdstat &&
! pvscan -s 2>/dev/null | grep -q "$devpath"; then
+ echo -ne "$devpath $1"
+ fi
elif (( ${#parts[@]} )); then
for part in ${parts[@]}; do
echo -ne "$part $1"
diff --git a/src/core/libs/lib-ui-interactive.sh
b/src/core/libs/lib-ui-interactive.sh
index bf19ef2..64be570 100644
--- a/src/core/libs/lib-ui-interactive.sh
+++ b/src/core/libs/lib-ui-interactive.sh
@@ -557,7 +557,7 @@ interactive_filesystems() {
if [ ! -f $TMP_BLOCKDEVICES ] || ! ask_yesno "Previous
blockdevice definitions found:\n`cat $TMP_BLOCKDEVICES`\n\
Use these as a starting point? Make sure your disk(s)
are partitioned correctly so your definitions can be applied. Pick 'no'
when in doubt to start from scratch" no
then
- find_usable_bdevs 'raw no_label no_fs\n' > $TMP_BLOCKDEVICES
+ find_usable_blockdevices 'raw no_label no_fs\n' >
$TMP_BLOCKDEVICES
fi
[ -z "$PART_ACCESS" ] && PART_ACCESS=dev
@@ -885,7 +885,7 @@ interactive_grub() {
# Create and edit the grub menu.lst
interactive_grub_menulst
- DEVS="$(find_usable_bdevs '_ ')"
+ DEVS="$(find_usable_blockdevices '_ ')"
if [ "$DEVS" = " " ]; then
notify "No hard drives were found"
return 1
More information about the arch-releng
mailing list