From Fedora Project Wiki

< Architectures‎ | RISC-V

Revision as of 11:22, 29 January 2019 by Davidlt (talk | contribs) (Remove pointers to stage4 BBL)

Download the latest disk image

Go to this link for the nightly builds and select the most recent (top) build. Look for the -sda.raw.xz file and download it. It will usually be quite large, around 500-1000 MB.

Uncompress it:

$ unxz Fedora-Developer-Rawhide-xxxx.n.0-sda.raw.xz

Tested disk images

You can find them here: https://dl.fedoraproject.org/pub/alt/risc-v/disk-images/fedora/

These disk images:

  • use "naked" filesystem (/dev/vda, not /dev/vda1);
  • have SELinux set to enforcing=1
  • have restored default SELinux security context (restorecon -Rv /);
  • kernel, initramfs, config and BBL copied out from /boot directory;
  • disk mage is compressed with xz using 16MiB block size;
  • have been booted in QEMU/libvirt a few times to verify;

Root password

riscv

Getting kernel, config, initramfs, BBL

Fedora/RISCV does not support BLS (Boot Loader Specification) More details. The new disk images contain /boot directory from where you can copy out kernel, config, initramfs, BBL (contains embedded kernel). Example:

$ export LIBGUESTFS_BACKEND=direct
$ guestfish \
  add Fedora-Developer-Rawhide-20190126.n.0-sda.raw : run : \
  mount /dev/sda1 / : ls /boot | grep -E '^(bbl|config|initramfs|vmlinuz)' | grep -v rescue
bbl-5.0.0-0.rc2.git0.1.0.riscv64.fc30.riscv64
config-5.0.0-0.rc2.git0.1.0.riscv64.fc30.riscv64
initramfs-5.0.0-0.rc2.git0.1.0.riscv64.fc30.riscv64.img
vmlinuz-5.0.0-0.rc2.git0.1.0.riscv64.fc30.riscv64
$ guestfish \
  add Fedora-Developer-Rawhide-20190126.n.0-sda.raw : run : mount /dev/sda1 / : \
  download /boot/bbl-5.0.0-0.rc2.git0.1.0.riscv64.fc30.riscv64 bbl-5.0.0-0.rc2.git0.1.0.riscv64.fc30.riscv64 : \
  download /boot/config-5.0.0-0.rc2.git0.1.0.riscv64.fc30.riscv64 config-5.0.0-0.rc2.git0.1.0.riscv64.fc30.riscv64 : \
  download /boot/initramfs-5.0.0-0.rc2.git0.1.0.riscv64.fc30.riscv64.img initramfs-5.0.0-0.rc2.git0.1.0.riscv64.fc30.riscv64.img : \
  download /boot/vmlinuz-5.0.0-0.rc2.git0.1.0.riscv64.fc30.riscv64 vmlinuz-5.0.0-0.rc2.git0.1.0.riscv64.fc30.riscv64

You can also use guestmount or QEMU/NBD to mount disk image. Examples:

$ mkdir a
$ guestmount -a $PWD/Fedora-Developer-Rawhide-20190126.n.0-sda.raw -m /dev/sda1 $PWD/a
$ cp a/boot/bbl-5.0.0-0.rc2.git0.1.0.riscv64.fc30.riscv64 .
$ guestunmount $PWD/a
$ sudo modprobe nbd max_part=8
$ sudo qemu-nbd -f raw --connect=/dev/nbd1 $PWD/Fedora-Developer-Rawhide-20190126.n.0-sda.raw
$ sudo fdisk -l /dev/nbd1
Disk /dev/nbd1: 7.5 GiB, 8053063680 bytes, 15728640 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: F0F4268F-1B73-46FF-BABA-D87F075DCCA5

Device      Start      End  Sectors  Size Type
/dev/nbd1p1  2048 15001599 14999552  7.2G Linux filesystem
$ sudo mount /dev/nbd1p1 a
$ sudo cp a/boot/initramfs-5.0.0-0.rc2.git0.1.0.riscv64.fc30.riscv64.img .
$ sudo umount a
$ sudo qemu-nbd --disconnect /dev/nbd1

Note NBD is highly useful if you need to run fdisk, e2fsck (e.g. after VM crash and filesystem lock up), resize2fs. It might be beneficial to look into nbdkit and nbd packages.

Boot under TinyEMU (RISCVEMU)

