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


ビルド愛は、世界のmicroSDカードを救う。
Tensorflow v1.14.0 / v1.15.0 / v2.0.0 の QEMUビルド用です。

# １．Environment
- Ubuntu 16.04 / 18.04 x86_64 (Host PC)
- Debian Buster aarch64 (Guest)
- qemu 4.0.0

# ２．Reference articles
**https://translatedcode.wordpress.com/2017/07/24/installing-debian-on-qemus-64-bit-arm-virt-board/**
**https://www.qemu.org/download/#source**

# ３．Procedure

```bash:QEMU4.0.0の導入とDebianベースイメージの準備
$ 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
$ ./configure
$ make -j8
$ sudo make install
$ qemu-system-aarch64 --version

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


$ cd ~
$ mkdir qemu-system-debian-arm64
$ cd qemu-system-debian-arm64
$ wget -O installer-linux http://http.us.debian.org/debian/dists/buster/main/installer-arm64/current/images/netboot/debian-installer/arm64/linux
$ wget -O installer-initrd.gz http://http.us.debian.org/debian/dists/buster/main/installer-arm64/current/images/netboot/debian-installer/arm64/initrd.gz
$ qemu-img create -f qcow2 hda.qcow2 40G
```

```bash:インストーラの起動
$ qemu-system-aarch64 -M virt -m 8192 -cpu cortex-a53 \
  -kernel installer-linux \
  -initrd installer-initrd.gz \
  -drive if=none,file=hda.qcow2,format=qcow2,id=hd \
  -device virtio-blk-pci,drive=hd \
  -netdev user,id=mynet \
  -device virtio-net-pci,netdev=mynet \
  -nographic -no-reboot
```

![Screenshot 2019-07-06 00:28:57.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/194769/5c3178a7-75e1-5739-132c-346300d023d2.png)
![Screenshot 2019-07-06 00:29:52.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/194769/628cb8f1-08fb-57d4-f3ad-64ac1b16ec1e.png)
![Screenshot 2019-07-06 00:30:26.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/194769/84da5877-7cfb-0de4-a739-54735e946227.png)
![Screenshot 2019-07-06 00:32:54.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/194769/45de08a4-91a1-04fe-6f53-a48990f554f7.png)
![Screenshot 2019-07-06 00:33:19.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/194769/60726020-877d-383f-ec12-eaf9d949037f.png)
![Screenshot 2019-07-06 00:34:52.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/194769/794efb89-7fed-7e78-4a4a-c3fe772ffb5f.png)
![Screenshot 2019-07-06 00:35:50.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/194769/23160674-a0d1-cd26-17da-0d9c3e291081.png)
![Screenshot 2019-07-06 00:36:17.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/194769/98cbf786-94bb-f28d-bd7a-2bd1964bd4db.png)
![Screenshot 2019-07-06 00:36:47.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/194769/4bffaa3e-c1c7-df37-6067-5a8d5a28b2d2.png)
![Screenshot 2019-07-06 00:37:09.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/194769/e08a7e50-67ce-af53-652f-cf579a53d2f1.png)
![Screenshot 2019-07-06 00:37:53.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/194769/d40b447c-de9b-1f90-8ab7-02a5cfe8f717.png)
![Screenshot 2019-07-06 00:42:33.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/194769/95ec14bb-9a5e-ba0c-7640-22bbd0c4fe9a.png)
![Screenshot 2019-07-06 00:43:38.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/194769/b3d42ce3-785d-f672-9e94-25a939dd339c.png)
![Screenshot 2019-07-06 00:44:45.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/194769/ad911f33-35eb-b4b2-eece-6ed8aad5b01f.png)
![Screenshot 2019-07-06 00:45:37.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/194769/1f9d1734-69a5-609c-3486-0d7569446a2f.png)
![Screenshot 2019-07-06 00:46:09.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/194769/9b74cf11-1cdb-efc4-78ea-42e8a38c75da.png)
![Screenshot 2019-07-06 00:46:34.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/194769/a972585c-19b1-7462-49fb-2dc67efbfbf7.png)
![Screenshot 2019-07-06 00:47:46.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/194769/91805270-e5b1-b75a-5dc6-95c8d596f5d5.png)
![Screenshot 2019-07-06 00:48:24.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/194769/e0f23503-6bc8-1402-3fa9-c5cf74cc1b00.png)
![Screenshot 2019-07-06 00:50:09.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/194769/b039b70e-68b9-86b5-c678-dad03dfd9d0a.png)
![Screenshot 2019-07-06 00:50:38.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/194769/ba566634-2106-fc77-267e-0379526eb315.png)
![Screenshot 2019-07-06 01:02:53.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/194769/dd854823-39fe-e2e6-fc07-a3d77ee23cac.png)
![Screenshot 2019-07-06 01:03:32.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/194769/e6382caa-652c-0378-a054-66a4f391b463.png)
![Screenshot 2019-07-06 14:23:53.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/194769/09e9862c-d8a2-5b21-f2aa-acd8519087e6.png)
![Screenshot 2019-07-06 01:04:44.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/194769/b6de24dd-316d-3fb9-9e6e-b47ea0a0d833.png)
![Screenshot 2019-07-06 01:06:15.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/194769/3898f81f-43f4-2b2e-0e68-8ed051be813c.png)
![Screenshot 2019-07-06 01:43:38.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/194769/a3cb01eb-51e4-3138-2507-05589ece78a5.png)
![Screenshot 2019-07-06 01:44:27.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/194769/83f7016c-9126-3d3c-8c8d-0cc48ed9999d.png)
![Screenshot 2019-07-06 01:46:24.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/194769/082f1847-4321-1fcd-3402-41c512dc13f5.png)
![Screenshot 2019-07-06 01:47:57.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/194769/fd0307fb-3f78-1938-9d39-6106c5218d10.png)
![Screenshot 2019-07-06 08:23:46.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/194769/faf93bfa-0f91-6677-bfd3-0fc8aa99af9f.png)
![Screenshot 2019-07-06 08:25:10.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/194769/4e32e6ef-edf3-a812-3851-9b4edacf2201.png)
![Screenshot 2019-07-06 08:26:32.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/194769/d295aea1-97bf-47b7-63fc-9605daaf3f36.png)
![Screenshot 2019-07-06 08:31:39.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/194769/94824f34-f196-9fe1-8943-2ae2e3cc0080.png)

