LoginSignup
23
22

More than 3 years have passed since last update.

QEMU4.0.0 + Raspbian Buster による RaspberryPi のエミュレーション環境構築(超シンプル手順バージョン)

Last updated at Posted at 2019-07-22

1.Introduction

RaspberryPi4 (Buster) 相当の RAM 4GB, CPU 4core の仮想環境構築手順はコチラ QEMU4.0.0 のハードウェアエミュレーションモードで Debian Buster armhf のOSイメージをゼロから作成する方法 (Kernel 4.19.0-5-armmp-lpae, Tensorflow armhfビルド用)

Staticモードでのaarch64環境構築は 前々回 で、ハードウェアエミュレーションモードでのaarch64環境構築は 前回 の記事で成功しています。 今回は素の Raspbian Buster イメージ (armv7l/armhf) を使用し、 ハードウェアエミュレーションモード で超手軽に環境を構築し直します。 残念なことに、この手順では シングルコア かつ RAM 256MB になりますので、巨大なパッケージのビルド用途には向きません。 ただ、RaspberryPiの実機が無くても遊べるメリットはあります。 今のところは、RAMが4GBあるいは1GB、CPUコアが4コアの仮想環境を構築する手順を模索中ですので、完成次第別の記事を投稿しようと思います。

2.Environment

  • Ubuntu 16.04 x86_64 (Host PC)
  • QEMU 4.0.0
  • Raspbian Buster (Python 3.7.3)
  • kernel-qemu-4.19.50-buster

3.Procedure

公式サイトから必要なもの一式をダウンロードすると日が暮れますので、私の Google Drive にリソース一式を保存しました。 QEMUそのものを自力でビルドする手順になっていますので、HostPCは Ubuntu 18.04 でも 19.04 でも何でもいいです。 QEMU3.x以前はバグが散見されましたので、なるべく最新安定版のビルドを通した方が色々と幸せになれることが分かりました。

Construction_of_Raspbian_environment_for_QEMU
$ cd ~
$ mkdir qemu-system-raspbian-armhf;cd qemu-system-raspbian-armhf

$ wget https://download.qemu.org/qemu-4.0.0.tar.xz
$ tar xvJf qemu-4.0.0.tar.xz
$ cd qemu-4.0.0
$ ./configure
$ make -j8
$ sudo make install
$ sudo ldconfig
$ qemu-system-arm --version

QEMU emulator version 4.0.0
Copyright (c) 2003-2019 Fabrice Bellard and the QEMU Project developers

$ cd ..

### Download 2019-07-10-raspbian-buster-lite
$ curl -sc /tmp/cookie "https://drive.google.com/uc?export=download&id=104jhVcHqfWPvHu5tFVNvRqtbCFt32Tgv" > /dev/null
$ CODE="$(awk '/_warning_/ {print $NF}' /tmp/cookie)"
$ curl -Lb /tmp/cookie "https://drive.google.com/uc?export=download&confirm=${CODE}&id=104jhVcHqfWPvHu5tFVNvRqtbCFt32Tgv" -o 2019-07-10-raspbian-buster-lite.zip
$ unzip 2019-07-10-raspbian-buster-lite.zip
$ rm 2019-07-10-raspbian-buster-lite.zip

### Download kernel-qemu-4.19.50-buster
$ curl -sc /tmp/cookie "https://drive.google.com/uc?export=download&id=1mrlIfISQlFUM-4urDMiu4jPQwySkBNBc" > /dev/null
$ CODE="$(awk '/_warning_/ {print $NF}' /tmp/cookie)"
$ curl -Lb /tmp/cookie "https://drive.google.com/uc?export=download&confirm=${CODE}&id=1mrlIfISQlFUM-4urDMiu4jPQwySkBNBc" -o kernel-qemu-4.19.50-buster

### Download versatile-pb.dtb
$ curl -sc /tmp/cookie "https://drive.google.com/uc?export=download&id=1xh9_sbAQ-9Db7rbKUhtKYeHFWzvsUq-t" > /dev/null
$ CODE="$(awk '/_warning_/ {print $NF}' /tmp/cookie)"
$ curl -Lb /tmp/cookie "https://drive.google.com/uc?export=download&confirm=${CODE}&id=1xh9_sbAQ-9Db7rbKUhtKYeHFWzvsUq-t" -o versatile-pb.dtb

### Launch Raspbian
$ qemu-system-arm \
  -kernel kernel-qemu-4.19.50-buster \
  -dtb versatile-pb.dtb \
  -m 256 -M versatilepb -cpu arm1176 \
  -serial stdio \
  -append "rw console=ttyAMA0 root=/dev/sda2 rootfstype=ext4 loglevel=8 rootwait fsck.repair=yes memtest=1" \
  -drive file=2019-07-10-raspbian-buster-lite.img,format=raw \
  -no-reboot

たったのコレだけでUbuntuのターミナル内でRaspbianが起動します。 寂しいですね。。。
でも、microSDカードを破壊しなくても良くなりますよ。
Screenshot 2019-07-22 23:22:50.png

4.Reference articles

https://github.com/dhruvvyas90/qemu-rpi-kernel
https://github.com/wimvanderbauwhede/limited-systems/wiki/Raspbian-%22stretch%22-for-Raspberry-Pi-3-on-QEMU

古いRaspbianイメージのダウンロード用サイト
https://downloads.raspberrypi.org/

23
22
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
23
22