2018-10-05 07:34:10 +00:00
|
|
|
# out-of-tree/qemu
|
2018-09-21 01:00:17 +00:00
|
|
|
|
2018-09-22 13:54:45 +00:00
|
|
|
Qemu wrapper for kernel-related CI tasks. Supports *GNU/Linux* and *macOS*.
|
2018-09-21 01:00:17 +00:00
|
|
|
|
2018-09-22 13:54:45 +00:00
|
|
|
Features:
|
|
|
|
* Uses upstream virtualization -- KVM in GNU/Linux and Hypervisor.framework in macOS.
|
|
|
|
* Run files and kernel modules directly from local filesystem. No need to copy byself!
|
|
|
|
* Run commands inside qemu virtual machine at the same way as you run in it locally.
|
2018-09-21 01:00:17 +00:00
|
|
|
|
2018-09-22 13:54:45 +00:00
|
|
|
## Installation
|
2018-09-21 01:00:17 +00:00
|
|
|
|
2019-02-02 21:24:29 +00:00
|
|
|
$ go get code.dumpstack.io/tools/out-of-tree/qemu
|
2018-09-21 01:00:17 +00:00
|
|
|
|
|
|
|
### Generate root image
|
|
|
|
|
|
|
|
First of all we need to generate rootfs for run qemu.
|
|
|
|
|
2018-10-25 23:38:12 +00:00
|
|
|
#### Install qemu and docker
|
2018-09-21 01:00:17 +00:00
|
|
|
|
2018-10-25 23:38:12 +00:00
|
|
|
##### GNU/Linux
|
2018-09-21 01:00:17 +00:00
|
|
|
|
2018-10-25 23:38:12 +00:00
|
|
|
$ sudo apt install -y qemu docker
|
|
|
|
|
|
|
|
##### macOS
|
2018-09-21 01:00:17 +00:00
|
|
|
|
|
|
|
Note: qemu on macOS since v2.12 (24 April 2018) supports Hypervisor.framework.
|
|
|
|
|
|
|
|
$ brew install qemu
|
2018-10-25 23:38:12 +00:00
|
|
|
$ brew cask install docker
|
2018-09-21 01:00:17 +00:00
|
|
|
|
2018-10-25 23:38:12 +00:00
|
|
|
#### Generate image
|
2018-09-21 01:00:17 +00:00
|
|
|
|
2019-02-02 21:24:29 +00:00
|
|
|
$ cd $GOPATH/src/code.dumpstack.io/tools/out-of-tree/tools/qemu-debian-img
|
2018-10-25 23:38:12 +00:00
|
|
|
$ ./bootstrap.sh
|
2018-09-21 01:00:17 +00:00
|
|
|
|
|
|
|
### Fill configuration file
|
|
|
|
|
2019-02-02 21:24:29 +00:00
|
|
|
$ $EDITOR $GOPATH/src/code.dumpstack.io/tools/out-of-tree/qemu/test.config.go
|
2018-09-21 01:00:17 +00:00
|
|
|
|
|
|
|
### Run tests
|
|
|
|
|
|
|
|
$ go test -v
|
2018-09-22 13:54:45 +00:00
|
|
|
|
|
|
|
## Usage
|
|
|
|
|
2019-02-02 21:24:29 +00:00
|
|
|
$ go get code.dumpstack.io/tools/out-of-tree/qemu
|
2018-09-22 13:54:45 +00:00
|
|
|
|
|
|
|
Minimal example:
|
|
|
|
|
|
|
|
kernel := qemu.Kernel{
|
|
|
|
Name: "Some kernel name",
|
|
|
|
KernelPath: "/path/to/vmlinuz",
|
|
|
|
InitrdPath: "/path/to/initrd", // if required
|
|
|
|
}
|
2019-08-17 09:05:06 +00:00
|
|
|
q, err := qemu.NewSystem(qemu.X86_64, kernel, "/path/to/qcow2")
|
2018-09-22 13:54:45 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err = q.Start(); err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
defer q.Stop()
|
|
|
|
|
|
|
|
output, err = q.Command("root", "echo Hello, World!")
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// output == "Hello, World!\n"
|
|
|
|
|
|
|
|
More information and list of all functions see at go documentation project, or just run locally:
|
|
|
|
|
2019-02-02 21:24:29 +00:00
|
|
|
$ godoc code.dumpstack.io/tools/out-of-tree/qemu
|