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

Conversation

sairon
Copy link
Member

@sairon sairon commented Mar 6, 2025

Use simple shell script to perform device wipe instead of calling OS Agent to do that through the UDisks2 API. While it might have been a good idea to use high level interface for that back then, it turns out it causes more issues than the benefits it could bring.

Main problem currently is that the OS Agent needs to read sysctl variables, but those are only set after mounting the overlay partition. But at the same time, the overlay partition can't be mounted if we want to wipe it - this creates a dependency cycle through the haos-agent.service.

To get rid of the cycle and simplify things, use a shell script doing basically the same what the OS Agent does. Since the wipe functionality only makes sense to be implemented on HAOS targets (not on Supervised), there's little point of having it in higher layer of abstraction that OS Agent provides.

It should be also checked if changes from #1291 are needed anymore, as the driving factor for those have been probably the wipe feature in OS Agent too, but at this point they seem to be harmless.

Summary by CodeRabbit

  • New Features
    • Introduced a secure wipe tool that safely validates and formats specific partitions, ensuring proper conditions before execution.
  • Refactor
    • Streamlined the wipe process by updating service startup order and removing unnecessary dependencies, simplifying execution and enhancing reliability.

Use simple shell script to perform device wipe instead of calling OS Agent to
do that through the UDisks2 API. While it might have been a good idea to use
high level interface for that back then, it turns out it causes more issues
than the benefits it could bring.

Main problem currently is that the OS Agent needs to read sysctl variables, but
those are only set after mounting the overlay partition. But at the same time,
the overlay partition can't be mounted if we want to wipe it - this creates a
dependency cycle through the haos-agent.service.

To get rid of the cycle and simplify things, use a shell script doing basically
the same what the OS Agent does. Since the wipe functionality only makes sense
to be implemented on HAOS targets (not on Supervised), there's little point of
having it in higher layer of abstraction that OS Agent provides.

It should be also checked if changes from #1291 are needed anymore, as the
driving factor for those have been probably the wipe feature in OS Agent too,
but at this point they seem to be harmless.
@sairon sairon added the os label Mar 6, 2025
@sairon sairon requested a review from agners March 6, 2025 14:29
Copy link

coderabbitai bot commented Mar 6, 2025

📝 Walkthrough

Walkthrough

This pull request updates the behavior of the haos-wipe functionality. In the systemd service file, dependency and startup ordering have been modified, and the execution command now directly calls a new wiping script instead of using a bus command. The new script verifies the presence and mount status of designated partitions before formatting them and updating the boot command line file.

Changes

File Path Change Summary
buildroot-external/.../system/haos-wipe.service Removed Requires=haos-agent.service; changed After=haos-agent.service to After=mnt-boot.mount; updated ExecStart from a busctl command to executing /usr/libexec/haos-wipe; removed ExecStartPost command.
buildroot-external/.../haos-wipe New shell script added. It checks the existence and mount status of overlay and data partitions, formats them with ext4 if valid, and removes a flag from cmdline.txt.

Sequence Diagram(s)

sequenceDiagram
    participant Sysd as Systemd
    participant Service as haos-wipe.service
    participant Script as haos-wipe script
    participant Overlay as Overlay Partition
    participant Data as Data Partition
    participant Boot as /mnt/boot/cmdline.txt

    Sysd->>Service: Start haos-wipe.service (after mnt-boot.mount)
    Service->>Script: Execute /usr/libexec/haos-wipe
    Script->>Overlay: Verify overlay partition (existence & unmounted)
    alt Overlay check fails
        Script-->>Service: Exit with error
    else Overlay valid
        Script->>Data: Verify data partition (existence & unmounted)
        alt Data check fails
            Script-->>Service: Exit with error
        else Data valid
            Script->>Data: Format data partition (ext4 options)
            Script->>Overlay: Format overlay partition (ext4 options)
            Script->>Boot: Remove wipe flag from cmdline.txt
            Script-->>Service: Complete execution
        end
    end
Loading

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai or @coderabbitai title anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
buildroot-external/rootfs-overlay/usr/libexec/haos-wipe (1)

30-30: Consider adding error handling for the cmdline.txt modification.

The script assumes /mnt/boot/cmdline.txt exists and is writable. Consider adding a check to verify the file exists before attempting to modify it.

- /usr/bin/sed -i 's/\s*haos.wipe=1//g' /mnt/boot/cmdline.txt
+ if [ -f /mnt/boot/cmdline.txt ]; then
+     /usr/bin/sed -i 's/\s*haos.wipe=1//g' /mnt/boot/cmdline.txt
+ else
+     echo "[ERROR] Unable to find cmdline.txt in boot partition"
+     exit 1
+ fi
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 36d9057 and 483ec91.

