mirror of
https://github.com/linuxkit/linuxkit.git
synced 2025-07-19 17:26:28 +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
|
||||
QemuImgPath string
|
||||
PublishedPorts []string
|
||||
TapDevice string
|
||||
}
|
||||
|
||||
func haveKVM() bool {
|
||||
@ -96,6 +97,7 @@ func runQemu(args []string) {
|
||||
|
||||
publishFlags := multipleFlag{}
|
||||
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 {
|
||||
log.Fatal("Unable to parse args")
|
||||
@ -215,6 +217,7 @@ func runQemu(args []string) {
|
||||
KVM: *enableKVM,
|
||||
Containerized: *qemuContainerized,
|
||||
PublishedPorts: publishFlags,
|
||||
TapDevice: *tapDevice,
|
||||
}
|
||||
|
||||
config = discoverBackend(config)
|
||||
@ -447,6 +450,12 @@ func buildQemuCmdline(config QemuConfig) (QemuConfig, []string) {
|
||||
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 {
|
||||
qemuArgs = append(qemuArgs, "-nographic")
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user