openbsd-riscv64-vm.html - www.codemadness.org - www.codemadness.org saait content files
 (HTM) git clone git://git.codemadness.org/www.codemadness.org
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
       openbsd-riscv64-vm.html (4042B)
       ---
            1 <!DOCTYPE html>
            2 <html dir="ltr" lang="en">
            3 <head>
            4         <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
            5         <meta http-equiv="Content-Language" content="en" />
            6         <meta name="viewport" content="width=device-width" />
            7         <meta name="keywords" content="OpenBSD, RISCV64, RISC-V, QEMU, vm" />
            8         <meta name="description" content="Setup an OpenBSD RISCV-64 VM in QEMU" />
            9         <meta name="author" content="Hiltjo" />
           10         <meta name="generator" content="Static content generated using saait: https://codemadness.org/saait.html" />
           11         <title>Setup an OpenBSD RISCV64 VM in QEMU - Codemadness</title>
           12         <link rel="stylesheet" href="style.css" type="text/css" media="screen" />
           13         <link rel="stylesheet" href="print.css" type="text/css" media="print" />
           14         <link rel="alternate" href="atom.xml" type="application/atom+xml" title="Codemadness Atom Feed" />
           15         <link rel="alternate" href="atom_content.xml" type="application/atom+xml" title="Codemadness Atom Feed with content" />
           16         <link rel="icon" href="/favicon.png" type="image/png" />
           17 </head>
           18 <body>
           19         <nav id="menuwrap">
           20                 <table id="menu" width="100%" border="0">
           21                 <tr>
           22                         <td id="links" align="left">
           23                                 <a href="index.html">Blog</a> |
           24                                 <a href="/git/" title="Git repository with some of my projects">Git</a> |
           25                                 <a href="/releases/">Releases</a> |
           26                                 <a href="gopher://codemadness.org">Gopherhole</a>
           27                         </td>
           28                         <td id="links-contact" align="right">
           29                                 <span class="hidden"> | </span>
           30                                 <a href="feeds.html">Feeds</a> |
           31                                 <a href="pgp.asc">PGP</a> |
           32                                 <a href="mailto:hiltjo@AT@codemadness.DOT.org">Mail</a>
           33                         </td>
           34                 </tr>
           35                 </table>
           36         </nav>
           37         <hr class="hidden" />
           38         <main id="mainwrap">
           39                 <div id="main">
           40                         <article>
           41 <header>
           42         <h1>Setup an OpenBSD RISCV64 VM in QEMU</h1>
           43         <p>
           44         <strong>Last modification on </strong> <time>2021-10-26</time>
           45         </p>
           46 </header>
           47 
           48 <p>This describes how to setup an OpenBSD RISCV64 VM in QEMU.</p>
           49 <p>The shellscript below does the following:</p>
           50 <ul>
           51 <li>Set up the disk image (raw format).</li>
           52 <li>Patch the disk image with the OpenBSD miniroot file for the installation.</li>
           53 <li>Downloads the opensbi and u-boot firmware files for qemu.</li>
           54 <li>Run the VM with the supported settings.</li>
           55 </ul>
           56 <p>The script is tested on the host GNU/Void Linux and OpenBSD-current.</p>
           57 <p><strong>IMPORTANT!: The signature and checksum for the miniroot, u-boot and opensbi
           58 files are not verified. If the host is OpenBSD make sure to instead install the
           59 packages (pkg_add u-boot-riscv64 opensbi) and adjust the firmware path for the
           60 qemu -bios and -kernel options. </strong></p>
           61 <h2>Shellscript</h2>
           62 <pre><code>#!/bin/sh
           63 # mirror list: https://www.openbsd.org/ftp.html
           64 mirror="https://ftp.bit.nl/pub/OpenBSD/"
           65 release="7.0"
           66 minirootname="miniroot70.img"
           67 
           68 miniroot() {
           69         test -f "${minirootname}" &amp;&amp; return # download once
           70 
           71         url="${mirror}/${release}/riscv64/${minirootname}"
           72         curl -o "${minirootname}" "${url}"
           73 }
           74 
           75 createrootdisk() {
           76         test -f disk.raw &amp;&amp; return # create once
           77         qemu-img create disk.raw 10G # create 10 GB disk
           78         dd conv=notrunc if=${minirootname} of=disk.raw # write miniroot to disk
           79 }
           80 
           81 opensbi() {
           82         f="opensbi.tgz"
           83         test -f "${f}" &amp;&amp; return # download and extract once.
           84 
           85         url="${mirror}/${release}/packages/amd64/opensbi-0.9p0.tgz"
           86         curl -o "${f}" "${url}"
           87 
           88         tar -xzf "${f}" share/opensbi/generic/fw_jump.bin
           89 }
           90 
           91 uboot() {
           92         f="uboot.tgz"
           93         test -f "${f}" &amp;&amp; return # download and extract once.
           94 
           95         url="${mirror}/${release}/packages/amd64/u-boot-riscv64-2021.07p0.tgz"
           96         curl -o "${f}" "${url}"
           97 
           98         tar -xzf "${f}" share/u-boot/qemu-riscv64_smode/u-boot.bin
           99 }
          100 
          101 setup() {
          102         miniroot
          103         createrootdisk
          104         opensbi
          105         uboot
          106 }
          107 
          108 run() {
          109         qemu-system-riscv64 \
          110                 -machine virt \
          111                 -nographic \
          112                 -m 2048M \
          113                 -smp 2 \
          114                 -bios share/opensbi/generic/fw_jump.bin \
          115                 -kernel share/u-boot/qemu-riscv64_smode/u-boot.bin \
          116                 -drive file=disk.raw,format=raw,id=hd0 -device virtio-blk-device,drive=hd0 \
          117                 -netdev user,id=net0,ipv6=off -device virtio-net-device,netdev=net0
          118 }
          119 
          120 setup
          121 run
          122 </code></pre>
          123 
          124                         </article>
          125                 </div>
          126         </main>
          127 </body>
          128 </html>