fix: extfs repair and resize

Fixes #10103

Signed-off-by: Andrey Smirnov <andrey.smirnov@siderolabs.com>
This commit is contained in:
Andrey Smirnov 2025-01-10 20:15:31 +04:00
parent 6e32ea5b7f
commit edf5c5e29b
No known key found for this signature in database
GPG Key ID: FE042E3D4085A811
4 changed files with 43 additions and 11 deletions

View File

@ -23,3 +23,4 @@ name: IMAGECACHE
provisioning:
diskSelector:
match: 'system_disk'
grow: true

View File

@ -12,10 +12,21 @@ import (
// repair a filesystem.
func (p *Point) repair(printerOptions PrinterOptions) error {
printerOptions.Printf("filesystem on %s needs cleaning, running repair", p.source)
var repairFunc func(partition string) error
if err := makefs.XFSRepair(p.source, p.fstype); err != nil {
return fmt.Errorf("xfs_repair: %w", err)
switch p.fstype {
case "ext4":
repairFunc = makefs.Ext4Repair
case "xfs":
repairFunc = makefs.XFSRepair
default:
return fmt.Errorf("unsupported filesystem type for repair: %s", p.fstype)
}
printerOptions.Printf("filesystem (%s) on %s needs cleaning, running repair", p.fstype, p.source)
if err := repairFunc(p.source); err != nil {
return fmt.Errorf("repair: %w", err)
}
printerOptions.Printf("filesystem successfully repaired on %s", p.source)

View File

@ -48,7 +48,25 @@ func Ext4(partname string, setters ...Option) error {
// Ext4Resize expands a ext4 filesystem to the maximum possible.
func Ext4Resize(partname string) error {
_, err := cmd.Run("resize2fs", partname)
// resizing the filesystem requires a check first
if err := Ext4Repair(partname); err != nil {
return fmt.Errorf("failed to repair before growing ext4 filesystem: %w", err)
}
return err
_, err := cmd.Run("resize2fs", partname)
if err != nil {
return fmt.Errorf("failed to grow ext4 filesystem: %w", err)
}
return nil
}
// Ext4Repair repairs a ext4 filesystem.
func Ext4Repair(partname string) error {
_, err := cmd.Run("e2fsck", "-f", "-p", partname)
if err != nil {
return fmt.Errorf("failed to repair ext4 filesystem: %w", err)
}
return nil
}

View File

@ -20,19 +20,21 @@ const (
// MUST be mounted, or this will fail.
func XFSGrow(partname string) error {
_, err := cmd.Run("xfs_growfs", "-d", partname)
if err != nil {
return fmt.Errorf("failed to grow XFS filesystem: %w", err)
}
return err
}
// XFSRepair repairs a XFS filesystem on the specified partition.
func XFSRepair(partname, fsType string) error {
if fsType != FilesystemTypeXFS {
return fmt.Errorf("unsupported filesystem type: %s", fsType)
func XFSRepair(partname string) error {
_, err := cmd.Run("xfs_repair", partname)
if err != nil {
return fmt.Errorf("error repairing XFS filesystem: %w", err)
}
_, err := cmd.Run("xfs_repair", partname)
return err
return nil
}
// XFS creates a XFS filesystem on the specified partition.