mirror of
https://github.com/linuxkit/linuxkit.git
synced 2025-07-21 10:09:07 +00:00
support tap devices in qemu backend
The motivation for this is networking out (in particular, testing NFS support) from the VM. We could be a lot more user friendly (a la libvirt) by creating the tap device for users and allowing them to specify a bridge instead, but then we'd need root to create this tap device. For now, let's make people do their own tap devices, and just use them. A tap device can be created for a bridge as follows: # ip tuntap add linuxkit0 mode tap user `whoami` # ip link set linuxkit0 up # ip link set linuxkit0 master $bridge_name and then used by: $ ./bin/linuxkit run qemu -tap-device linuxkit0 linuxkit Signed-off-by: Tycho Andersen <tycho@docker.com>
This commit is contained in:
parent
c76096e4d5
commit
d237c92273
@ -35,6 +35,7 @@ type QemuConfig struct {
|
|||||||
QemuBinPath string
|
QemuBinPath string
|
||||||
QemuImgPath string
|
QemuImgPath string
|
||||||
PublishedPorts []string
|
PublishedPorts []string
|
||||||
|
TapDevice string
|
||||||
}
|
}
|
||||||
|
|
||||||
func haveKVM() bool {
|
func haveKVM() bool {
|
||||||
@ -96,6 +97,7 @@ func runQemu(args []string) {
|
|||||||
|
|
||||||
publishFlags := multipleFlag{}
|
publishFlags := multipleFlag{}
|
||||||
flags.Var(&publishFlags, "publish", "Publish a vm's port(s) to the host (default [])")
|
flags.Var(&publishFlags, "publish", "Publish a vm's port(s) to the host (default [])")
|
||||||
|
tapDevice := flags.String("tap-device", "", "Tap device to use as eth0 (optional)")
|
||||||
|
|
||||||
if err := flags.Parse(args); err != nil {
|
if err := flags.Parse(args); err != nil {
|
||||||
log.Fatal("Unable to parse args")
|
log.Fatal("Unable to parse args")
|
||||||
@ -215,6 +217,7 @@ func runQemu(args []string) {
|
|||||||
KVM: *enableKVM,
|
KVM: *enableKVM,
|
||||||
Containerized: *qemuContainerized,
|
Containerized: *qemuContainerized,
|
||||||
PublishedPorts: publishFlags,
|
PublishedPorts: publishFlags,
|
||||||
|
TapDevice: *tapDevice,
|
||||||
}
|
}
|
||||||
|
|
||||||
config = discoverBackend(config)
|
config = discoverBackend(config)
|
||||||
@ -447,6 +450,12 @@ func buildQemuCmdline(config QemuConfig) (QemuConfig, []string) {
|
|||||||
qemuArgs = append(qemuArgs, "-net", "nic")
|
qemuArgs = append(qemuArgs, "-net", "nic")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if config.TapDevice != "" {
|
||||||
|
qemuArgs = append(qemuArgs, "-net", "nic,model=virtio")
|
||||||
|
tapArg := fmt.Sprintf("tap,ifname=%s,script=no,downscript=no", config.TapDevice)
|
||||||
|
qemuArgs = append(qemuArgs, "-net", tapArg)
|
||||||
|
}
|
||||||
|
|
||||||
if config.GUI != true {
|
if config.GUI != true {
|
||||||
qemuArgs = append(qemuArgs, "-nographic")
|
qemuArgs = append(qemuArgs, "-nographic")
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user