StratoVirt supports json configuration file and cmdline arguments. If you set the same item in both json configuration file and cmdline arguments, cmdline arguments will override settings in json configuration file.
General configuration of machine, including
This feature is closed by default. There are two ways to open it:
# cmdline
-machine [type=]name[,dump-guest-core=on|off][,mem-share=on|off]
# json
{
"machine-config": {
"type": "MicroVm",
"dump_guest_core": false,
"mem-share": false,
...
},
...
}
StratoVirt supports to set the number of VCPUs(nr_vcpus).
This allows you to set the maximum number of VCPUs that VM will support. The maximum value is 254 and the minimum value that makes sense is 1.
By default, after booted, VM will online all CPUs you set.
# cmdline
-smp [cpus=]n
# json
{
"machine-config": {
"vcpu_count": 1,
...
},
...
}
StratoVirt supports to set the size of VM's memory in cmdline.
This allows you to set the size of memory that VM will support.
You can choose M
or G
as unit (default unit is Byte
).
Default VM memory size is 256M. The supported VM memory size is among [256M, 512G].
# cmdline
-m [size=]megs
-m 805306368
-m 256M
-m 1G
# json
{
"machine-config": {
"mem_size": 805306368,
...
},
...
}
StratoVirt supports to set the backend file of VM's memory.
This allows you to give a path to backend-file, which can be either a directory or a file. The path has to be absolute path.
# cmdline
-mem-path /path/to/file
-mem-path /path/to/dir
# json
{
"machine-config": {
"mem_path": "/path/to/file",
...
},
...
}
Memory backend file can be used to let guest use hugetlbfs on host. The following steps show how to use hugepages:
# mount hugetlbfs on a directory on host
$ mount -t hugetlbfs hugetlbfs /path/to/hugepages
# set the count of hugepages
$ sysctl vm.nr_hugepages=1024
# check hugepage size and count on host
$ cat /proc/meminfo
# run StratoVirt with backend-file
... -mem-path /path/to/hugepages ...
StratoVirt supports to launch PE or bzImage (only x86_64) format linux kernel 4.19 and can also set kernel parameters for VM.
This allows you to give a path to linux kernel, the path can be either absolute path or relative path.
And the given kernel parameters will be actually analyzed by boot loader.
# cmdline
-kernel /path/to/kernel \
-append console=ttyS0 rebook=k panic=1 pci=off tsc=reliable ipv6.disable=1
# json
{
"boot-source": {
"kernel_image_path": "/path/to/kernel",
"boot_args": "console=ttyS0 reboot=k panic=1 pci=off tsc=reliable ipv6.disable=1",
...
},
...
}
StratoVirt supports to launch VM by a initrd (boot loader initialized RAM disk) as well.
If the path to initrd image is configured, it will be loaded to ram by boot loader.
If you want to use initrd as rootfs, root=/dev/ram
and rdinit=/bin/sh
must be added in Kernel Parameters.
# cmdline
-initrd /path/to/initrd
# json
{
"boot-source": {
"initrd_fs_path": "/path/to/initrd",
...
},
...
}
StratoVirt supports to deploy one kind of legacy device and four kinds of virtio-mmio devices.
The max number of devices is 16 on x86_64 platform and 32 on aarch64 platform.
Iothread is used by devices to improve io performance. StratoVirt will spawn some extra threads du to iothread
configuration,
and these threads can be used by devices exclusively improving performance.
There is only one argument for iothread:
# cmdline
-iothread id=iothread1 -iothread id=iothread2
Virtio block device is a virtual block device, which process read and write requests in virtio queue from guest.
Seven properties are supported for virtio block device.
O_DIRECT
mode or notIf you want to boot VM with a virtio block device as rootfs, you should add root=DEVICE_NAME_IN_GUESTOS
in Kernel Parameters. DEVICE_NAME_IN_GUESTOS
will from vda
to vdz
in order.
# cmdline
-drive id=drive_id,file=path_on_host,serial=serial_num,readonly=off,direct=off[,iothread=iothread1,iops=200]
# json
{
...
"drive": [
{
"drive_id": "rootfs",
"path_on_host": "/path/to/block",
"serial_num": "11111111",
"direct": false,
"read_only": false,
"iothread": "iothread1",
"iops": 200
}
],
...
}
Virtio-net is a virtual Ethernet card in VM. It can enable the network capability of VM.
Four properties are supported for virtio net device.
# cmdline
-netdev id=iface_id,netdev=host_dev_name[,mac=12:34:56:78:9A:BC][,iothread=iothread1]
# json
{
...
"net": [
{
"iface_id": "tap0",
"host_dev_name": "tap0",
"mac": "12:34:56:78:9A:BC",
"iothread": "iothread1"
}
]
}
StratoVirt also supports vhost-net to get a higher performance in network.
It can be set by given vhost
property.
# cmdline
-netdev id=iface_id,netdev=host_dev_name,vhost=on[,mac=12:34:56:78:9A:BC]
# json
{
...
"net": [
{
"iface_id": "tap0",
"host_dev_name": "tap0",
"mac": "12:34:56:78:9A:BC",
"vhost_type": "vhost-kernel"
}
]
}
How to set a tap device?
# In host
$ brctl addbr qbr0
$ ip tuntap add tap0 mode tap
$ brctl addif qbr0 tap0
$ ifconfig qbr0 up; ifconfig tap0 up
$ ifconfig qbr0 1.1.1.1
# Run StratoVirt
... -netdev id=net-0,netdev=tap0 ...
# In guest
$ ip link set eth0 up
$ ip addr add 1.1.1.2/24 dev eth0
# Now network is reachable
$ ping 1.1.1.1
Virtio console is a general-purpose serial device for data transfer between the guest and host. Character devices at /dev/hvc0 to /dev/hvc7 in guest will be created once setting it. In host, it will be presented as a UnixSocket.
Two properties can be set for virtio console device.
# shell
-chardev id=console_id,path=socket_path
# json
{
"console": [
{
"console_id": "charconsole0",
"socket_path": "/path/to/socket/path"
}
],
...
}
Virtio vsock is a host/guest communication device like virtio console, but it has higher performance.
If you want use it, need:
And modprobe vhost_vsock
in the host.
Two properties can be set for virtio vsock device.
3<=guest_cid<u32:MAX
# cmdline
-device vsock,id=vsock_id,guest-cid=3
# json
{
"vsock": {
"vsock_id": "vsock-3462376255",
"guest_cid": 3
},
...
}
You can only set one virtio vsock device for one VM.
You can also use nc-vsock
to test virtio-vsock.
# In guest
$ nc-vsock -l port_num
# In host
$ nc-vsock guest_cid port_num
Serial is a legacy device for VM, it is a communication interface which bridges the guest and host.
Commonly, we use serial as ttyS0 to output console message in StratoVirt.
In StratoVirt, we can set one serial and bind it with host's stdio.
There is only one argument for serial device:
# cmdline
-serial stdio
# json
{
"serial": {
"stdio": true
},
...
}
Balloon is a virtio device, it offers a flex memory mechanism for VM.
Only one property is supported for virtio-balloon.
# cmdline
-balloon deflate-on-oom=true
# json
{
"balloon": {
"deflate_on_oom": true
},
}
Virtio rng is a paravirtualized random number generator device, it provides a hardware rng device to the guest.
If you want use it, need:
Only two property is supported for virtio-rng.
64<=bytes_per_sec<1000000000
# cmdline
-rng random_file=/path/to/random_file[,bytes_per_sec=1000000]
# json
{
"rng": {
"random_file": "/path/to/random_file",
"bytes_per_sec": 1000000
},
}
StratoVirt controls VM's lifecycle and external api interface with QMP in current version.
When running StratoVirt, you must create api-channel in cmdline arguments as a management interface.
StratoVirt supports UnixSocket-type api-channel, you can set it by:
# cmdline
-api-channel unix:/path/to/api/socket
After StratoVirt started, you can connect to StratoVirt's api-channel and manage it by QMP.
Several steps to connect api-channel are showed as following:
# Start with UnixSocket
$ ncat -U /path/to/api/socket
Once connection is built, you will receive a greeting
message from StratoVirt.
{"QMP":{"version":{"StratoVirt":{"micro":1,"minor":0,"major":0},"package":""},"capabilities":[]}}
Now you can input QMP command to control StratoVirt.
With QMP, you can control VM's lifecycle by command stop
, cont
, quit
and check VM state by
query-status
.
stop
Stop all guest VCPUs execution.
<- {"execute":"stop"}
-> {"event":"STOP","data":{},"timestamp":{"seconds":1583908726,"microseconds":162739}}
-> {"return":{}}
cont
Resume all guest VCPUs execution.
<- {"execute":"cont"}
-> {"event":"RESUME","data":{},"timestamp":{"seconds":1583908853,"microseconds":411394}}
-> {"return":{}}
quit
This command will cause StratoVirt process to exit gracefully.
<- {"execute":"quit"}
-> {"return":{}}
-> {"event":"SHUTDOWN","data":{"guest":false,"reason":"host-qmp-quit"},"timestamp":{"ds":1590563776,"microseconds":519808}}
query-status
Query the running status of all VCPUs.
<- { "execute": "query-status" }
-> { "return": { "running": true,"singlestep": false,"status": "running" } }
getfd
Receive a file descriptor via SCM rights and assign it a name.
<- { "execute": "getfd", "arguments": { "fdname": "fd1" } }
-> { "return": {} }
StratoVirt supports hot-replacing virtio-blk and virtio-net devices with QMP.
<- {"execute": "blockdev-add", "arguments": {"node-name": "drive-0", "file": {"driver": "file", "filename": "/path/to/block"}, "cache": {"direct": true}, "read-only": false}}
-> {"return": {}}
<- {"execute": "device_add", "arguments": {"id": "drive-0", "driver": "virtio-blk-mmio", "addr": "0x1"}}
-> {"return": {}}
node-name
in blockdev-add
should be same as id
in device_add
.
For addr
, it start at 0x0
mapping in guest with vda
on x86_64 platform, and start at 0x1
mapping in guest with vdb
on aarch64 platform.
You can also remove the replaceable block device by:
<- {"execute": "device_del", "arguments": {"id": "drive-0"}}
-> {"event": "DEVICE_DELETED", "data":{"device": "drive-0", "path": "/path/to/block"}}
-> {"return": {}}
<- {"execute":"netdev_add", "arguments":{"id":"net-0", "ifname":"tap0"}}
-> {"return": {}}
<- {"execute":"device_add", "arguments":{"id":"net-0", "driver":"virtio-net-mmio", "addr":"0x0"}}
-> {"return": {}}
id
in netdev_add
should be same as id
in device_add
.
For addr
, it start at 0x0
mapping in guest with eth0
.
You can also remove the replaceable net device by:
<- {"execute": "device_del", "arguments": {"id": "net-0"}}
-> {"event":"DEVICE_DELETED","data":{"device":"net-0","path":"net-0"},"timestamp":{"seconds":1614310541,"microseconds":554250}}
-> {"return": {}}
With QMP command you can set target memory size of guest and get memory size of guest.
Set target memory size of guest.
<- { "execute": "balloon", "arguments": { "value": 2147483648 } }
-> {"return":{}}
Get memory size of guest.
<- { "execute": "query-balloon" }
-> {"return":{"actual":2147483648}}
When some events happen, connected client will receive QMP events.
Now StratoVirt supports four events: SHUTDOWN
, STOP
, RESUME
, DEVICE_DELETED
.
QMP use leak bucket
to control QMP command flow. Now QMP server accept 100 commands per second.
StratoVirt supports to run as a daemon.
# cmdline
-daemonize
When run StratoVirt as a daemon, you are not allowed to bind serial with stdio or output log to stdio.
And you can also restore StratoVirt's pid number to a file by:
# cmdline
-pidfile /path/to/pidfile
StratoVirt use seccomp(2) to limit the syscalls
in StratoVirt process by default. StratoVirt use only 39 syscalls in x86_64 (38 syscalls in aarch64) after running.
It will make a slight influence on performance to StratoVirt. If you want to disable seccomp, you can
run StratoVirt with -disable-seccomp
.
# cmdline
-disable-seccomp
StratoVirt supports to output log to stderr and log file.
You can enable StratoVirt's logging by:
# Output log to stderr
-D
# Output log to log file
-D /path/to/log/file
StratoVirt's log-level depends on env STRATOVIRT_LOG_LEVEL
.
StratoVirt supports five log-levels: trace
, debug
, info
, warn
, error
. The default level is error
.
Вы можете оставить комментарий после Вход в систему
Неприемлемый контент может быть отображен здесь и не будет показан на странице. Вы можете проверить и изменить его с помощью соответствующей функции редактирования.
Если вы подтверждаете, что содержание не содержит непристойной лексики/перенаправления на рекламу/насилия/вульгарной порнографии/нарушений/пиратства/ложного/незначительного или незаконного контента, связанного с национальными законами и предписаниями, вы можете нажать «Отправить» для подачи апелляции, и мы обработаем ее как можно скорее.
Опубликовать ( 0 )