LoginSignup
2
3

More than 3 years have passed since last update.

Debian Buster armhf のOSイメージをAWSの仮想マシンで作る

Last updated at Posted at 2019-07-25

1.何がしたいのか

AWSのEC2に仮想RaspberryPiを作って、高速にビルドがしたい。
いつもウォッチしている、@PINTOさんが仮想環境の構築に成功したので、私もやってみたい

2.なぜAWSで作るの?

DELLに発注した高速マシンがまだ届かないから。
注文してから3週間が経過してしまった。

3.参考にする場所は?

QEMU4.0.0 のハードウェアエミュレーションモードで Debian Buster armhf のOSイメージをゼロから作成する方法 (Kernel 4.19.0-5-armmp-lpae, Tensorflow armhfビルド用)

TensorFlowをひたすら高速でビルドするためだけに、睡眠時間を削って環境を構築した上、貴重なノウハウを公開してくれる@PINTOさんに感謝。

4.構築する環境

クラウドマシン
+ AWS Ubuntu Server 16.04 LTS (HVM), SSD Volume Type (64 ビット x86)
+ t2.xlarge vCPU4,メモリ16GB(無料枠の対象外),SSD 30GB

構築する環境は参考にしているサイトに一致させる
+ QEMU 4.0.0
+ Debian Buster armhf/armv7l (Python 3.7.3)

5.構築作業

全て@PINTOさんの手順に合わせて実行します。
変更分は自分の環境とAWSのクリーンな環境からなので、必要な環境をインストール。
リンク

作業の前にsshの設定を変更します。
AWSにsshで接続すると、比較的短時間でサーバーから切断されて、何度も再接続を強いられます。
15秒毎に信号を送って、接続を維持します。

~/.ssh/config
ServerAliveInterval 15

configureが色々文句をいうので、最後の方は半ばヤケクソで色んなものを一気にインストールしています。

QEMUのセットアップ
$ sudo apt-get update

$ cd ~
$ wget https://download.qemu.org/qemu-4.0.0.tar.xz
$ tar xvJf qemu-4.0.0.tar.xz
$ cd qemu-4.0.0

$ sudo apt update
$ sudo apt upgrade

$ sudo apt-get install build-essential 
$ sudo apt-get install cmake
$ sudo apt-get install pkg-config
$ sudo apt-get install libgtk2.0-0

$ sudo apt-get install build-essential zlib1g-dev pkg-config libglib2.0-dev binutils-dev libboost-all-dev autoconf libtool libssl-dev libpixman-1-dev libpython-dev python-pip python-capstone virtualenv

$ ./configure --python=/usr/bin/python3

Install prefix    /usr/local
BIOS directory    /usr/local/share/qemu
firmware path     /usr/local/share/qemu-firmware
binary directory  /usr/local/bin
library directory /usr/local/lib
module directory  /usr/local/lib/qemu
libexec directory /usr/local/libexec
include directory /usr/local/include
config directory  /usr/local/etc
local state directory   /usr/local/var
Manual directory  /usr/local/share/man
ELF interp prefix /usr/gnemul/qemu-%M
Source path       /home/ubuntu/qemu-4.0.0
GIT binary        git
GIT submodules    
C compiler        cc
Host C compiler   cc
C++ compiler      c++
Objective-C compiler cc
ARFLAGS           rv
CFLAGS            -O2 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -g 
QEMU_CFLAGS       -I/usr/include/pixman-1 -I$(SRC_PATH)/dtc/libfdt  -pthread -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -fPIE -DPIE -m64 -mcx16 -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Wstrict-prototypes -Wredundant-decls -Wall -Wundef -Wwrite-strings -Wmissing-prototypes -fno-strict-aliasing -fno-common -fwrapv -std=gnu99  -Wendif-labels -Wno-missing-include-dirs -Wempty-body -Wnested-externs -Wformat-security -Wformat-y2k -Winit-self -Wignored-qualifiers -Wold-style-declaration -Wold-style-definition -Wtype-limits -fstack-protector-strong -I$(SRC_PATH)/capstone/include
LDFLAGS           -Wl,--warn-common -Wl,-z,relro -Wl,-z,now -pie -m64 -g 
QEMU_LDFLAGS      -L$(BUILD_DIR)/dtc/libfdt 
make              make
install           install
python            /usr/bin/python3 -B (3.5.2)
slirp support     internal 
smbd              /usr/sbin/smbd
module support    no
host CPU          x86_64
host big endian   no
target list       aarch64-softmmu alpha-softmmu arm-softmmu cris-softmmu hppa-softmmu i386-softmmu lm32-softmmu m68k-softmmu microblaze-softmmu microblazeel-softmmu mips-softmmu mips64-softmmu mips64el-softmmu mipsel-softmmu moxie-softmmu nios2-softmmu or1k-softmmu ppc-softmmu ppc64-softmmu riscv32-softmmu riscv64-softmmu s390x-softmmu sh4-softmmu sh4eb-softmmu sparc-softmmu sparc64-softmmu tricore-softmmu unicore32-softmmu x86_64-softmmu xtensa-softmmu xtensaeb-softmmu aarch64-linux-user aarch64_be-linux-user alpha-linux-user arm-linux-user armeb-linux-user cris-linux-user hppa-linux-user i386-linux-user m68k-linux-user microblaze-linux-user microblazeel-linux-user mips-linux-user mips64-linux-user mips64el-linux-user mipsel-linux-user mipsn32-linux-user mipsn32el-linux-user nios2-linux-user or1k-linux-user ppc-linux-user ppc64-linux-user ppc64abi32-linux-user ppc64le-linux-user riscv32-linux-user riscv64-linux-user s390x-linux-user sh4-linux-user sh4eb-linux-user sparc-linux-user sparc32plus-linux-user sparc64-linux-user tilegx-linux-user x86_64-linux-user xtensa-linux-user xtensaeb-linux-user
gprof enabled     no
sparse enabled    no
strip binaries    yes
profiler          no
static build      no
SDL support       no 
SDL image support no
GTK support       no 
GTK GL support    no
VTE support       no 
TLS priority      NORMAL
GNUTLS support    no
libgcrypt         no
nettle            no 
libtasn1          no
PAM               no
iconv support     yes
curses support    no
virgl support     no 
curl support      no
mingw32 support   no
Audio drivers      oss
Block whitelist (rw) 
Block whitelist (ro) 
VirtFS support    no
Multipath support no
VNC support       yes
VNC SASL support  no
VNC JPEG support  no
VNC PNG support   no
xen support       no
brlapi support    no
bluez  support    no
Documentation     no
PIE               yes
vde support       no
netmap support    no
Linux AIO support no
ATTR/XATTR support yes
Install blobs     yes
KVM support       yes
HAX support       no
HVF support       no
WHPX support      no
TCG support       yes
TCG debug enabled no
TCG interpreter   no
malloc trim support yes
RDMA support      no
PVRDMA support    no
fdt support       git
membarrier        no
preadv support    yes
fdatasync         yes
madvise           yes
posix_madvise     yes
posix_memalign    yes
libcap-ng support no
vhost-net support yes
vhost-crypto support yes
vhost-scsi support yes
vhost-vsock support yes
vhost-user support yes
Trace backends    log
spice support     no 
rbd support       no
xfsctl support    no
smartcard support no
libusb            no
usb net redir     no
OpenGL support    no
OpenGL dmabufs    no
libiscsi support  no
libnfs support    no
build guest agent yes
QGA VSS support   no
QGA w32 disk info no
QGA MSI support   no
seccomp support   no
coroutine backend ucontext
coroutine pool    yes
debug stack usage no
mutex debugging   no
crypto afalg      no
GlusterFS support no
gcov              gcov
gcov enabled      no
TPM support       yes
libssh2 support   no
TPM passthrough   
TPM emulator      
QOM debugging     yes
Live block migration yes
lzo support       no
snappy support    no
bzip2 support     no
lzfse support     no
NUMA host support yes
libxml2           no
tcmalloc support  no
jemalloc support  no
avx2 optimization yes
replication support yes
VxHS block device no
bochs support     yes
cloop support     yes
dmg support       yes
qcow v1 support   yes
vdi support       yes
vvfat support     yes
qed support       yes
parallels support yes
sheepdog support  yes
capstone          internal
docker            no
libpmem support   no
libudev           no
default devices   yes

