Fixing detection of HDD/SSD without partition (#1603)

This commit is contained in:
Christian Rotzoll 2020-09-30 13:55:04 +02:00 committed by rootzoll
parent a584d4687e
commit 666605d26b

View file

@ -79,18 +79,37 @@ if [ "$1" = "status" ]; then
echo "# SETUP INFO"
# find the HDD (biggest single partition)
hdd=""
sizeDataPartition=0
lsblk -o NAME,SIZE -b | grep "[^|*][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
testdevice=$(echo $line | cut -d " " -f 1)
testsize=$(echo $line | cut -d " " -f 2)
if [ ${testsize} -gt ${sizeDataPartition} ]; then
sizeDataPartition=${testsize}
hddDataPartition="${testdevice:2:4}"
hdd="${hddDataPartition:0:3}"
# cut line info into different informations
testname=$(echo $line | cut -d " " -f 1 | sed 's/[^a-z0-9]*//g')
testdevice=$(echo $testname | sed 's/[^a-z]*//g')
testpartition=$(echo $testname | grep -P '[a-z]{3,5}[0-9]{1}')
testsize=$(echo $line | sed "s/ */ /g" | cut -d " " -f 2 | sed 's/[^0-9]*//g')
#echo "# line($line)"
#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)
if [ ${#hdd} -eq 0 ]; then
hdd="${testdevice}"
fi
# if a partition was found - make sure to use the biggest
if [ ${#testpartition} -gt 0 ] && [ ${testsize} -gt ${sizeDataPartition} ]; then
sizeDataPartition=${testsize}
hddDataPartition="${testpartition}"
hdd="${testdevice}"
fi
done < .lsblk.tmp
rm -f .lsblk.tmp 1>/dev/null 2>/dev/null
if [ ${#hddDataPartition} -lt 4 ]; then
echo "# WARNING: found invalid partition (${ddDataPartition}) - redacting"
hddDataPartition=""
fi
isSSD=$(sudo cat /sys/block/${hdd}/queue/rotational 2>/dev/null | grep -c 0)
echo "hddCandidate='${hdd}'"
@ -125,7 +144,7 @@ if [ "$1" = "status" ]; then
mountError=""
sudo mkdir -p /mnt/hdd
if [ "${hddFormat}" = "ext4" ]; then
hddDataPartitionExt4=$hddDataPartition
hddDataPartitionExt4=$hddDataPartition
mountError=$(sudo mount /dev/${hddDataPartitionExt4} /mnt/hdd 2>&1)
isTempMounted=$(df | grep /mnt/hdd | grep -c ${hddDataPartitionExt4})
fi