Avoid waiting for external drive unnecessarily (#1066)

* Avoid waiting for external drive unnecessarily

Even though the condition to start hassos-data.service is not met (the
file /mnt/overlay/data-move is not there by default), it seems that
systemd waits for the dependencies for hassos-data.service. Don't
Require or Wants any dependencies which might not be present by
default.

* Use systemd to wait for partition using partlabel device

* Use sfdisk which allows to wipe filesystem signatures

Even though we zap the partition table using sgdisk, the file system
superblock (which contains the file system label) does survive. This
can cause problems when trying to reuse a disk previously already
labeled using hassos-data: It might take precendence on next boot
over the existing data partition on the eMMC.

Make sure to clean all file system signatures using sfdisk.
This commit is contained in:
Stefan Agner 2020-12-08 01:11:00 +01:00 committed by GitHub
parent 162084082e
commit 1a8f9ca2e3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 9 deletions

View File

@ -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

View File

@ -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

View File

@ -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")"