Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use shell script instead of OS Agent for device wipe #3916

Merged
merged 1 commit into from
Mar 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
30 changes: 30 additions & 0 deletions buildroot-external/rootfs-overlay/usr/libexec/haos-wipe
Original file line number Diff line number Diff line change
@@ -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