Fix datactl for NVMe devices (#1550)

Add "p" in partition names ending with digit.

See https://community.home-assistant.io/t/datactl-help/276117 and https://unix.stackexchange.com/a/500910/334933
This commit is contained in:
Christian Knittl-Frank 2021-09-21 00:24:08 +02:00 committed by GitHub
parent 7d187405de
commit 1e7cd66165
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -45,8 +45,13 @@ uuid=a52a4597-fa3a-4851-aefd-2fbe9f849079, type=0FC63DAF-8483-4772-8E79-3D69D847
EOF
# Since we create a new partition table etc. we are guaranteed the target
# partition is partition 1
NEW_DEVICE_PART_SIZE=$(cat "/sys/class/block/$(basename "${NEW_DEVICE_ROOT}")1/size")
# partition is partition 1. If the device name ends with a digit, "p" is
# placed between device name and partition number.
case "${NEW_DEVICE_ROOT}" in
*[0-9]) NEW_DEVICE_PART="${NEW_DEVICE_ROOT}p1";;
*) NEW_DEVICE_PART="${NEW_DEVICE_ROOT}1";;
esac
NEW_DEVICE_PART_SIZE=$(cat "/sys/class/block/$(basename "${NEW_DEVICE_PART}")/size")
OLD_DEVICE_PART_SIZE=$(cat "/sys/class/block/$(basename "${DATA_DEVICE_CHILD}")/size")
if [ "${NEW_DEVICE_PART_SIZE}" -lt "${OLD_DEVICE_PART_SIZE}" ]; then