Skip to content

fix: only export data partition after filesystem setup - #813

Open
mjc wants to merge 1 commit into
sipeed:mainfrom
mjc:mjc/fix-data-partition-format
Open

fix: only export data partition after filesystem setup#813
mjc wants to merge 1 commit into
sipeed:mainfrom
mjc:mjc/fix-data-partition-format

Conversation

@mjc

@mjc mjc commented Jun 5, 2026

Copy link
Copy Markdown

Summary

Prevent NanoKVM from mounting or exporting /dev/mmcblk0p3 as the default data disk until the partition setup has actually completed.

The old first-boot flow could leave /etc/kvm.disk0 behind even if formatting or mounting failed. On later boots, that stale marker could make NanoKVM treat an unformatted or partially prepared partition as usable, then expose it through USB mass storage or the storage APIs.

This change makes the default data-partition state explicit:

  • Track interrupted formatting with /etc/kvm.disk0.formatting and retry it on the next boot.
  • Create /etc/kvm.disk0 only after a filesystem is confirmed and the partition mounts successfully.
  • Remove stale ready markers when p3 is missing, pending, or an unknown non-empty partition.
  • Gate the default p3 USB export, storage mount API, and VM virtual-disk state on the same readiness checks.
  • Preserve custom /boot/usb.disk0 backing files; only the built-in default p3 path is blocked while setup is incomplete.

Fixes #76
Fixes #242

Maintainer notes

This is intentionally scoped to the default data partition lifecycle. It avoids auto-formatting unknown non-empty partitions because they may contain user data, while still recovering empty legacy partitions that were previously marked ready.

There is overlap with #814 in S03usbdev. If that PR lands first, this branch should be rebased so the same readiness gate is applied to the refactored USB gadget setup.

Validation

Added focused regression coverage for the data-partition lifecycle:

  • tools/test-s01fs-data-disk.sh covers first-boot p3 creation, pending-format retries, mkfs/mount failure cleanup, legacy empty-partition recovery, unknown non-empty partition protection, custom backing preservation, and S03 USB mass-storage export gating.
  • server/service/storage/image_test.go covers storage API readiness checks so explicit /dev/mmcblk0p3 mounts are rejected until p3 is ready, while unmounts and custom image paths still work.
  • server/service/vm/virtualdisk/state_test.go covers VM virtual-disk state so the default data disk is not reported enabled while p3 is missing, pending, or missing its ready marker.
  • Makefile includes these regressions in the existing test target.

Copilot AI review requested due to automatic review settings June 5, 2026 22:10

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds a focused test harness for the S01fs init script and refactors S01fs to support safer/conditional data partition creation, formatting, and mounting with configurable paths for easier testing.

Changes:

  • Introduces tools/test-s01fs-data-disk.sh with stubbed system utilities to validate S01fs data-partition behavior.
  • Refactors kvmapp/system/init.d/S01fs to use overridable NANOKVM_* paths and adds logic to detect empty/unreadable partitions before formatting.
  • Adds marker-file management around formatting to indicate completion state.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 9 comments.

File Description
tools/test-s01fs-data-disk.sh Adds an integration-style shell test runner with stubbed commands and assertions for S01fs.
kvmapp/system/init.d/S01fs Parameterizes device/dir paths and adds partition emptiness detection + conditional mkfs/mount/marker behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread kvmapp/system/init.d/S01fs Outdated
Comment thread kvmapp/system/init.d/S01fs Outdated
Comment thread kvmapp/system/init.d/S01fs
Comment thread tools/test-s01fs-data-disk.sh
Comment thread tools/test-s01fs-data-disk.sh Outdated
Comment thread tools/test-s01fs-data-disk.sh Outdated
Comment thread tools/test-s01fs-data-disk.sh
Comment thread tools/test-s01fs-data-disk.sh
Comment thread tools/test-s01fs-data-disk.sh
@mjc
mjc marked this pull request as draft June 11, 2026 19:30
@mjc mjc changed the title fix: retry /data partition formatting when setup marker is stale fix: data partition formatting and export readiness Jun 11, 2026
@mjc
mjc force-pushed the mjc/fix-data-partition-format branch from 407882a to dfe19fe Compare June 11, 2026 21:12
@mjc mjc changed the title fix: data partition formatting and export readiness fix: only export data partition after filesystem setup Jun 19, 2026
@mjc
mjc marked this pull request as ready for review June 19, 2026 22:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

File Deletion Required for Full Version Device New NanoKVM - /dev/mmcblk0p3 - no filesytem

2 participants