From dc5e46139a630e36ba3378b1e491657d38f0c076 Mon Sep 17 00:00:00 2001 From: Achilleas Koutsou Date: Tue, 2 Mar 2021 12:47:18 +0100 Subject: [PATCH] osbuild2: new dracut stage to re-create initrd --- internal/osbuild2/dracut_stage.go | 56 ++++++++++++++++++++++++++ internal/osbuild2/dracut_stage_test.go | 16 ++++++++ 2 files changed, 72 insertions(+) create mode 100644 internal/osbuild2/dracut_stage.go create mode 100644 internal/osbuild2/dracut_stage_test.go diff --git a/internal/osbuild2/dracut_stage.go b/internal/osbuild2/dracut_stage.go new file mode 100644 index 000000000..d2f18ec1f --- /dev/null +++ b/internal/osbuild2/dracut_stage.go @@ -0,0 +1,56 @@ +package osbuild2 + +type DracutStageOptions struct { + // List of target kernel versions + Kernel []string `json:"kernel"` + + // Compression method for the initramfs + Compress string `json:"compress,omitempty"` + + // Exact list of dracut modules to use + Modules []string `json:"modules,omitempty"` + + // Additional dracut modules to include + AddModules []string `json:"add_modules,omitempty"` + + // Dracut modules to not include + OmitModules []string `json:"omit_modules,omitempty"` + + // Kernel modules to exclusively include + Drivers []string `json:"drivers,omitempty"` + + // Add a specific kernel module + AddDrivers []string `json:"add_drivers,omitempty"` + + // Add driver and ensure that they are tried to be loaded + ForceDrivers []string `json:"force_drivers,omitempty"` + + // Kernel filesystem modules to exclusively include + Filesystems []string `json:"filesystems,omitempty"` + + // Add custom files to the initramfs + // What (keys) to include where (values) + Include map[string]string `json:"include,omitempty"` + + // Install the specified files + Install []string `json:"install,omitempty"` + + // Combine early microcode with the initramfs + EarlyMicrocode bool `json:"early_microcode,omitempty"` + + // Create reproducible images + Reproducible bool `json:"reproducible,omitempty"` + + // Extra arguments to directly pass to dracut + Extra []string `json:"extra,omitempty"` +} + +func (DracutStageOptions) isStageOptions() {} + +// Dracut stage (re-)creates the initial RAM file-system +func NewDracutStage(options *DracutStageOptions) *Stage { + return &Stage{ + Type: "org.osbuild.dracut", + Options: options, + } +} diff --git a/internal/osbuild2/dracut_stage_test.go b/internal/osbuild2/dracut_stage_test.go new file mode 100644 index 000000000..dc5ac0b14 --- /dev/null +++ b/internal/osbuild2/dracut_stage_test.go @@ -0,0 +1,16 @@ +package osbuild2 + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestNewDracutStage(t *testing.T) { + expectedStage := &Stage{ + Type: "org.osbuild.dracut", + Options: &DracutStageOptions{}, + } + actualStage := NewDracutStage(&DracutStageOptions{}) + assert.Equal(t, expectedStage, actualStage) +}