Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

Commit

Permalink
Merge pull request #98 from bergwolf/initrd
Browse files Browse the repository at this point in the history
support to boot guest with an initrd image
  • Loading branch information
bergwolf authored Mar 28, 2018
2 parents 4ac5a6a + 423e864 commit 01f7e46
Show file tree
Hide file tree
Showing 22 changed files with 269 additions and 62 deletions.
4 changes: 2 additions & 2 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@

[[constraint]]
name = "github.com/intel/govmm"
revision = "e87160f8ea39dfe558bf6761f74717d191d82493"
revision = "82c67ab9b21e8cd0042b6c2d3be2d3705a511603"

[[constraint]]
name = "github.com/kata-containers/agent"
Expand Down
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ PROJECT_BUG_URL = $(PROJECT_URL)/kata-containers/issues/new
BIN_PREFIX = $(PROJECT_TYPE)
PROJECT_DIR = $(PROJECT_TAG)
IMAGENAME = $(PROJECT_TAG).img
INITRDNAME = $(PROJECT_TAG)-initrd.img

TARGET = $(BIN_PREFIX)-runtime
TARGET_OUTPUT = $(CURDIR)/$(TARGET)
Expand Down Expand Up @@ -77,6 +78,7 @@ PKGRUNDIR := $(LOCALSTATEDIR)/run/$(PROJECT_DIR)
PKGLIBEXECDIR := $(LIBEXECDIR)/$(PROJECT_DIR)

KERNELPATH := $(PKGDATADIR)/vmlinuz.container
INITRDPATH := $(PKGDATADIR)/$(INITRDNAME)
IMAGEPATH := $(PKGDATADIR)/$(IMAGENAME)
FIRMWAREPATH :=

