概要
RISC-V向けにビルドしたChromiumをエミュレータ上で動作確認しようとした際にエミュレータの起動で躓いたので備忘録として残しておく。
前提
- ホストOS: Ubuntu24.04
手順
QEMUのセットアップ
以下のコマンドでQEMUをセットアップする
sudo apt update
sudo apt install qemu-kvm libvirt-daemon-system libvirt-clients bridge-utils virt-manager qemu-system-misc opensbi u-boot-qemu
sudo usermod -aG libvirt $USER
sudo usermod -aG kvm $USER
コマンドを実行したら一旦ログアウトして再ログインする。
Debian riscv64-virt disk imageのダウンロード
Debian Quick Image Bakerにアクセスし、「Images for riscv64-virt」をクリックしてDebian riscv64-virt disk imageをダウンロードする。
ダウンロード後解凍する。
今回は一旦手元のMacにダウンロードしてアーカイブマネージャを使用して解凍した後Ubuntuマシンにscpして送った。
CLIでのエミュレータの起動
解凍したディレクトリに移動し以下のコマンドを実行する。
qemu-system-riscv64 -machine virt -m 4G -smp 8 -cpu rv64 \
-device virtio-blk-device,drive=hd \
-drive file=image.qcow2,if=none,id=hd \
-device virtio-net-device,netdev=net \
-netdev user,id=net,hostfwd=tcp::2222-:22 \
-bios /usr/lib/riscv64-linux-gnu/opensbi/generic/fw_jump.elf \
-kernel /usr/lib/u-boot/qemu-riscv64_smode/uboot.elf \
-object rng-random,filename=/dev/urandom,id=rng \
-device virtio-rng-device,rng=rng \
-nographic -append "root=LABEL=rootfs console=ttyS0"
起動に成功するとユーザー名とパスワードの入力を求められるのでどちらもdebianと入力するとログインできる。
デスクトップ環境のインストール
エミュレータにログイン後以下のコマンドを実行しroot権限を取得する。
パスワードはroot。
su -
ルート権限取得後以下のコマンドを実行しデスクトップ環境をインストールしエミュレータをシャットダウンする。
apt update
apt upgrade
apt install task-gnome-desktop
shutdown -h now
apt update実行時にたまに以下のエラーが出る。
root@debian:~# apt update
Hit:1 http://deb.debian.org/debian unstable InRelease
Reading package lists... Error!
Error: Encountered a section with no Package: header
Error: Problem with MergeList /var/lib/apt/lists/deb.debian.org_debian_dists_unstable_main_binary-riscv64_Packages
Error: The package lists or status file could not be parsed or opened.
この場合以下のコマンドを実行すると解決する。
rm -rf /var/lib/apt/lists/*
mkdir -p /var/lib/apt/lists/partial
apt clean
apt autoclean
apt update
デスクトップ環境の起動
以下のコマンドでDebianデスクトップ環境を起動する。
qemu-system-riscv64 \
-machine virt \
-m 4G -smp 8 \
-cpu rv64 \
-device virtio-blk-device,drive=hd \
-drive file=image.qcow2,if=none,id=hd \
-device virtio-net-device,netdev=net \
-netdev user,id=net,hostfwd=tcp::2222-:22 \
-bios /usr/lib/riscv64-linux-gnu/opensbi/generic/fw_jump.elf \
-kernel /usr/lib/u-boot/qemu-riscv64_smode/uboot.elf \
-device virtio-gpu-device \
-device virtio-vga \
-display sdl,gl=on \
-device qemu-xhci,id=xhci \
-device usb-kbd,bus=xhci.0 \
-device usb-mouse,bus=xhci.0 \
-append "root=LABEL=rootfs rw"
起動に成功するとパスワードの入力を求められるのでdebianと入力するとログインできる。
