Skip to content

Commit

Permalink
qemu: add initrd support
Browse files Browse the repository at this point in the history
Append initrd image to qemu arguments if configured.

Signed-off-by: Peng Tao <bergwolf@gmail.com>
  • Loading branch information
bergwolf committed Mar 20, 2018
1 parent e87160f commit 0c0ec8f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
8 changes: 8 additions & 0 deletions qemu/qemu.go
Original file line number Diff line number Diff line change
Expand Up @@ -1117,6 +1117,9 @@ type Kernel struct {
// Path is the guest kernel path on the host filesystem.
Path string

// InitrdPath is the guest initrd path on the host filesystem.
InitrdPath string

// Params is the kernel parameters string.
Params string
}
Expand Down Expand Up @@ -1395,6 +1398,11 @@ func (config *Config) appendKernel() {
config.qemuParams = append(config.qemuParams, "-kernel")
config.qemuParams = append(config.qemuParams, config.Kernel.Path)

if config.Kernel.InitrdPath != "" {
config.qemuParams = append(config.qemuParams, "-initrd")
config.qemuParams = append(config.qemuParams, config.Kernel.InitrdPath)
}

if config.Kernel.Params != "" {
config.qemuParams = append(config.qemuParams, "-append")
config.qemuParams = append(config.qemuParams, config.Kernel.Params)
Expand Down
7 changes: 4 additions & 3 deletions qemu/qemu_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -395,12 +395,13 @@ func TestAppendKnobsAllFalse(t *testing.T) {
testAppend(knobs, knobsString, t)
}

var kernelString = "-kernel /opt/vmlinux.container -append root=/dev/pmem0p1 rootflags=dax,data=ordered,errors=remount-ro rw rootfstype=ext4 tsc=reliable"
var kernelString = "-kernel /opt/vmlinux.container -initrd /opt/initrd.container -append root=/dev/pmem0p1 rootflags=dax,data=ordered,errors=remount-ro rw rootfstype=ext4 tsc=reliable"

func TestAppendKernel(t *testing.T) {
kernel := Kernel{
Path: "/opt/vmlinux.container",
Params: "root=/dev/pmem0p1 rootflags=dax,data=ordered,errors=remount-ro rw rootfstype=ext4 tsc=reliable",
Path: "/opt/vmlinux.container",
InitrdPath: "/opt/initrd.container",
Params: "root=/dev/pmem0p1 rootflags=dax,data=ordered,errors=remount-ro rw rootfstype=ext4 tsc=reliable",
}

testAppend(kernel, kernelString, t)
Expand Down

0 comments on commit 0c0ec8f

Please sign in to comment.