Detection of HDD/SSD (#1625)

See #1621
This commit is contained in:
arno
2020-10-07 12:43:53 +02:00
committed by rootzoll
parent e3e68e3459
commit 263837f1e7

View File

@@ -81,6 +81,8 @@ if [ "$1" = "status" ]; then
# find the HDD (biggest single partition) # find the HDD (biggest single partition)
hdd="" hdd=""
sizeDataPartition=0 sizeDataPartition=0
OSPartition=$(sudo df /usr | grep dev | cut -d " " -f 1)
lsblk -o NAME,SIZE -b | grep -P "[s|v]d[a-z][0-9]?" > .lsblk.tmp lsblk -o NAME,SIZE -b | grep -P "[s|v]d[a-z][0-9]?" > .lsblk.tmp
while read line; do while read line; do
@@ -88,24 +90,40 @@ if [ "$1" = "status" ]; then
testname=$(echo $line | cut -d " " -f 1 | sed 's/[^a-z0-9]*//g') testname=$(echo $line | cut -d " " -f 1 | sed 's/[^a-z0-9]*//g')
testdevice=$(echo $testname | sed 's/[^a-z]*//g') testdevice=$(echo $testname | sed 's/[^a-z]*//g')
testpartition=$(echo $testname | grep -P '[a-z]{3,5}[0-9]{1}') testpartition=$(echo $testname | grep -P '[a-z]{3,5}[0-9]{1}')
if [ ${#testpartition} -gt 0 ]; then
testsize=$(echo $line | sed "s/ */ /g" | cut -d " " -f 2 | sed 's/[^0-9]*//g') testsize=$(echo $line | sed "s/ */ /g" | cut -d " " -f 2 | sed 's/[^0-9]*//g')
else
testsize=0
fi
#echo "# line($line)" #echo "# line($line)"
#echo "# testname(${testname}) testdevice(${testdevice}) testpartition(${testpartition}) testsize(${testsize})" #echo "# testname(${testname}) testdevice(${testdevice}) testpartition(${testpartition}) testsize(${testsize})"
# if no matching device found yet - take first for the beginning (just in case no partions at all) # count partitions
if [ ${#hdd} -eq 0 ]; then testpartitioncount=$(sudo fdisk -l | grep /dev/$testdevice | wc -l)
hdd="${testdevice}" # do not count line with disk info
fi testpartitioncount=$((testpartitioncount-1))
# if a partition was found - make sure to use the biggest if [ $testpartitioncount -gt 0 ]; then
if [ ${#testpartition} -gt 0 ] && [ ${testsize} -gt ${sizeDataPartition} ]; then # if a partition was found - make sure to skip OS partition
if [ "$testpartition" != "$OSPartition" ]; then
# make sure to use the biggest
if [ ${testsize} -gt ${sizeDataPartition} ]; then
sizeDataPartition=${testsize} sizeDataPartition=${testsize}
hddDataPartition="${testpartition}" hddDataPartition="${testpartition}"
hdd="${testdevice}" hdd="${testdevice}"
fi fi
fi
else
# Partion to be created is smaller than disk so this is not correct (but close)
sizeDataPartition=$(sudo fdisk -l /dev/$testdevice | grep GiB | cut -d " " -f 5)
hddDataPartition="${testdevice}1"
hdd="${testdevice}"
fi
done < .lsblk.tmp done < .lsblk.tmp
rm -f .lsblk.tmp 1>/dev/null 2>/dev/null rm -f .lsblk.tmp 1>/dev/null 2>/dev/null
if [ ${#hddDataPartition} -lt 4 ]; then if [ ${#hddDataPartition} -lt 4 ]; then
echo "# WARNING: found invalid partition (${ddDataPartition}) - redacting" echo "# WARNING: found invalid partition (${ddDataPartition}) - redacting"
hddDataPartition="" hddDataPartition=""
@@ -124,7 +142,10 @@ if [ "$1" = "status" ]; then
echo "hddGigaBytes=${hddDataPartitionGigaBytes}" echo "hddGigaBytes=${hddDataPartitionGigaBytes}"
# check if single drive with that size # check if single drive with that size
hddCount=$(lsblk -o NAME,SIZE -b | grep -c ${hddDataPartition}) hddCount=0
if [ ${#hddDataPartition} -gt 0 ]; then
hddCount=1
fi
echo "hddCount=${hddCount}" echo "hddCount=${hddCount}"
# check format of devices partition # check format of devices partition