fix(storage): fix FormatAndMount for container environment

Bug 1 (sfdisk): Add wipefs before sfdisk; change partition type from
,,,L (unsupported GPT shorthand) to ,, (default Linux GUID); add
--force --wipe always flags to handle existing partition tables.

Bug 2 (mount): Replace fstab-lookup mount with explicit device path:
  mount -t ext4 -o defaults,noatime /host-dev/sdb1 /mnt/hdd_1
Container's /etc/fstab is Docker's auto-generated one, not the host's.

Bug 3 (mount propagation): Change /mnt volume to long-form bind with
propagation: rshared so mounts created inside container propagate to
the host. Requires mount --make-rshared /mnt on host before restart.

Safety: Use req.MountName (ASCII) for ext4 -L label (16-byte limit;
UTF-8 display label stays in settings.json). Add findmnt verification
after mount. Improve progress messages with command details.

Smart partition: In storageInitAPIHandler, if disk already has exactly
1 empty partition (no filesystem), skip wipefs+sfdisk and format the
existing partition directly.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-02-17 11:38:52 +01:00
parent 252058aec0
commit 2064f32199
3 changed files with 54 additions and 17 deletions
@@ -201,6 +201,22 @@ func (s *Server) storageInitAPIHandler(w http.ResponseWriter, r *http.Request) {
SetDefault: req.SetDefault,
}
// Smart partition: if disk has exactly 1 partition with no filesystem,
// skip destructive repartitioning and format the existing partition directly.
if fmtReq.CreatePartition {
if scanResult, scanErr := storage.ScanDisks(); scanErr == nil {
for _, disk := range scanResult.AvailableDisks {
if disk.Path == req.DevicePath && len(disk.Partitions) == 1 && disk.Partitions[0].FSType == "" {
s.logger.Printf("[INFO] Disk %s has 1 empty partition (%s) — skipping repartition",
req.DevicePath, disk.Partitions[0].Path)
fmtReq.DevicePath = disk.Partitions[0].Path
fmtReq.CreatePartition = false
break
}
}
}
}
go func() {
progressCh := make(chan storage.FormatProgress, 32)
// Collect progress