From 1e7cd661650112e7a35e4305e97c6b86dd4689f0 Mon Sep 17 00:00:00 2001 From: Christian Knittl-Frank Date: Tue, 21 Sep 2021 00:24:08 +0200 Subject: [PATCH] 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 --- buildroot-external/rootfs-overlay/usr/bin/datactl | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/buildroot-external/rootfs-overlay/usr/bin/datactl b/buildroot-external/rootfs-overlay/usr/bin/datactl index 594b5c63d..dd68cfcfd 100755 --- a/buildroot-external/rootfs-overlay/usr/bin/datactl +++ b/buildroot-external/rootfs-overlay/usr/bin/datactl @@ -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