```bash:カーネルの抽出
$ sudo apt-get install -y libguestfs-tools

$ sudo virt-filesystems -a hda.qcow2 
/dev/sda1
/dev/sda2

$ sudo virt-ls -a hda.qcow2 /boot/
System.map-4.19.0-6-arm64
config-4.19.0-6-arm64
initrd.img
initrd.img-4.19.0-6-arm64
initrd.img.old
lost+found
vmlinuz
vmlinuz-4.19.0-6-arm64
vmlinuz.old

$ sudo virt-copy-out -a hda.qcow2 /boot/vmlinuz-4.19.0-6-arm64 /boot/initrd.img-4.19.0-6-arm64 .
```
![qemu-system-debian-arm64 - ファイルマネージャー_012.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/194769/510649b4-0c54-c43f-0077-9b5ecbf900a9.png)

```bash:Debian_Buster_起動
$ cd ~/qemu-system-debian-arm64
$ qemu-system-aarch64 -M virt -m 10240 -cpu cortex-a53 -smp 8 \
  -kernel vmlinuz-4.19.0-6-arm64 \
  -initrd initrd.img-4.19.0-6-arm64 \
  -append 'root=/dev/vda2' \
  -drive if=none,file=hda.qcow2,format=qcow2,id=hd \
  -device virtio-blk-pci,drive=hd \
  -netdev user,id=mynet \
  -device virtio-net-pci,netdev=mynet \
  -nographic
```
![Screenshot 2019-07-06 10:04:25.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/194769/4cd3e9bd-c95b-bf3b-5839-d811561cfcc0.png)
![Terminal - b920405@ubuntu: ~-qemu-system-debian-arm64_013.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/194769/bd36740d-1c3c-1ec8-0ce6-ecebace55b7b.png)


```bash:カーネルとアーキテクチャの確認
$ uname -a
Linux debian 4.19.0-6-arm64 #1 SMP Debian 4.19.67-2+deb10u1 (2019-09-20) aarch64 GNU/Linux
```
![Terminal - b920405@ubuntu: ~-qemu-system-debian-arm64_014.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/194769/bb4cbb92-f170-af7b-e31e-2d76511d8ee3.png)

```console:sudoコマンドの有効化
$ su -
# apt-get update
# apt-get install sudo
# visudo

====================================
# User privilege specification
root    ALL=(ALL:ALL) ALL
debian  ALL=(ALL) ALL
====================================

# exit
```