同步操作将从 openEuler/stratovirt 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
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 only PE-format kernel images on both x86_64 and aarch64 platforms, which can be built with:
Firstly, get the openEuler kernel source code:
$ git clone https://gitee.com/openeuler/kernel
$ cd kernel
Switch the kernel version to kernel-4.19:
$ git checkout kernel-4.19
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
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
}
],
"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.
If you want to know more information on running StratoVirt, go to the Configuration Guidebook.
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。