Host os
You can run StratoVirt on both x86_64 and aarch64 platforms.
And on top of that, the StratoVirt is based on KVM, so please make sure you have KVM module on your platform.
Authority
You should have read/write permissions to /dev/kvm
. If not, you can get your permissions by:
$ sudo setfacl -m u:${USER}:rw /dev/kvm
To build StratoVirt, make sure that Rust language environment and Cargo have already been installed. The recommended version of rustc is 1.42 or later.
$ rustc -version
rustc 1.42.0
If you want to deploy rust environment, the following link will help you:
https://www.rust-lang.org/tools/install
With musl-libc, StratoVirt is linked statically and has no library dependencies. It's the default target to build StratoVirt.
# Add musl rust tool-chain, if installed, skip
$ arch=`uname -m`
$ rustup target add ${arch}-unknown-linux-musl
# Build StratoVirt
$ cargo build --release --target ${arch}-unknown-linux-musl
Now you can find StratoVirt binary file in target/${arch}-unknown-linux-musl/release/stratovirt
.
StratoVirt can also be built using glibc toolchains. By this way, StratoVirt is linked dynamically.
# Add gnu rust tool-chain, if installed, skip
$ arch=`uname -m`
$ rustup target add ${arch}-unknown-linux-gnu
# Build StratoVirt
$ cargo build --release --target ${arch}-unknown-linux-gnu
Now you can find StratoVirt binary file in target/${arch}-unknown-linux-gnu/release/stratovirt
.
The StratoVirt in current version supports PE or bzImage (only x86_64) format kernel images on both x86_64 and aarch64 platforms, which can be built with:
Firstly, get the openEuler kernel source code:
$ git clone -b kernel-4.19 --depth=1 https://gitee.com/openeuler/kernel
$ cd kernel
Configure your linux kernel. You can use our recommended config and
copy it to kernel
path as .config
. You can also modify config options by:
$ make menuconfig
Build and transform kernel image to PE format.
$ make -j vmlinux && objcopy -O binary vmlinux vmlinux.bin
If you want compile bzImage format kernel in x86_64.
$ make -j bzImage
Rootfs image is a file system image. An EXT4-format image with /sbin/init
can be mounted at
boot time in StratoVirt. Below is a simple way to make a EXT4 rootfs image:
Prepare a properly-sized file(e.g. 1G):
$ dd if=/dev/zero of=./rootfs.ext4 bs=1G count=20
Create an empty EXT4 file system on this file:
$ mkfs.ext4 ./rootfs.ext4
Mount the file image:
$ mkdir -p /mnt/rootfs
$ sudo mount ./rootfs.ext4 /mnt/rootfs && cd /mnt/rootfs
Get the latest alpine-minirootfs for your platform(e.g. aarch64 3.12.0):
$ wget http://dl-cdn.alpinelinux.org/alpine/latest-stable/releases/aarch64/alpine-minirootfs-3.12.0-aarch64.tar.gz
$ tar -zxvf alpine-minirootfs-3.12.0-aarch64.tar.gz
$ rm alpine-minirootfs-3.12.0-aarch64.tar.gz
Make a simple /sbin/init
for EXT4 file image.
$ rm sbin/init && touch sbin/init && cat > sbin/init <<EOF
#! /bin/sh
mount -t devtmpfs dev /dev
mount -t proc proc /proc
mount -t sysfs sysfs /sys
ip link set up dev lo
exec /sbin/getty -n -l /bin/sh 115200 /dev/ttyS0
poweroff -f
EOF
$ sudo chmod +x sbin/init
Unmount rootfs image:
$ cd ~ && umount /mnt/rootfs
With kernel and rootfs image, we can boot a guest linux machine by StratoVirt.
The minimum configuration for StratoVirt is:
You can deploy StratoVirt with cmdline arguments:
# Make sure api-channel can be created.
$ rm -f /path/to/socket
# Start StratoVirt
$ ./stratovirt \
-kernel /path/to/vmlinux.bin \
-append console=ttyS0 pci=off reboot=k panic=1 root=/dev/vda \
-drive file=/path/to/rootfs,id=rootfs,readonly=off \
-api-channel unix:/path/to/socket \
-serial stdio
StratoVirt can also boot from a json configuration file like provided sample default.json.
# Json configuration file
$ cat default.json
{
"boot-source": {
"kernel_image_path": "/path/to/kernel",
"boot_args": "console=ttyS0 reboot=k panic=1 pci=off tsc=reliable ipv6.disable=1 root=/dev/vda"
},
"machine-config": {
"vcpu_count": 1,
"mem_size": 268435456
},
"drive": [
{
"drive_id": "rootfs",
"path_on_host": "/path/to/rootfs/image",
"direct": false,
"read_only": false
}
],
"balloon": {
"deflate_on_oom": true
},
"serial": {
"stdio": true
}
}
# Start StratoVirt
$ ./stratovirt \
-config ./default.json \
-api-channel unix:/path/to/socket
You can also run StratoVirt with initrdfs, read initrd_guide.
ACPI(Advanced Configuration and Power Interface) has not been implemented yet in StratoVirt. Power management, such as shutdown
or reboot
behavior, is not allowed. So it is not feasible to use shutdown
or poweroff
command to close the VM.
Instead, use reboot
command in the guest or quit
command with QMP to close the VM.
If you want to know more information on running StratoVirt, go to the Configuration Guidebook.
Вы можете оставить комментарий после Вход в систему
Неприемлемый контент может быть отображен здесь и не будет показан на странице. Вы можете проверить и изменить его с помощью соответствующей функции редактирования.
Если вы подтверждаете, что содержание не содержит непристойной лексики/перенаправления на рекламу/насилия/вульгарной порнографии/нарушений/пиратства/ложного/незначительного или незаконного контента, связанного с национальными законами и предписаниями, вы можете нажать «Отправить» для подачи апелляции, и мы обработаем ее как можно скорее.
Опубликовать ( 0 )