Expand Down Expand Up @@ -140,6 +142,8 @@ USER_VARS += DESTSYSCONFIG
USER_VARS += DESTTARGET
USER_VARS += IMAGENAME
USER_VARS += IMAGEPATH
USER_VARS += INITRDNAME
USER_VARS += INITRDPATH
USER_VARS += MACHINETYPE
USER_VARS += KERNELPATH
USER_VARS += FIRMWAREPATH
Expand Down Expand Up @@ -244,6 +248,7 @@ var showConfigPathsOption = fmt.Sprintf("%s-show-default-config-paths", projectP
var defaultHypervisorPath = "$(QEMUPATH)"
var defaultImagePath = "$(IMAGEPATH)"
var defaultKernelPath = "$(KERNELPATH)"
var defaultInitrdPath = "$(INITRDPATH)"
var defaultFirmwarePath = "$(FIRMWAREPATH)"
var defaultMachineAccelerators = "$(MACHINEACCELERATORS)"
var defaultShimPath = "$(SHIMPATH)"
Expand Down Expand Up @@ -319,6 +324,7 @@ $(GENERATED_FILES): %: %.in Makefile VERSION
-e "s|@DESTSYSCONFIG@|$(DESTSYSCONFIG)|g" \
-e "s|@IMAGEPATH@|$(IMAGEPATH)|g" \
-e "s|@KERNELPATH@|$(KERNELPATH)|g" \
-e "s|@INITRDPATH@|$(INITRDPATH)|g" \
-e "s|@FIRMWAREPATH@|$(FIRMWAREPATH)|g" \
-e "s|@MACHINEACCELERATORS@|$(MACHINEACCELERATORS)|g" \
-e "s|@KERNELPARAMS@|$(KERNELPARAMS)|g" \
Expand Down
20 changes: 19 additions & 1 deletion cli/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ type tomlConfig struct {
type hypervisor struct {
Path string `toml:"path"`
Kernel string `toml:"kernel"`
Initrd string `toml:"initrd"`
Image string `toml:"image"`
Firmware string `toml:"firmware"`
MachineAccelerators string `toml:"machine_accelerators"`
Expand Down Expand Up @@ -131,11 +132,21 @@ func (h hypervisor) kernel() (string, error) {
return resolvePath(p)
}

func (h hypervisor) initrd() (string, error) {
p := h.Initrd

if p == "" {
return "", nil
}

return resolvePath(p)
}

func (h hypervisor) image() (string, error) {
p := h.Image

if p == "" {
p = defaultImagePath
return "", nil
}

return resolvePath(p)
Expand Down Expand Up @@ -267,6 +278,11 @@ func newQemuHypervisorConfig(h hypervisor) (vc.HypervisorConfig, error) {
return vc.HypervisorConfig{}, err
}

initrd, err := h.initrd()
if err != nil {
return vc.HypervisorConfig{}, err
}

image, err := h.image()
if err != nil {
return vc.HypervisorConfig{}, err
Expand All @@ -289,6 +305,7 @@ func newQemuHypervisorConfig(h hypervisor) (vc.HypervisorConfig, error) {
return vc.HypervisorConfig{
HypervisorPath: hypervisor,
KernelPath: kernel,
InitrdPath: initrd,
ImagePath: image,
FirmwarePath: firmware,
MachineAccelerators: machineAccelerators,
Expand Down Expand Up @@ -393,6 +410,7 @@ func loadConfiguration(configPath string, ignoreLogging bool) (resolvedConfigPat
HypervisorPath: defaultHypervisorPath,
KernelPath: defaultKernelPath,
ImagePath: defaultImagePath,
InitrdPath: defaultInitrdPath,
FirmwarePath: defaultFirmwarePath,
MachineAccelerators: defaultMachineAccelerators,
HypervisorMachineType: defaultMachineType,
Expand Down
1 change: 1 addition & 0 deletions cli/config/configuration.toml.in
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
[hypervisor.qemu]
path = "@QEMUPATH@"
kernel = "@KERNELPATH@"
initrd = "@INITRDPATH@"
image = "@IMAGEPATH@"
machine_type = "@MACHINETYPE@"

Expand Down
43 changes: 41 additions & 2 deletions cli/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,7 @@ func TestMinimalRuntimeConfig(t *testing.T) {
HypervisorPath: defaultHypervisorPath,
KernelPath: defaultKernelPath,
ImagePath: defaultImagePath,
InitrdPath: defaultInitrdPath,
HypervisorMachineType: defaultMachineType,
DefaultVCPUs: defaultVCPUCount,
DefaultMemSz: defaultMemSize,
Expand Down Expand Up @@ -757,6 +758,44 @@ func TestHypervisorDefaultsKernel(t *testing.T) {
assert.Equal(h.kernelParams(), kernelParams, "custom hypervisor kernel parameterms wrong")
}

// The default initrd path is not returned by h.initrd()
func TestHypervisorDefaultsInitrd(t *testing.T) {
assert := assert.New(t)

tmpdir, err := ioutil.TempDir(testDir, "")
assert.NoError(err)
defer os.RemoveAll(tmpdir)

testInitrdPath := filepath.Join(tmpdir, "initrd")
testInitrdLinkPath := filepath.Join(tmpdir, "initrd-link")

err = createEmptyFile(testInitrdPath)
assert.NoError(err)

err = syscall.Symlink(testInitrdPath, testInitrdLinkPath)
assert.NoError(err)

savedInitrdPath := defaultInitrdPath

defer func() {
defaultInitrdPath = savedInitrdPath
}()

defaultInitrdPath = testInitrdPath
h := hypervisor{}
p, err := h.initrd()
assert.NoError(err)
assert.Equal(p, "", "default Image path wrong")

// test path resolution
defaultInitrdPath = testInitrdLinkPath
h = hypervisor{}
p, err = h.initrd()
assert.NoError(err)
assert.Equal(p, "")
}

// The default image path is not returned by h.image()
func TestHypervisorDefaultsImage(t *testing.T) {
assert := assert.New(t)

Expand All @@ -783,14 +822,14 @@ func TestHypervisorDefaultsImage(t *testing.T) {
h := hypervisor{}
p, err := h.image()
assert.NoError(err)
assert.Equal(p, defaultImagePath, "default Image path wrong")
assert.Equal(p, "", "default Image path wrong")

// test path resolution
defaultImagePath = testImageLinkPath
h = hypervisor{}
p, err = h.image()
assert.NoError(err)
assert.Equal(p, testImagePath)
assert.Equal(p, "")
}

func TestProxyDefaults(t *testing.T) {
Expand Down
51 changes: 32 additions & 19 deletions cli/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,35 +152,48 @@ func create(containerID, bundlePath, console, pidFilePath string, detach bool,
return createPIDFile(pidFilePath, process.Pid)
}

func getKernelParams(containerID string) []vc.Param {
return []vc.Param{
{
Key: "init",
Value: "/usr/lib/systemd/systemd",
},
{
Key: "systemd.unit",
Value: systemdUnitName,
},
{
Key: "systemd.mask",
Value: "systemd-networkd.service",
},
{
Key: "systemd.mask",
Value: "systemd-networkd.socket",
},
var systemdKernelParam = []vc.Param{
{
Key: "init",
Value: "/usr/lib/systemd/systemd",
},
{
Key: "systemd.unit",
Value: systemdUnitName,
},
{
Key: "systemd.mask",
Value: "systemd-networkd.service",
},
{
Key: "systemd.mask",
Value: "systemd-networkd.socket",
},
}

func getKernelParams(containerID string, needSystemd bool) []vc.Param {
p := []vc.Param{
{
Key: "ip",
Value: fmt.Sprintf("::::::%s::off::", containerID),
},
}

if needSystemd {
p = append(p, systemdKernelParam...)
}

return p
}

func needSystemd(config vc.HypervisorConfig) bool {
return config.ImagePath != ""
}

// setKernelParams adds the user-specified kernel parameters (from the
// configuration file) to the defaults so that the former take priority.
func setKernelParams(containerID string, runtimeConfig *oci.RuntimeConfig) error {
defaultKernelParams := getKernelParamsFunc(containerID)
defaultKernelParams := getKernelParamsFunc(containerID, needSystemd(runtimeConfig.HypervisorConfig))

if runtimeConfig.HypervisorConfig.Debug {
strParams := vc.SerializeParams(defaultKernelParams, "=")
Expand Down
2 changes: 1 addition & 1 deletion cli/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -861,7 +861,7 @@ func TestCreateInvalidKernelParams(t *testing.T) {
getKernelParamsFunc = savedFunc
}()

getKernelParamsFunc = func(containerID string) []vc.Param {
getKernelParamsFunc = func(containerID string, needSystemd bool) []vc.Param {
return []vc.Param{
{
Key: "",
Expand Down
13 changes: 12 additions & 1 deletion cli/kata-env.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
//
// XXX: Increment for every change to the output format
// (meaning any change to the EnvInfo type).
const formatVersion = "1.0.9"
const formatVersion = "1.0.10"

// MetaInfo stores information on the format of the output itself
type MetaInfo struct {
Expand All @@ -44,6 +44,11 @@ type KernelInfo struct {
Parameters string
}

// InitrdInfo stores initrd image details
type InitrdInfo struct {
Path string
}

// ImageInfo stores root filesystem image details
type ImageInfo struct {
Path string
Expand Down Expand Up @@ -130,6 +135,7 @@ type EnvInfo struct {
Hypervisor HypervisorInfo
Image ImageInfo
Kernel KernelInfo
Initrd InitrdInfo
Proxy ProxyInfo
Shim ShimInfo
Agent AgentInfo
Expand Down Expand Up @@ -307,12 +313,17 @@ func getEnvInfo(configFile string, config oci.RuntimeConfig) (env EnvInfo, err e
Parameters: strings.Join(vc.SerializeParams(config.HypervisorConfig.KernelParams, "="), " "),
}

initrd := InitrdInfo{
Path: config.HypervisorConfig.InitrdPath,
}

env = EnvInfo{
Meta: meta,
Runtime: runtime,
Hypervisor: hypervisor,
Image: image,
Kernel: kernel,
Initrd: initrd,
Proxy: proxy,
Shim: shim,
Agent: agent,
Expand Down
8 changes: 8 additions & 0 deletions vendor/github.com/intel/govmm/qemu/qemu.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions virtcontainers/asset.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ func (t assetType) annotations() (string, string, error) {
return annotations.KernelPath, annotations.KernelHash, nil
case imageAsset:
return annotations.ImagePath, annotations.ImageHash, nil
case initrdAsset:
return annotations.InitrdPath, annotations.InitrdHash, nil
case hypervisorAsset:
return annotations.HypervisorPath, annotations.HypervisorHash, nil
case firmwareAsset:
Expand All @@ -46,6 +48,7 @@ func (t assetType) annotations() (string, string, error) {
const (
kernelAsset assetType = "kernel"
imageAsset assetType = "image"
initrdAsset assetType = "initrd"
hypervisorAsset assetType = "hypervisor"
firmwareAsset assetType = "firmware"
)
Expand All @@ -66,6 +69,8 @@ func (a *asset) valid() bool {
return true
case imageAsset:
return true
case initrdAsset:
return true
case hypervisorAsset:
return true
case firmwareAsset:
Expand Down
Loading

0 comments on commit 01f7e46

Please sign in to comment.