mirror of
https://github.com/siderolabs/talos.git
synced 2025-12-06 18:11:33 +01:00
fix: extfs repair and resize
Fixes #10103 Signed-off-by: Andrey Smirnov <andrey.smirnov@siderolabs.com>
This commit is contained in:
parent
6e32ea5b7f
commit
edf5c5e29b
@ -23,3 +23,4 @@ name: IMAGECACHE
|
|||||||
provisioning:
|
provisioning:
|
||||||
diskSelector:
|
diskSelector:
|
||||||
match: 'system_disk'
|
match: 'system_disk'
|
||||||
|
grow: true
|
||||||
|
|||||||
@ -12,10 +12,21 @@ import (
|
|||||||
|
|
||||||
// repair a filesystem.
|
// repair a filesystem.
|
||||||
func (p *Point) repair(printerOptions PrinterOptions) error {
|
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 {
|
switch p.fstype {
|
||||||
return fmt.Errorf("xfs_repair: %w", err)
|
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)
|
printerOptions.Printf("filesystem successfully repaired on %s", p.source)
|
||||||
|
|||||||
@ -48,7 +48,25 @@ func Ext4(partname string, setters ...Option) error {
|
|||||||
|
|
||||||
// Ext4Resize expands a ext4 filesystem to the maximum possible.
|
// Ext4Resize expands a ext4 filesystem to the maximum possible.
|
||||||
func Ext4Resize(partname string) error {
|
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
|
||||||
}
|
}
|
||||||
|
|||||||
@ -20,19 +20,21 @@ const (
|
|||||||
// MUST be mounted, or this will fail.
|
// MUST be mounted, or this will fail.
|
||||||
func XFSGrow(partname string) error {
|
func XFSGrow(partname string) error {
|
||||||
_, err := cmd.Run("xfs_growfs", "-d", partname)
|
_, err := cmd.Run("xfs_growfs", "-d", partname)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to grow XFS filesystem: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// XFSRepair repairs a XFS filesystem on the specified partition.
|
// XFSRepair repairs a XFS filesystem on the specified partition.
|
||||||
func XFSRepair(partname, fsType string) error {
|
func XFSRepair(partname string) error {
|
||||||
if fsType != FilesystemTypeXFS {
|
_, err := cmd.Run("xfs_repair", partname)
|
||||||
return fmt.Errorf("unsupported filesystem type: %s", fsType)
|
if err != nil {
|
||||||
|
return fmt.Errorf("error repairing XFS filesystem: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err := cmd.Run("xfs_repair", partname)
|
return nil
|
||||||
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// XFS creates a XFS filesystem on the specified partition.
|
// XFS creates a XFS filesystem on the specified partition.
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user