📒 Files selected for processing (2)
  • buildroot-external/rootfs-overlay/usr/lib/systemd/system/haos-wipe.service (1 hunks)
  • buildroot-external/rootfs-overlay/usr/libexec/haos-wipe (1 hunks)
🔇 Additional comments (6)
buildroot-external/rootfs-overlay/usr/libexec/haos-wipe (3)

1-31: The haos-wipe script looks robust and well-structured.

The script follows good practices with proper error checking and clear messages. It verifies partitions exist and aren't mounted before wiping them, which is critical for safety.


7-21: Good safety checks before formatting partitions.

The script correctly verifies both existence and mount status of partitions before attempting to format them, preventing potential data loss or system corruption.


24-27:

❓ Verification inconclusive

Verify the formatting parameters align with system requirements.

The script uses specific formatting parameters like -I 256 for the overlay partition and optimization flags. Make sure these match the expected filesystem requirements for your system.


🏁 Script executed:

#!/bin/bash
# Check existing partition settings to ensure new formatting matches requirements

echo "Checking current overlay partition settings:"
if [ -b /dev/disk/by-label/hassos-overlay ]; then
  dumpe2fs -h /dev/disk/by-label/hassos-overlay 2>/dev/null | grep -E "Inode size:|Filesystem features:"
fi

echo "Checking current data partition settings:"
if [ -b /dev/disk/by-label/hassos-data ]; then
  dumpe2fs -h /dev/disk/by-label/hassos-data 2>/dev/null | grep -E "Inode size:|Filesystem features:"
fi

Length of output: 282


Action: Validate Filesystem Formatting Parameters

The mkfs.ext4 commands currently use parameters such as -I 256 (for the overlay partition) along with optimization flags. The verification script did not return partition details—most likely because neither /dev/disk/by-label/hassos-overlay nor /dev/disk/by-label/hassos-data exists in the test environment. This means we couldn’t automatically confirm that the specified formatting options match your system's current filesystem requirements.

  • Please manually verify in your production or staging environment that using -I 256 along with the lazy initialization flags is correct for the hassos-overlay partition.
  • Ensure that similar optimization flags for the hassos-data partition align with expected filesystem features.
  • Revisit the conditions for the existence of these partitions in the script to avoid silent failures if they are missing.
buildroot-external/rootfs-overlay/usr/lib/systemd/system/haos-wipe.service (3)

7-7: Appropriate dependency change for the wipe service.

Changing from After=haos-agent.service to After=mnt-boot.mount correctly resolves the dependency cycle mentioned in the PR objectives. This ensures the service starts after the boot partition is mounted but doesn't require the agent.


13-13: Simplified ExecStart command improves maintainability.

Replacing the busctl command with a direct script execution makes the service cleaner and easier to understand. This approach properly separates concerns by moving all wipe logic to the dedicated script.


1-17:

❓ Verification inconclusive

Verify that all needed dependencies are still preserved.

The removal of the Requires=haos-agent.service dependency is intentional as part of migrating away from the OS Agent. However, ensure that the service still has all necessary dependencies for proper operation.


🏁 Script executed:

#!/bin/bash
# Check dependencies and ordering in the new service setup

echo "Verifying service ordering:"
if systemctl cat mnt-boot.mount &>/dev/null; then
  echo "Boot mount service exists."
else
  echo "Warning: mnt-boot.mount service not found in test environment."
fi

echo "Checking partition mounting services:"
if systemctl cat mnt-data.mount mnt-overlay.mount &>/dev/null; then
  echo "Partition mount services exist."
else
  echo "Warning: mount services not found in test environment."
fi

echo "Examining if wipe flag is used elsewhere:"
grep -r "haos.wipe" --include="*.service" /usr/lib/systemd/system/ || echo "No other services reference the wipe flag"

Length of output: 794


Dependency Verification for haos-wipe Service – Please Confirm Production Dependencies

The configuration intentionally removes the Requires=haos-agent.service dependency as part of migrating away from the OS Agent. However, the verification script indicated that the mounting services (mnt-boot.mount, mnt-data.mount, and mnt-overlay.mount) were not found in the test environment. This might be due to limitations in the test setup rather than an actual misconfiguration.

  • Action Items:
    • Confirm in your production (or packaging) environment that mnt-boot.mount is available.
    • Verify that both mnt-data.mount and mnt-overlay.mount are defined and activated.
    • Ensure that the haos.wipe=1 condition reliably triggers the haos-wipe service without unintended side effects.

Please double-check these dependencies to ensure proper service operation.

@sairon sairon merged commit 6c4f32a into dev Mar 6, 2025
3 checks passed
@sairon sairon deleted the haos-wipe-script branch March 6, 2025 15:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants