From 03c6aca73f7c832774035de83714aa0655892459 Mon Sep 17 00:00:00 2001 From: Marius Vollmer Date: Mon, 16 May 2016 12:01:35 +0300 Subject: [PATCH] Handle partition names like "loop0p1" This also assumes that the block device for the partition is available right after "udevadm settle". Fixes #137 --- container-storage-setup.sh | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/container-storage-setup.sh b/container-storage-setup.sh index 1b2b91a..6c126d0 100755 --- a/container-storage-setup.sh +++ b/container-storage-setup.sh @@ -683,12 +683,11 @@ scan_disks() { local new_disks="" for dev in $DEVS_ABS; do - local basename=$(basename $dev) - local p + local part=$(query_first_child $dev) - if is_dev_part_of_vg ${dev}1 $VG; then - Info "Device ${dev} is already partitioned and is part of volume group $VG" - continue + if [ -n "$part" ] && is_dev_part_of_vg ${part} $VG; then + Info "Device ${dev} is already partitioned and is part of volume group $VG" + continue fi # If signatures are being overridden, then simply return the disk as new @@ -699,8 +698,7 @@ scan_disks() { fi # If device does not have partitions, it is a new disk requiring processing. - p=$(awk "\$4 ~ /${basename}./ {print \$4}" /proc/partitions) - if [[ -z "$p" ]]; then + if [ -z "$part" ]; then new_disks="$dev $new_disks" continue fi @@ -717,12 +715,11 @@ create_partition_sfdisk(){ # TODO: # * Consider gpt, or unpartitioned volumes # * Error handling when partition(s) already exist - # * Deal with loop/nbd device names. See growpart code size=$(( $( awk "\$4 ~ /"$( basename $dev )"/ { print \$3 }" /proc/partitions ) * 2 - 2048 )) cat <