RISCVEMU recently (2018-09-23) was renamed to TinyEMU (https://bellard.org/tinyemu/).

TinyEMU allow booting Fedora disk images in TUI and GUI modes. You can experiment using JSLinux (no need to download/compile/etc) here: https://bellard.org/jslinux/

Below are instructions how to boot Fedora into X11/Fluxbox GUI mode.

Step 1. Compile TinyEMU:

wget https://bellard.org/tinyemu/tinyemu-2018-09-23.tar.gz
tar xvf tinyemu-2018-09-23.tar.gz
cd tinyemu-2018-09-23
make

Step 2. Setup for booting Fedora:

mkdir fedora
cd fedora
cp ../temu .

# Download pre-built BBL with embedded kernel
wget https://bellard.org/jslinux/bbl64-4.15.bin

# Create configuration file for TinyEMU
cat <<EOF > root-riscv64.cfg
/* VM configuration file */
{
    version: 1,
    machine: "riscv64",
    memory_size: 1400,
    bios: "bbl64-4.15.bin",
    cmdline: "loglevel=3 console=tty0 root=/dev/vda1 rw TZ=${TZ}",
    drive0: { file: "Fedora-Developer-Rawhide-xxxx.n.0-sda.raw" },
    eth0: { driver: "user" },
    display0: {
        device: "simplefb",
        width: 1920,
        height: 1080,
    },
    input_device: "virtio",
}
EOF

# Download disk image and unpack in the same directory

Step 3. Boot it.

./temu -rw root-riscv64.cfg

We need to use -rw if we want our changes to persist in disk image. Otherwise disk image will be loaded as read-only and all changes will not persist after reboot.

Once the system is booted login as root with riscv as password. Finally start X11 with Fluxbox: startx /usr/bin/startfluxbox. To gratefully shutdown just type poweroff into console.

The disk image also incl. awesome and i3 for testing. Dillo is available as a basic web browser (no javascript support) and pcmanfm as file manager.

Boot under QEMU

You will need a very recent version of qemu. If in doubt, compile from upstream qemu sources.

qemu-system-riscv64 \
    -nographic \
    -machine virt \
    -smp 4 \
    -m 2G \
    -kernel bbl \
    -object rng-random,filename=/dev/urandom,id=rng0 \
    -device virtio-rng-device,rng=rng0 \
    -append "console=ttyS0 ro root=/dev/vda1" \
    -device virtio-blk-device,drive=hd0 \
    -drive file=Fedora-Developer-Rawhide-xxxx.n.0-sda.raw,format=raw,id=hd0 \
    -device virtio-net-device,netdev=usernet \
    -netdev user,id=usernet,hostfwd=tcp::10000-:22

The latest disk images (since late 2018) build a proper Fedora kernel, incl. loadable modules and initramfs. If you are using newer disk images you might want to add initramfs option:

    -initrd initramfs-<..>.img

You can also create qcow2 disk image with raw Fedora disk as backing one. This way Fedora raw is unmodified and all changes are written to qcow2 layer. You will need to install libguestfs-tools-c.

qemu-img create -f qcow2 -F raw -b Fedora-Developer-Rawhide-xxxx.n.0-sda.raw tmp.qcow2 20G
virt-resize -v -x --expand /dev/sda1 Fedora-Developer-Rawhide-xxxx.n.0-sda.raw tmp.qcow2 
virt-filesystems --long -h --all -a tmp.qcow2

Then modify above QEMU invocation by changing -drive option to:

-drive file=tmp.qcow2,id=hd0

You can use up to -smp 8, which is helpful for building large projects.

Once machine is booted you can connect via SSH:

ssh -p 10000 -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no root@localhost

Boot with libvirt

Detailed instructions how to install libvirt: https://docs.fedoraproject.org/en-US/quick-docs/getting-started-with-virtualization/

Quick instructions for libvirt installation (tested on Fedora 29):

dnf group install --with-optional virtualization
systemctl start libvirtd
systemctl enable libvirtd

Needs libvirt ≥ 4.7.0 which is the first version with upstream RISC-V support. This is available in Fedora 29. You should be able to boot the disk image using a command similar to this:

# virt-install \
    --name fedora-riscv \
    --arch riscv64 \
    --machine virt \
    --vcpus 4 \
    --memory 2048 \
    --import \
    --disk path=/var/lib/libvirt/images/Fedora-Developer-Rawhide-xxxx.n.0-sda.raw,bus=virtio \
    --boot kernel=/var/lib/libvirt/images/bbl,kernel_args="console=ttyS0 ro root=/dev/vda1" \
    --network network=default,model=virtio \
    --rng device=/dev/urandom,model=virtio \
    --graphics none

The latest disk images (since late 2018) build a proper Fedora kernel, incl. loadable modules and initramfs. If you are using newer disk images you might want to add initramfs snippet initrd=/var/lib/libvirt/images/initramfs to --boot option:

    --boot kernel=/var/lib/libvirt/images/bbl,initrd=/var/lib/libvirt/images/initramfs,kernel_args="console=ttyS0 ro root=/dev/vda1" \

Note that will automatically boot you into the console. If you don't want that add --noautoconsole option. You can later use virsh tool to manage your VM and get to console.

You can use up to --vcpus 8, which is helpful for large projects.

Add --channel name=org.qemu.guest_agent.0 option if you want virsh shutdown <name> to work. This requires qemu-guest-agent to be installed in disk image (available in Developer, GNOME and Minimal disk images starting Oct 15, 2018, but not in Nano disk images).

If you want to change hostname before 1st boot install libguestfs-tools-c and then:

virt-customize -a Fedora-Developer-Rawhide-xxxx.n.0-sda.raw --hostname fedora-riscv-mymagicbox

A quick reference of virsh commands:

  • virsh list --all - list all VMs and their states
  • virsh console <name> - connect to serial console (remember: Escape character is ^])
  • virsh shutdown <name> - power down VM (see above for more details)
  • virsh start <name> - power up VM
  • virsh undefine <name> - remove VM
  • virsh net-list - list network (useful for the next command)
  • virsh net-dhcp-leases <network_name> - list DHCP leases, <network_name> most likely will be default. This is useful when you want to get IPv4 and SSH to the VM.
  • virsh domifaddr <name> - alternative for the above two commands, only shows IPv4 for one VM
  • virsh reset <name> - hard reset VM
  • virsh destroy <name> hard power down of VM

