diff --git a/hack/test/patches/image-cache.yaml b/hack/test/patches/image-cache.yaml index 76b1585856..4d05807a28 100644 --- a/hack/test/patches/image-cache.yaml +++ b/hack/test/patches/image-cache.yaml @@ -23,3 +23,4 @@ name: IMAGECACHE provisioning: diskSelector: match: 'system_disk' + grow: true diff --git a/internal/pkg/mount/v2/repair.go b/internal/pkg/mount/v2/repair.go index 06ffacad90..2991063b03 100644 --- a/internal/pkg/mount/v2/repair.go +++ b/internal/pkg/mount/v2/repair.go @@ -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) diff --git a/pkg/makefs/ext4.go b/pkg/makefs/ext4.go index 404a1c3228..0e3be8526b 100644 --- a/pkg/makefs/ext4.go +++ b/pkg/makefs/ext4.go @@ -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 { + // 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) + } + _, err := cmd.Run("resize2fs", partname) + if err != nil { + return fmt.Errorf("failed to grow ext4 filesystem: %w", err) + } - return 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 } diff --git a/pkg/makefs/xfs.go b/pkg/makefs/xfs.go index 8f968e6eb0..c9a9dee39a 100644 --- a/pkg/makefs/xfs.go +++ b/pkg/makefs/xfs.go @@ -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) + } - return err + return nil } // XFS creates a XFS filesystem on the specified partition.