diff --git a/buildroot-external/rootfs-overlay/usr/bin/datactl b/buildroot-external/rootfs-overlay/usr/bin/datactl index 4a31fb9f5..152b942f3 100755 --- a/buildroot-external/rootfs-overlay/usr/bin/datactl +++ b/buildroot-external/rootfs-overlay/usr/bin/datactl @@ -36,13 +36,11 @@ if [ "${1}" = "move" ] && [ -e "${2}" ]; then exit 1 fi - sgdisk --zap-all "${NEW_DEVICE_ROOT}" - sgdisk \ - -n "0:0:0" \ - -c "0:hassos-data-external" \ - -t "0:0FC63DAF-8483-4772-8E79-3D69D8477DE4" \ - -u "0:a52a4597-fa3a-4851-aefd-2fbe9f849079" \ - "${NEW_DEVICE_ROOT}" + # Create GPT partition table with a single data partition + cat << EOF | sfdisk --wipe-partitions=always --wipe=always "${NEW_DEVICE_ROOT}" +label: gpt +uuid=a52a4597-fa3a-4851-aefd-2fbe9f849079, type=0FC63DAF-8483-4772-8E79-3D69D8477DE4, name=hassos-data-external +EOF # Since we create a new partition table etc. we are guaranteed the target # partition is partition 1 @@ -51,7 +49,7 @@ if [ "${1}" = "move" ] && [ -e "${2}" ]; then if [ "${NEW_DEVICE_PART_SIZE}" -lt "${OLD_DEVICE_PART_SIZE}" ]; then echo "[INFO] Target device too small!" - sgdisk --zap-all "${NEW_DEVICE_ROOT}" + echo "label: gpt" | sfdisk "${NEW_DEVICE_ROOT}" exit 1 fi diff --git a/buildroot-external/rootfs-overlay/usr/lib/systemd/system/hassos-data.service b/buildroot-external/rootfs-overlay/usr/lib/systemd/system/hassos-data.service index f2b4660c0..6f8b2136f 100644 --- a/buildroot-external/rootfs-overlay/usr/lib/systemd/system/hassos-data.service +++ b/buildroot-external/rootfs-overlay/usr/lib/systemd/system/hassos-data.service @@ -3,7 +3,7 @@ Description=Home Assistant OS data partition migration DefaultDependencies=no RefuseManualStart=true RefuseManualStop=true -Requires=mnt-overlay.mount dev-disk-by\x2dlabel-hassos\x2ddata.device dev-disk-by\x2dpartlabel-hassos\x2ddata\x2dexternal.device +Requires=mnt-overlay.mount dev-disk-by\x2dlabel-hassos\x2ddata.device Wants=hassos-expand.service After=mnt-overlay.mount dev-disk-by\x2dlabel-hassos\x2ddata.device systemd-fsck@dev-disk-by\x2dlabel-hassos\x2ddata.service dev-disk-by\x2dpartlabel-hassos\x2ddata\x2dexternal.device Before=hassos-expand.service diff --git a/buildroot-external/rootfs-overlay/usr/libexec/hassos-data b/buildroot-external/rootfs-overlay/usr/libexec/hassos-data index 83a38c556..671f779b5 100755 --- a/buildroot-external/rootfs-overlay/usr/libexec/hassos-data +++ b/buildroot-external/rootfs-overlay/usr/libexec/hassos-data @@ -7,6 +7,16 @@ set -e # Rely on systemd-udev symlinks to find current data partition by fs label OLD_DEVICE_CHILD="$(readlink -f "/dev/disk/by-label/hassos-data")" +# We cannot rely on systemd Wants/Requires since this is evaluated before +# ConditionPathExists, and would make us wait for an external device on +# every boot. +# Instead, just start the unit here, which makes sure a device with the +# partlabel "hassos-data-external" is present. +if ! systemctl start "dev-disk-by\\x2dpartlabel-hassos\\x2ddata\\x2dexternal.device"; then + echo "[ERROR] External data device ${NEW_DEVICE} not found!" + exit 1 +fi + # Rely on systemd-udev symlinks to find external data partition by partlabel NEW_DEVICE_CHILD="$(readlink -f "/dev/disk/by-partlabel/hassos-data-external")"