Skip to content

Commit d4813df

Browse files
committed
add stratovirt-riscv-part1
Signed-off-by: Zhangjin Wu <falcon@tinylab.org>
1 parent 2988606 commit d4813df

File tree

1 file changed

+141
-0
lines changed

1 file changed

+141
-0
lines changed
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
---
2+
layout: post
3+
author: '乖乖是干饭王'
4+
title: 'Stratovirt 的 RISC-V 支持(一):环境配置'
5+
draft: false
6+
album: 'RISC-V Linux'
7+
license: 'cc-by-nc-nd-4.0'
8+
permalink: /stratovirt-riscv-part1/
9+
description: 'Stratovirt 的 RISC-V 支持(一):环境配置'
10+
category:
11+
- 开源项目
12+
- RISC-V
13+
tags:
14+
- Linux
15+
- RISC-V
16+
- Stratovirt
17+
- KVM
18+
- Rust
19+
- QEMU
20+
---
21+
22+
> Corrector: [TinyCorrect](https://gitee.com/tinylab/tinycorrect) v0.2-rc2 - [spaces]
23+
> Author: Sunts <stsmail163@163.com>
24+
> Date: 2024/08/30
25+
> Revisor: Falcon <falcon@tinylab.org>
26+
> Project: [RISC-V Linux 内核剖析](https://gitee.com/tinylab/riscv-linux)
27+
> Sponsor: PLCT Lab, ISCAS
28+
29+
30+
## 前言
31+
32+
StratoVirt 是一种基于 Linux 内核虚拟化(KVM)的开源轻量级虚拟化技术。Stratovirt 的运行环境必须要有 RISC-V 的 H 扩展以及在其之上运行的 Linux 提供 KVM 支持。本文采用 QEMU + Ubuntu 22.04 的环境。
33+
34+
## 准备 Ubuntu 镜像
35+
36+
打开终端,执行以下命令,下载镜像。
37+
38+
```shell
39+
wget https://cdimage.ubuntu.com/releases/jammy/release/ubuntu-22.04.4-preinstalled-server-riscv64+unmatched.img.xz
40+
```
41+
42+
解压缩系统镜像文件
43+
44+
```shell
45+
xz -d ubuntu-22.04.4-preinstalled-server-riscv64+unmatched.img.xz
46+
```
47+
48+
## 编译 QEMU
49+
50+
考虑到直接使用 apt 命令安装的 QEMU 可能不支持 RISC-V 虚拟化扩展。所以直接下载源码编译。
51+
52+
安装编译前所需工具
53+
54+
```shell
55+
sudo apt install autoconf automake autotools-dev curl libmpc-dev libmpfr-dev libgmp-dev \
56+
gawk build-essential bison flex texinfo gperf libtool patchutils bc \
57+
zlib1g-dev libexpat-dev git ninja-build \
58+
libglib2.0-dev libfdt-dev libpixman-1-dev
59+
```
60+
61+
```shell
62+
# 根据 python 版本调整版本号
63+
sudo apt-get install python3.12-venv
64+
```
65+
66+
QEMU 的 user 用户模式网络配置需要 libslirp 的支持
67+
68+
下载 libslirp 源码和编译所需工具
69+
70+
```shell
71+
git clone https://gitlab.freedesktop.org/slirp/libslirp.git
72+
sudo apt install meson
73+
```
74+
75+
libslirp 编译,安装
76+
77+
```shell
78+
meson build
79+
ninja -C build install
80+
```
81+
82+
下载 QEMU 源码
83+
84+
```shell
85+
git clone https://github.com/qemu/qemu.git
86+
```
87+
88+
编译 RV64 架构下的 QEMU:qemu-system-riscv64
89+
90+
```shell
91+
cd qemu && ./configure --target-list=riscv64-softmmu --enable-slirp && make
92+
```
93+
94+
## 用 QEMU 引导 Linux
95+
96+
安装 U-boot 和 Opensbi
97+
98+
```shell
99+
sudo apt install u-boot-qemu opensbi
100+
```
101+
102+
启动 Linux
103+
104+
```shell
105+
./qemu/build/qemu-system-riscv64 -machine virt -nographic -m 8192 -smp 6 -bios /usr/lib/riscv64-linux-gnu/opensbi/generic/fw_jump.bin -kernel /usr/lib/u-boot/qemu-riscv64_smode/uboot.elf -device virtio-net-device,netdev=eth0 -netdev user,id=eth0,hostfwd=tcp::6666-:22 -device virtio-rng-pci -drive file=./ubuntu-22.04.4-preinstalled-server-riscv64+unmatched.img,format=raw,if=virtio
106+
```
107+
108+
登录到 Linux,系统会立即要求更改密码
109+
110+
```shell
111+
# 默认用户名和密码
112+
username: ubuntu
113+
password: ubuntu
114+
```
115+
116+
加载 kvm 模块,并验证
117+
118+
```shell
119+
sudo modprobe kvm
120+
ls /dev/
121+
```
122+
123+
/dev 目录下观察到文件 kvm 即可。
124+
125+
## RUST 环境安装
126+
127+
按照官方提供的命令直接安装最新的 RUST 即可。
128+
129+
```shell
130+
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
131+
```
132+
133+
看到提示信息:`Rust is installed now. Great!` 即安装完成。
134+
135+
## 小结
136+
137+
环境配置过程中的源码下载或 RUST 安装等过程难免要从 github 等外网下载内容,请配置解决。
138+
139+
## 参考资料
140+
141+
- [QEMU 官方文档](https://wiki.qemu.org/Documentation/Platforms/RISCV)

0 commit comments

Comments
 (0)