talos/pkg/makefs/xfs.go
Andrey Smirnov 018086d1fa refactor: extract blockdevice library
Library `blockdevice` was extracted as `talos-systems/go-blockdevice`,
this PR finalizes the move by removing Talos copy of it.

Some functions around `mkfs`/`growfs` were extracted as `makefs`
package, as they depend on `cmd` package.

Signed-off-by: Andrey Smirnov <smirnov.andrey@gmail.com>
2020-10-05 11:18:43 -07:00

46 lines
1015 B
Go

// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
package makefs
import (
"fmt"
"github.com/talos-systems/talos/pkg/cmd"
)
// XFSGrow expands a XFS filesystem to the maximum possible. The partition
// MUST be mounted, or this will fail.
func XFSGrow(partname string) error {
_, err := cmd.Run("xfs_growfs", "-d", partname)
return err
}
// XFS creates a XFS filesystem on the specified partition.
func XFS(partname string, setters ...Option) error {
if partname == "" {
return fmt.Errorf("missing path to disk")
}
opts := NewDefaultOptions(setters...)
// The ftype=1 naming option is required by overlayfs.
args := []string{"-n", "ftype=1"}
if opts.Force {
args = append(args, "-f")
}
if opts.Label != "" {
args = append(args, "-L", opts.Label)
}
args = append(args, partname)
_, err := cmd.Run("mkfs.xfs", args...)
return err
}