Disks: allow persisting the primary mount from the UI; clean NTFS before mounting.

The Disks page treated /media/wrolpi as fully protected, so a
manually-mounted primary drive could not be persisted from the UI — and
the Persist toggle would have been wrong anyway: it wrote fstab.yaml,
which the wrolpi-mounts reconciler refuses to apply for the primary
mount (RESERVED_MOUNT_POINTS).  Route Persist for the primary mount to
the host's /etc/fstab (as onboarding does), report its entry in the
fstab list endpoint, and enable the toggle in both UIs while keeping
Unmount blocked.  Mounts outside /media (e.g. /boot/efi, which showed
an Unmount button) are now entirely untouchable System mounts.

Also:
- Run `ntfsfix -d` before mounting ntfs/ntfs3 volumes so the Windows
  dirty flag (Fast Startup, unclean unplug) cannot block mounting;
  non-fatal and a no-op on clean volumes.
- Add uid/gid fstab options for ntfs/ntfs3, matching mount_drive().
- Log reconcile diagnostics (desired/already-mounted/skipped with
  reasons) so an idle wrolpi-mounts run explains itself in the journal.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Roland 2026-07-05 14:50:56 -06:00
parent 85bd5619fa
commit c25902b92a
No known key found for this signature in database
GPG key ID: 1BA620CE6C9A4680
11 changed files with 251 additions and 18 deletions

View file

@ -178,6 +178,22 @@ def mount_drive(
uid, gid = get_wrolpi_uid_gid()
options = f"{options},uid={uid},gid={gid}"
# NTFS volumes are frequently left "dirty" (Windows Fast Startup, or an
# unclean unplug), which makes the driver refuse to mount them. ntfsfix -d
# clears the dirty flag and replays the journal; it is a no-op on clean
# volumes. Failure is non-fatal: the mount below reports the real error.
if fstype in ("ntfs", "ntfs3"):
try:
fix = subprocess.run(
["ntfsfix", "-d", device],
capture_output=True, text=True, timeout=60,
)
if fix.returncode != 0:
logger.warning("ntfsfix %s failed (mount will still be attempted): %s",
device, (fix.stderr or fix.stdout).strip())
except (subprocess.TimeoutExpired, OSError) as e:
logger.warning("Could not run ntfsfix on %s: %s", device, e)
# Build mount command
cmd = ["mount"]
if fstype:

View file

@ -164,9 +164,10 @@ def add_fstab_entry(
# This ensures we don't get duplicates when remounting the same device to a different location
entries = _filter_entry_with_comment(entries, mount_point=mount_point, device=device_spec)
# For exfat/vfat, add uid/gid options to set ownership to wrolpi user
# These filesystems don't support POSIX permissions natively
if fstype in ("exfat", "vfat"):
# For filesystems without native POSIX permissions, add uid/gid options to
# set ownership to the wrolpi user. Covers the FAT family and both NTFS
# drivers (ntfs-3g FUSE and the in-kernel ntfs3), matching mount_drive().
if fstype in ("exfat", "vfat", "ntfs", "ntfs3"):
uid, gid = get_wrolpi_uid_gid()
options = f"{options},uid={uid},gid={gid}"

View file

@ -16,7 +16,7 @@ import sys
from controller.lib.disks import get_wrolpi_uid_gid
from controller.lib.fstab_migration import migrate_etc_fstab
from controller.lib.mount_executor import SubprocessMountExecutor
from controller.lib.reconciler import Reconciler
from controller.lib.reconciler import DEFAULT_FSTAB_PATH, Reconciler
logger = logging.getLogger(__name__)
@ -48,11 +48,19 @@ def main(argv=None) -> int:
)
result = reconciler.apply()
if result.desired_count == 0:
logger.info("%s lists no mounts; nothing to reconcile.", DEFAULT_FSTAB_PATH)
logger.info(
"Reconcile complete: %d mounted, %d unmounted, %d mount failures, %d unmount failures",
"Reconcile complete: %d desired, %d already mounted, %d skipped, "
"%d mounted, %d unmounted, %d mount failures, %d unmount failures",
result.desired_count, len(result.already_mounted), len(result.skipped),
len(result.mounted), len(result.unmounted),
len(result.mount_failures), len(result.unmount_failures),
)
for mp in result.already_mounted:
logger.info("Already mounted: %s", mp)
for mp, reason in result.skipped:
logger.info("Skipped %s: %s", mp, reason)
for mp, err in result.mount_failures:
logger.error("Failed to mount %s: %s", mp, err)
for mp, err in result.unmount_failures:

View file

@ -54,6 +54,11 @@ class ReconcileResult:
mount_failures: list[tuple[str, str]] = field(default_factory=list)
unmount_failures: list[tuple[str, str]] = field(default_factory=list)
skipped: list[tuple[str, str]] = field(default_factory=list)
# Diagnostics: how many entries fstab.yaml listed, and which of them were
# satisfied before this run. Together with `skipped` these explain a
# "nothing to do" reconcile in the journal.
desired_count: int = 0
already_mounted: list[str] = field(default_factory=list)
@property
def all_succeeded(self) -> bool:
@ -87,6 +92,7 @@ class Reconciler:
desired = load_fstab(self._fstab_path)
live = self._executor.current_mount_points()
managed = self._read_managed()
result.desired_count = len(desired.mounts)
# 1. Mount each entry in fstab.yaml that isn't already live.
for entry in desired.mounts:
@ -98,6 +104,7 @@ class Reconciler:
# Already mounted — claim ownership so a later removal can
# safely unmount it.
managed.add(entry.mount_point)
result.already_mounted.append(entry.mount_point)
continue
options = self._inject_uid_gid(entry)
self._ensure_dir(entry.mount_point)