diff --git a/buildroot-external/rootfs-overlay/usr/lib/systemd/system/haos-wipe.service b/buildroot-external/rootfs-overlay/usr/lib/systemd/system/haos-wipe.service index 8df2b5647..c15119f53 100644 --- a/buildroot-external/rootfs-overlay/usr/lib/systemd/system/haos-wipe.service +++ b/buildroot-external/rootfs-overlay/usr/lib/systemd/system/haos-wipe.service @@ -4,15 +4,13 @@ DefaultDependencies=no RefuseManualStart=true RefuseManualStop=true Wants=mnt-boot.mount -Requires=haos-agent.service -After=haos-agent.service mnt-boot.mount +After=mnt-boot.mount Before=mnt-data.mount mnt-overlay.mount ConditionKernelCommandLine=haos.wipe=1 [Service] Type=oneshot -ExecStart=/usr/bin/busctl --verbose --timeout=1h call io.hass.os /io/hass/os/System io.hass.os.System WipeDevice -ExecStartPost=/usr/bin/sed -i 's/\s*haos.wipe=1//g' /mnt/boot/cmdline.txt +ExecStart=/usr/libexec/haos-wipe [Install] WantedBy=sysinit.target diff --git a/buildroot-external/rootfs-overlay/usr/libexec/haos-wipe b/buildroot-external/rootfs-overlay/usr/libexec/haos-wipe new file mode 100755 index 000000000..7a1c24892 --- /dev/null +++ b/buildroot-external/rootfs-overlay/usr/libexec/haos-wipe @@ -0,0 +1,30 @@ +#!/bin/sh +set -e + +PARTITION_OVERLAY="/dev/disk/by-label/hassos-overlay" +PARTITION_DATA="/dev/disk/by-label/hassos-data" + +if [ ! -b "$PARTITION_OVERLAY" ]; then + echo "[ERROR] Overlay partition not found" + exit 1 +elif findmnt "$PARTITION_OVERLAY" > /dev/null; then + echo "[ERROR] Unable to wipe overlay partition while it is already mounted" + exit 1 +fi + +if [ ! -b "$PARTITION_DATA" ]; then + echo "[ERROR] Data partition not found" + exit 1 +elif findmnt "$PARTITION_DATA" > /dev/null; then + echo "[ERROR] Unable to wipe data partition while it is already mounted" + exit 1 +fi + +echo "[INFO] Wiping data partition" +mkfs.ext4 -L "hassos-data" -E lazy_itable_init=0,lazy_journal_init=0 "$PARTITION_DATA" + +echo "[INFO] Wiping overlay partition" +mkfs.ext4 -L "hassos-overlay" -I 256 -E lazy_itable_init=0,lazy_journal_init=0 "$PARTITION_OVERLAY" + +echo "[INFO] Removing wipe flag from cmdline.txt" +/usr/bin/sed -i 's/\s*haos.wipe=1//g' /mnt/boot/cmdline.txt