Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add btrfs partition support #173

Merged
merged 1 commit into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion pkg/plugins/layout.go
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,31 @@ func (dev Disk) expandFilesystem(device string, console Console, l logger.Interf
if err != nil {
return out, err
}
case "btrfs":
// to grow an btrfs fs it needs to be mounted :/
tmpDir, err := os.MkdirTemp("", "yip")
defer os.Remove(tmpDir)

if err != nil {
return out, err
}
out, err = console.Run(fmt.Sprintf("mount -t btrfs %s %s", device, tmpDir))
if err != nil {
return out, err
}
out, err = console.Run(fmt.Sprintf("btrfs filesystem resize max %s", tmpDir))
if err != nil {
// If we error out, try to umount the dir to not leave it hanging
out, err2 := console.Run(fmt.Sprintf("umount %s", tmpDir))
if err2 != nil {
return out, err2
}
return out, err
}
out, err = console.Run(fmt.Sprintf("umount %s", tmpDir))
if err != nil {
return out, err
}
default:
return "", errors.New(fmt.Sprintf("Could not find filesystem for %s, not resizing the filesystem", device))
}
Expand Down Expand Up @@ -794,7 +819,7 @@ func (gd *GdiskCall) ExpandPTable() {
func (mkfs MkfsCall) buildOptions() ([]string, error) {
opts := []string{}

linuxFS, _ := regexp.MatchString("ext[2-4]|xfs", mkfs.part.FileSystem)
linuxFS, _ := regexp.MatchString("ext[2-4]|xfs|btrfs", mkfs.part.FileSystem)
fatFS, _ := regexp.MatchString("fat|vfat", mkfs.part.FileSystem)

switch {
Expand Down
2 changes: 1 addition & 1 deletion pkg/plugins/layout_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ var _ = Describe("Layout", func() {

It("Works on an non-xfs fs with a label longer than 12 chars", func() {
label = "LABEL_TOO_LONG_FOR_XFS"
for _, filesystem := range []string{"ext2", "ext3", "ext4"} {
for _, filesystem := range []string{"ext2", "ext3", "ext4", "btrfs"} {
testConsole := console.New()
testConsole.AddCmds(CmdsAddPartByLabel(filesystem))
err := Layout(l, schema.Stage{
Expand Down
Loading