在虚拟机 virtualbox Ubuntu 18.04 中搭建6.828的实验环境

在虚拟机 virtualbox Ubuntu 18.04 中搭建6.828的实验环境

操作系统: Windows 10 家庭版
在 Windows 10 系统中,安装virtualbox, 在virtualbox中安装Ubuntu18.04,最后在Ubuntu 18.04 中,编译 riscv 工具链,qemu已经在18.04默认安装了,不必再安装。

  1. 获取 riscv toolchain 源码
    git clone --recursive https://github.com/riscv/riscv-gnu-toolchain

    如果一些仓库获取失败,可以运行如下命令:
    cd riscv-gnu-toolchain
    git submodule update --init --recursive

    1.1 比如,我在获取源码时,boringssl 就不能下载下来,Google 搜索boringssl 找到了一个GitHub上的镜像链接:https://github.com/google/boringssl.git . 然后在目录: ./riscv-gnu-toolchain/qemu/roms/edk2/CryptoPkg/Library/OpensslLib/openssl/boringssl 下运行如下命令:cd ./riscv-gnu-toolchain/qemu/roms/edk2/CryptoPkg/Library/OpensslLib/openssl/
    rm -r boringssl
    git clone https://github.com/google/boringssl.git

    成功后,运行如下命令,如果还有下载失败的仓库,可以从步骤1.1开始,单独下载源码
    cd ./riscv-gnu-toolchain/
    git submodule update --init --recursive

  2. 编译前,需要准备的工具以及库
    sudo apt-get install autoconf automake autotools-dev curl libmpc-dev libmpfr-dev libgmp-dev gawk build-essential bison flex texinfo gperf libtool patchutils bc zlib1g-dev libexpat-dev

  3. 编译 riscv 工具链,假设你将编译好的 riscv 工具链安装在 /usr/loca 中,这个路径可以根据自己的喜好替换,但是替换后的路径要在$PATH 环境变量中可以找到。
    cd ./riscv-gnu-toolchain
    ./configure --prefix=/usr/local
    sudo make

  4. 至此,riscv 工具链已经成功编译完成,可以运行如下命令加以验证
    $ riscv64-unknown-elf-gcc --version
    riscv64-unknown-elf-gcc (GCC) 9.2.0 Copyright (C) 2019 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

    $ qemu-system-riscv64 --version
    QEMU emulator version 4.1.0 Copyright (c) 2003-2019 Fabrice Bellard and the QEMU Project developers
    注意:如果提示找不到 riscv64-unknown-elf-gcc ,应该将 /usr/local/bin 目录添加至$PATH 中

  5. 编译以及运行xv6
    cd ./xv6-riscv
    $ make qemu
    ...
    init: starting sh
    $

    如果碰到错误: qemu-system-riscv64: cannot set up guest memory 'riscv_virt_board.ram': Cannot allocate memory Makefile:161: recipe for target 'qemu' failed make: *** [qemu] Error 1
    这是因为,虚拟机没有足够的内存可供分配,有两种方法,一种是增加虚拟机的内存,另一种是减小xv6系统的分配内存,修改xv6的Makefile,方法如下:

    vim Makefile
    搜索/-m 3G
    可以找到这行 QEMUOPTS = -machine virt -bios none -kernel $K/kernel -m 3G -smp $(CPUS) -nographic
    将 3G 修改为 1.5G,重新运行 make qemu,应该可以启动成功,如果还不能,就继续减少内存大小。

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

友情链接更多精彩内容