-
Notifications
You must be signed in to change notification settings - Fork 571
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bring in e2fsprogs from pkgs. Initial support for ext* filesystems. Fixes: #9746 Signed-off-by: Noel Georgi <git@frezbo.dev>
- Loading branch information
Showing
6 changed files
with
162 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
v1.9.0-alpha.0-40-g567a14a | ||
v1.9.0-alpha.0-45-ga463a50 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// 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/google/uuid" | ||
"github.com/siderolabs/go-cmd/pkg/cmd" | ||
|
||
"github.com/siderolabs/talos/pkg/imager/utils" | ||
) | ||
|
||
// Ext4 creates a ext4 filesystem on the specified partition. | ||
func Ext4(partname string, setters ...Option) error { | ||
opts := NewDefaultOptions(setters...) | ||
|
||
var args []string | ||
|
||
if opts.Label != "" { | ||
args = append(args, "-L", opts.Label) | ||
} | ||
|
||
if opts.Force { | ||
args = append(args, "-F") | ||
} | ||
|
||
if opts.Reproducible { | ||
if epoch, ok, err := utils.SourceDateEpoch(); err != nil { | ||
return err | ||
} else if ok { | ||
// ref: https://gitlab.archlinux.org/archlinux/archiso/-/merge_requests/202/diffs | ||
detUUID := uuid.NewSHA1(uuid.MustParse("93a870ff-8565-4cf3-a67b-f47299271a96"), []byte(fmt.Sprintf("%d ext4 hash seed", epoch))) | ||
|
||
args = append(args, "-U", detUUID.String()) | ||
args = append(args, "-E", fmt.Sprintf("hash_seed=%s", detUUID.String())) | ||
} | ||
} | ||
|
||
args = append(args, partname) | ||
|
||
_, err := cmd.Run("mkfs.ext4", args...) | ||
|
||
return err | ||
} | ||
|
||
// Ext4Resize expands a ext4 filesystem to the maximum possible. | ||
func Ext4Resize(partname string) error { | ||
_, err := cmd.Run("resize2fs", partname) | ||
|
||
return err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
// 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_test | ||
|
||
import ( | ||
"crypto/sha256" | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/siderolabs/talos/pkg/makefs" | ||
) | ||
|
||
// TestExt4Reproducibility tests that the ext4 filesystem is reproducible. | ||
func TestExt4Reproducibility(t *testing.T) { | ||
hostname, _ := os.Hostname() //nolint:errcheck | ||
|
||
if hostname == "buildkitsandbox" { | ||
t.Skip("test not supported under buildkit as partition devices are not propagated from /dev") | ||
} | ||
|
||
t.Setenv("SOURCE_DATE_EPOCH", "1732109929") | ||
|
||
tmpDir := t.TempDir() | ||
|
||
tempFile := filepath.Join(tmpDir, "reproducible-ext4.img") | ||
|
||
if _, err := os.Create(tempFile); err != nil { | ||
t.Fatalf("failed to create file: %v", err) | ||
} | ||
|
||
if err := os.Truncate(tempFile, 64*1024); err != nil { | ||
t.Fatalf("failed to create file: %v", err) | ||
} | ||
|
||
if err := makefs.Ext4(tempFile, makefs.WithReproducible(true)); err != nil { | ||
t.Fatalf("failed to create ext4 filesystem: %v", err) | ||
} | ||
|
||
// get the file sha256 checksum | ||
fileData, err := os.ReadFile(tempFile) | ||
if err != nil { | ||
t.Fatalf("failed to read file: %v", err) | ||
} | ||
|
||
sum1 := sha256.Sum256(fileData) | ||
|
||
// create the filesystem again | ||
if err := makefs.Ext4(tempFile, makefs.WithReproducible(true), makefs.WithForce(true)); err != nil { | ||
t.Fatalf("failed to create ext4 filesystem: %v", err) | ||
} | ||
|
||
// get the file sha256 checksum | ||
fileData, err = os.ReadFile(tempFile) | ||
if err != nil { | ||
t.Fatalf("failed to read file: %v", err) | ||
} | ||
|
||
sum2 := sha256.Sum256(fileData) | ||
|
||
assert.Equal(t, sum1, sum2) | ||
} | ||
|
||
// TestExt4Resize tests that the ext4 filesystem can be resized. | ||
func TestExt4Resize(t *testing.T) { | ||
hostname, _ := os.Hostname() //nolint:errcheck | ||
|
||
if hostname == "buildkitsandbox" { | ||
t.Skip("test not supported under buildkit as partition devices are not propagated from /dev") | ||
} | ||
|
||
tmpDir := t.TempDir() | ||
|
||
tempFile := filepath.Join(tmpDir, "resize-ext4.img") | ||
|
||
if _, err := os.Create(tempFile); err != nil { | ||
t.Fatalf("failed to create file: %v", err) | ||
} | ||
|
||
if err := os.Truncate(tempFile, 64*1024); err != nil { | ||
t.Fatalf("failed to create file: %v", err) | ||
} | ||
|
||
if err := makefs.Ext4(tempFile); err != nil { | ||
t.Fatalf("failed to create ext4 filesystem: %v", err) | ||
} | ||
|
||
if err := os.Truncate(tempFile, 128*1024); err != nil { | ||
t.Fatalf("failed to resize file: %v", err) | ||
} | ||
|
||
assert.NoError(t, makefs.Ext4Resize(tempFile)) | ||
} |