From 224ade8fea0ff3e085373f51b5563c481e2acce1 Mon Sep 17 00:00:00 2001 From: Scott Coulton Date: Thu, 15 Feb 2018 15:09:10 +1100 Subject: [PATCH 1/2] This commit adds the functionality to run the qemu container detached --- src/cmd/linuxkit/run_qemu.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/cmd/linuxkit/run_qemu.go b/src/cmd/linuxkit/run_qemu.go index 7ba1933ab..2ea09a4f0 100644 --- a/src/cmd/linuxkit/run_qemu.go +++ b/src/cmd/linuxkit/run_qemu.go @@ -40,6 +40,7 @@ type QemuConfig struct { Memory string Accel string Containerized bool + Detached bool QemuBinPath string QemuImgPath string PublishedPorts []string @@ -162,6 +163,7 @@ func runQemu(args []string) { // Backend configuration qemuContainerized := flags.Bool("containerized", false, "Run qemu in a container") qemuCmd := flags.String("qemu", "", "Path to the qemu binary (otherwise look in $PATH)") + qemuDetached := flags.Bool("detached", false, "Set qemu container to run in the background") // Generate UUID, so that /sys/class/dmi/id/product_uuid is populated vmUUID := uuid.New() @@ -306,6 +308,7 @@ func runQemu(args []string) { Memory: *mem, Accel: *accel, Containerized: *qemuContainerized, + Detached: *qemuDetached, QemuBinPath: *qemuCmd, PublishedPorts: publishFlags, NetdevConfig: netdevConfig, @@ -427,6 +430,10 @@ func runQemuContainer(config QemuConfig) error { dockerArgs = append(dockerArgs, "--device", "/dev/kvm") } + if config.Detached == true { + dockerArgs = append(dockerArgs, "-d") + } + if config.PublishedPorts != nil && len(config.PublishedPorts) > 0 { forwardings, err := buildDockerForwardings(config.PublishedPorts) if err != nil { From a7ec17b08fe94ee01559ed5f86fef265b0bf3f91 Mon Sep 17 00:00:00 2001 From: Scott Coulton Date: Mon, 19 Feb 2018 11:53:13 +1100 Subject: [PATCH 2/2] Added a fail if the user sets detached to true when qemu is running locally --- src/cmd/linuxkit/run_qemu.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/cmd/linuxkit/run_qemu.go b/src/cmd/linuxkit/run_qemu.go index 2ea09a4f0..3f325b047 100644 --- a/src/cmd/linuxkit/run_qemu.go +++ b/src/cmd/linuxkit/run_qemu.go @@ -366,6 +366,11 @@ func runQemuLocal(config QemuConfig) error { } } + // Detached mode is only supported in a container. + if config.Detached == true { + return fmt.Errorf("Detached mode is only supported when running in a container, not locally") + } + qemuCmd := exec.Command(config.QemuBinPath, args...) // If verbosity is enabled print out the full path/arguments log.Debugf("%v\n", qemuCmd.Args)