Skip to content

Commit

Permalink
Implement lz4 image compression
Browse files Browse the repository at this point in the history
Kernel needs "legacy lz4 frame format" that got implemented here
pierrec/lz4#118

Closes #34
  • Loading branch information
anatol committed Mar 19, 2021
1 parent e448888 commit a4ea5b0
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 4 deletions.
2 changes: 1 addition & 1 deletion docs/manpage.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Booster advantages:

* `modules` is a comma-separates list of extra modules to add to the generated image. One can use a module name or a path relative to the modules dir (/usr/lib/modules/$KERNEL_VERSION). If the path ends with slash symbol (/) then it considered a directory and all modules from this directory needs to be added recursively. booster also takes modules dependencies into account, all dependencies of the specified modules will be added to the image as well.

* `compression` is a flag that specifies compression for the output initramfs file. Currently supported algorithms are "zstd", "gzip", "xz", "none". If no option specified then "zstd" is used as a default compression.
* `compression` is a flag that specifies compression for the output initramfs file. Currently supported algorithms are "zstd", "gzip", "xz", "lz4", "none". If no option specified then "zstd" is used as a default compression.

* `mount_timeout` timeout for waiting for root filesystem to appear. The field format is a decimal number and then unit number. Valid units are "s", "m", "h". If no value specified then default timeout (3 minutes) is used. To disable the timeout completely specify "0s".

Expand Down
7 changes: 7 additions & 0 deletions generator/generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,8 @@ func verifyCompressedFile(compression string, file string) error {
verifyCmd = exec.Command("gzip", "--test", file)
case "xz":
verifyCmd = exec.Command("xz", "--test", file)
case "lz4":
verifyCmd = exec.Command("lz4", "--test", file)
default:
return fmt.Errorf("Unknown compression: %s", compression)
}
Expand Down Expand Up @@ -321,6 +323,10 @@ func testXzImageCompression(t *testing.T) {
createTestInitRamfs(t, &options{compression: "xz"})
}

func testLz4ImageCompression(t *testing.T) {
createTestInitRamfs(t, &options{compression: "lz4"})
}

func testUniversalMode(t *testing.T) {
opts := options{
universal: true,
Expand Down Expand Up @@ -523,6 +529,7 @@ func TestGenerator(t *testing.T) {
t.Run("ZstdImageCompression", testZstdImageCompression)
t.Run("GzipImageCompression", testGzipImageCompression)
t.Run("XzImageCompression", testXzImageCompression)
t.Run("Lz4ImageCompression", testLz4ImageCompression)
t.Run("UniversalMode", testUniversalMode)
t.Run("HostMode", testHostMode)
t.Run("SoftDepenencies", testSoftDependencies)
Expand Down
2 changes: 1 addition & 1 deletion generator/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/frankban/quicktest v1.11.3 // indirect
github.com/google/renameio v1.0.0
github.com/klauspost/compress v1.11.12
github.com/pierrec/lz4 v2.6.0+incompatible
github.com/pierrec/lz4 v2.6.1-0.20210319102207-f414fbbaf285+incompatible
github.com/ulikunitz/xz v0.5.10
github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8
golang.org/x/sys v0.0.0-20210317091845-390168757d9c
Expand Down
4 changes: 2 additions & 2 deletions generator/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfn
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/pierrec/lz4 v2.6.0+incompatible h1:Ix9yFKn1nSPBLFl/yZknTp8TU5G4Ps0JDmguYK6iH1A=
github.com/pierrec/lz4 v2.6.0+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY=
github.com/pierrec/lz4 v2.6.1-0.20210319102207-f414fbbaf285+incompatible h1:iq/u+BKDwfi5ZUrtar8zyL8asYa5mCZLYoY5R1qGIgc=
github.com/pierrec/lz4 v2.6.1-0.20210319102207-f414fbbaf285+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY=
github.com/ulikunitz/xz v0.5.10 h1:t92gobL9l3HE202wg3rlk19F6X+JOxl9BBrCCMYEYd8=
github.com/ulikunitz/xz v0.5.10/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14=
github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8 h1:nIPpBwaJSVYIxUFsDv3M8ofmx9yWTog9BfvIu0q41lo=
Expand Down
3 changes: 3 additions & 0 deletions generator/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/google/renameio"
"github.com/klauspost/compress/zstd"
"github.com/ulikunitz/xz"
"github.com/pierrec/lz4"
)

type Image struct {
Expand Down Expand Up @@ -50,6 +51,8 @@ func NewImage(path string, compression string, stripBinaries bool) (*Image, erro
return nil, err
}
compressor, err = conf.NewWriter(file)
case "lz4":
compressor = lz4.NewWriterLegacy(file)
case "none":
compressor = file
default:
Expand Down
7 changes: 7 additions & 0 deletions tests/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ func generateInitRamfs(opts Opts) (string, error) {
verifyCmd = exec.Command("gzip", "--test", output)
case "xz":
verifyCmd = exec.Command("xz", "--test", output)
case "lz4":
verifyCmd = exec.Command("lz4", "--test", output)
default:
return "", fmt.Errorf("Unknown compression: %s", opts.compression)
}
Expand Down Expand Up @@ -444,6 +446,11 @@ func TestBooster(t *testing.T) {
disk: "assets/ext4.img",
kernelArgs: []string{"root=UUID=5c92fc66-7315-408b-b652-176dc554d370"},
}))
t.Run("Lz4ImageCompression", boosterTest(Opts{
compression: "lz4",
disk: "assets/ext4.img",
kernelArgs: []string{"root=UUID=5c92fc66-7315-408b-b652-176dc554d370"},
}))

t.Run("MountTimeout", boosterTest(Opts{
compression: "xz",
Expand Down

0 comments on commit a4ea5b0

Please sign in to comment.