> ## Content Index
> Fetch the complete content index at: https://blog.hacking.pub/llms.txt
> Use this file to discover other available public pages before exploring further.

# xv6 系列一（搭建环境）
- URL: https://blog.hacking.pub/2022/02/04/xv6-xi-lie-da-jian-huan-jing/
- Published: 2022-02-04T12:54:59.000Z
- Updated: 2022-02-04T12:54:59.000Z
- Author: chainhelen

#### 准备

需要三个部分

1. RISC-V 工具链
2. 虚拟机
3. xv6源码

#### 1\. 工具链

###### RISC-V工具链

RISC-V 建议采用手动编译的方式，`brew install riscv-tools`相对于来说比较卡

```
git clone --recursive https://github.com/riscv/riscv-gnu-toolchain

```

代码下载时间比较久

问题：  
a. 如果下载sub module下载失败了，需要进入 `riscv-gnu-toolchain`目录下，重新执行 `git submodule update --init --recursive` 下载  
b. 遇到错误`/bin/sh: flock: command not found`，同上  
c. 遇到错误`configure: error: GNU awk not found`，手动安装`brew install gawk` 以及 `brew install gsed`

###### 工具链编译

```
./configure --prefix=/usr/local/opt/riscv-gnu-toolchain    #配置产物路径
make                                                       #编译

```

###### 添加环境变量

bash 放在 \~/.bash\_profile，如果zsh放在 \~/.zshrc

```
export PATH=$PATH:/usr/local/opt/riscv-gnu-toolchain/bin
source ~/.zshrc

```

键入 `riscv64-unknown-elf-gcc -v` 如果能显示版本说明安装成功

#### 2\. QEMU

```
brew install qemu     

```

#### 3\. xv6

[mit xv6](https://pdos.csail.mit.edu/6.828/2021/xv6.html?ref=blog.hacking.pub) 这里提示下载源码

```
git clone git://github.com/mit-pdos/xv6-riscv.git

```

然后 进入 目录`xv6-riscv`，键入`make && make qemu`