diff --git a/files/diskspreparation.sh b/files/diskspreparation.sh index fe11121675657b13fa8d43cd72350946b6f6f2b7..335b5542da448a55c21fa493b8b4b1eb9253752b 100755 --- a/files/diskspreparation.sh +++ b/files/diskspreparation.sh @@ -206,6 +206,16 @@ setDiskPartitionFlags() { return } +# getPartitionDeviceByIndex - returns the partition device of a disk by index +# parameter: +# $1 - name of the disk device +# $2 - index of the disk partition +# return: +# partition device of the given disk on STDOUT +getPartitionDeviceByIndex() { + fdisk -l /dev/$1 2>/dev/null | sed -n -e "s/^\(\/dev[^ ]*\) .*$/\1/p" | sed -n "$2p" +} + # formatDiskPartion - format a partition # parameter: # $1 - disk device name @@ -216,9 +226,11 @@ setDiskPartitionFlags() { # 1 - error occurred # 2 - unknown filesystem formatDiskPartion() { - local device="/dev/$1$2" + local device local retval=0 + device=$(getPartitionDeviceByIndex $1 $2) + case $(echo $3 | tr "[A-Z]" "[a-z]") in "ext4") mkfs.ext4 -q -F ${device} >/dev/null|| retval=1 ;; "ext3") mkfs.ext3 -q -F ${device} >/dev/null || retval=1 ;; @@ -283,6 +295,7 @@ generateFSTab() { local dmp local pass local dev + local partdev if [ $# -eq 3 ]; then @@ -296,8 +309,9 @@ generateFSTab() { idx=1 for part in $(eval "for p in \${DISK_$(echo ${disk} | tr [a-z] [A-Z])_PARTITIONS[@]}; do echo \$p; done ") do - uuid=$(blkid -s UUID -o value /dev/${disk}${idx}) - fs=$(blkid -s TYPE -o value /dev/${disk}${idx}) + partdev=$(getPartitionDeviceByIndex ${disk} ${idx}) + uuid=$(blkid -s UUID -o value ${partdev}) + fs=$(blkid -s TYPE -o value ${partdev}) mntpnt=$(echo ${part} | cut -f 3 -d ";") opts=$(echo ${part} | cut -f 4 -d ";") dmp=$(echo ${part} | cut -f 5 -d ";") @@ -313,10 +327,10 @@ generateFSTab() { case ${2} in "uuid") dev="UUID=${uuid}" ;; *) - dev="/dev/${disk}${idx}" + dev=${partdev} ;; esac - echo "#/dev/${disk}${idx}" >>$1 + echo "#${dev}" >>$1 if [ "${mntpnt}" != "none" ]; then echo -e "${dev} ${mntpntpfx}${mntpnt} ${fs} ${opts} ${dmp} ${pass}\n" >>$1