NOTE: cross-compilers enabled:  'cc' 'cc'
make -j4

15分くらいで終わっていた。

$ sudo make install
$ qemu-system-arm --version
QEMU emulator version 4.0.0
Copyright (c) 2003-2019 Fabrice Bellard and the QEMU Project developers

インストールもあっさり終了して、QEMU 4.0インストールできました。

6.仮想マシンの設定

@PINTO さんのGoogleDriveから全てコピーして、エミュレータ上のRaspberryPi-Busterを設定します。
仮想マシンに入ってしまえば、環境の差とかあまり関係ないです。
以下の手順は完全にコピーになってしまいましたので、以後の手順はこちらに移動して実行してください。

QEMU4.0.0 のハードウェアエミュレーションモードで Debian Buster armhf のOSイメージをゼロから作成する方法 (Kernel 4.19.0-5-armmp-lpae, Tensorflow armhfビルド用)

$ cd ~
$ mkdir qemu-system-debian-armhf;cd qemu-system-debian-armhf/

# vmlinuz download 
$ curl -sc /tmp/cookie "https://drive.google.com/uc?export=download&id=15cwDe68vMRoPmz2z789C0_LDElDVHDIx" > /dev/null
$ CODE="$(awk '/_warning_/ {print $NF}' /tmp/cookie)"
$ curl -Lb /tmp/cookie "https://drive.google.com/uc?export=download&confirm=${CODE}&id=15cwDe68vMRoPmz2z789C0_LDElDVHDIx" -o installer-vmlinuz

# initrd.gz download
$ curl -sc /tmp/cookie "https://drive.google.com/uc?export=download&id=1bTMiZ9Nmi1pjguf4wHRkaYaNb_Jb9Pe7" > /dev/null
$ CODE="$(awk '/_warning_/ {print $NF}' /tmp/cookie)"
$ curl -Lb /tmp/cookie "https://drive.google.com/uc?export=download&confirm=${CODE}&id=1bTMiZ9Nmi1pjguf4wHRkaYaNb_Jb9Pe7" -o installer-initrd.gz

# Create disk image
$ qemu-img create -f qcow2 hda.qcow2 20G

# Launch Installer
$ qemu-system-arm -M virt -m 1024 \
  -kernel installer-vmlinuz \
  -initrd installer-initrd.gz \
  -drive if=none,file=hda.qcow2,format=qcow2,id=hd \
  -device virtio-blk-device,drive=hd \
  -netdev user,id=mynet \
  -device virtio-net-device,netdev=mynet \
  -nographic -no-reboot

とりあえず、手順に沿って実行していくと、全部で3時間くらいでインストールが完了します。

このコマンドで実行できます。

仮想マシン起動コマンド
qemu-system-arm -M virt -m 4096 -smp 4 \
  -kernel vmlinuz-4.19.0-5-armmp-lpae \
  -initrd initrd.img-4.19.0-5-armmp-lpae \
  -append 'root=/dev/vda2' \
  -drive if=none,file=hda.qcow2,format=qcow2,id=hd \
  -device virtio-blk-device,drive=hd \
  -netdev user,id=mynet \
  -device virtio-net-device,netdev=mynet \
  -nographic
2
3
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
2
3