mirror of
https://github.com/home-assistant/operating-system.git
synced 2026-04-20 08:49:09 +01:00
* Make the datactl command more robust Validate target disk (partition) size to avoid a copy attempt which will fail. If e2image operation fails, make sure the leftover copy is not regonized as data partition. * Fix hassos-data service device unit dependencies
34 lines
1.5 KiB
Bash
Executable File
34 lines
1.5 KiB
Bash
Executable File
#!/bin/sh
|
|
# ==============================================================================
|
|
# Home Assistant OS data partition migration script
|
|
# ==============================================================================
|
|
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")"
|
|
|
|
# Rely on systemd-udev symlinks to find external data partition by partlabel
|
|
NEW_DEVICE_CHILD="$(readlink -f "/dev/disk/by-partlabel/hassos-data-external")"
|
|
|
|
NEW_DEVICE_PART_SIZE=$(cat "/sys/class/block/$(basename "${NEW_DEVICE_CHILD}")/size")
|
|
OLD_DEVICE_PART_SIZE=$(cat "/sys/class/block/$(basename "${OLD_DEVICE_CHILD}")/size")
|
|
if [ "${NEW_DEVICE_PART_SIZE}" -lt "${OLD_DEVICE_PART_SIZE}" ]; then
|
|
echo "[INFO] Target device too small!"
|
|
exit 1
|
|
fi
|
|
|
|
echo "[INFO] Moving data from ${OLD_DEVICE_CHILD} to ${NEW_DEVICE_CHILD}"
|
|
if ! e2image -ra -p "${OLD_DEVICE_CHILD}" "${NEW_DEVICE_CHILD}"; then
|
|
echo "[ERROR] Copying data partition to external device failed!"
|
|
# Rename partition to make sure HAOS does not try to mount a failed copy attempt.
|
|
e2label "${NEW_DEVICE_CHILD}" hassos-data-failed || true
|
|
exit 1
|
|
fi
|
|
|
|
# At this point we have two partition with the same fs label. Make sure
|
|
# to rename the internal partition so we won't mount it anymore.
|
|
echo "[INFO] Rename old hassos-data partition ${OLD_DEVICE_CHILD}"
|
|
e2label "${OLD_DEVICE_CHILD}" hassos-data-old
|
|
|
|
echo "[INFO] Data move has been completed successfully"
|