If you want to use ssh user@virtualMachine you can setup libvirt NSS module. See: https://wiki.libvirt.org/page/NSS_module

You might want to expand raw Fedora disk image before setting up VM. Here is one example:

truncate -r Fedora-Developer-Rawhide-xxxx.n.0-sda.raw xxxx.n.0-sda.raw
truncate -s 40G xxxx.n.0-sda.raw
virt-resize -v -x --expand /dev/sda1 Fedora-Developer-Rawhide-xxxx.n.0-sda.raw xxxx.n.0-sda.raw
virt-filesystems --long -h --all -a xxxx.n.0-sda.raw
virt-df -h -a xxxx.n.0-sda.raw

Then adjust --disk path= option in libvirt invocation.

You might want also to setup logging for serial console (in case kernel panics or something else).

For this we will be using two commands: virsh edit <name> (modifying VM XML) and virsh dumpxml <name> (dump VM XML for backup). You need to modify <serial> node by adding <log file='/var/log/libvirt/qemu/fedora-riscv-mymagicbox.serial.log'/>. Then power down and power up the VM.

Alternatively you can use --serial log.file=/.../whatever.serial.log with virt-install command.

If you want less information being displayed during boot then add quiet into kernel_args line, e.g.: kernel_args="console=ttyS0 ro quiet root=/dev/vda1"

Install on the HiFive Unleashed SD card

These are instructions for the HiFive Unleashed board.

The disk image (above) is partitioned, but usually we need an unpartitioned ("naked") filesystem. There are several ways to get this, but the easiest is:

$ guestfish -a Fedora-Developer-Rawhide-xxxx.n.0-sda.raw \
    run : download /dev/sda1 Fedora-Developer-Rawhide-xxxx.n.0-sda1.raw

This creates a naked ext4 filesystem called *-sda1.raw. The naked ext4 filesystem can be copied over the second partition of the SD card.

You can also build a custom bbl+kernel+initramfs to boot directly into the SD card using these sources.

Install on the HiFive Unleashed using NBD server

Look at https://github.com/rwmjones/fedora-riscv-kernel in the sifive_u540 branch. This is quite complex to set up so it's best to ask on the #fedora-riscv IRC channel.

Install Fedora GNOME Desktop on SiFive HiFive Unleashed + Microsemi HiFive Unleashed Expansion board

Detailed instructions are provided by Atish Patra from Western Digital Corporation (WDC). See their GitHub page for details and pictures: https://github.com/westerndigitalcorporation/RISC-V-Linux

So far two GPUs are confirmed to be working: Radeon HD 6450 and Radeon HD 5450.