1
0
mirror of https://github.com/home-assistant/operating-system.git synced 2026-04-19 08:19:50 +01:00
Files
operating-system/buildroot-external/rootfs-overlay/usr/libexec/hassos-data
Stefan Agner 46bb12844f Rewrite datactl command (#1046)
* Rewrite datactl command

Prepare the target partition as part of the datactl command. Rely on
partlabel for the target disk since we are always using GPT on the
target disk. Use systemd and partlabel mechanism to wait and find
the target data disk. Keep using the file system label to identify
the source disk.

Also use e2image instead of raw dd to move data. This should
speed up the processes significantly.

* Fix corner case when reusing same disk again
2020-12-03 20:05:02 +01:00

25 lines
1.0 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")"
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!"
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"