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

**Tensorflow-bin**　[![GitHub stars](https://img.shields.io/github/stars/PINTO0309/Tensorflow-bin.svg?style=social&label=Stars)](https://github.com/PINTO0309/Tensorflow-bin)
<a href="https://github.com/PINTO0309/Tensorflow-bin"><img src="https://github-link-card.s3.ap-northeast-1.amazonaws.com/PINTO0309/Tensorflow-bin.png" width="460px"></a>
**Bazel_bin**　[![GitHub stars](https://img.shields.io/github/stars/PINTO0309/Bazel_bin.svg?style=social&label=Stars)](https://github.com/PINTO0309/Bazel_bin)
<a href="https://github.com/pinto0309/Bazel_bin"><img src="https://github-link-card.s3.ap-northeast-1.amazonaws.com/pinto0309/Bazel_bin.png" width="460px"></a>
# １．Introduction
私はいつも、RaspberryPi3 で Tensorflow をビルドしています。 ただ、Tensorflow はビルドをするために大量のリソースを消費するため、RaspberryPi3 の RAM 1GB では SWAP が大量に発生して micorSDカード を破壊してしまいます。 そこで、Raspbian Buster とほぼ同じ環境を QEMU 4.0.0 の仮想環境上に構築し、さらに、 **`RAM 4GB + CPU 4core`** を実現したうえで、 Tensorflow をビルドしようとしました。 OSをイチからインストールする手順ですのでとても時間が掛かりますが、確実に起動に成功する手順をココに残します。 Tensorflow を自力でビルドする理由は、公式のパッケージがバグっているということと、Tensorflow Lite がデフォルトで無効になっているのを自力で解消しているということだけです。

なお、巷には QEMU の STATICモード による環境構築手順の記事があちこちにありますが、 対象OSが Jessie/Stretch であったり、RAM が 256MB かつ CPU が シングルコア だったり、QEMU のI/O周りにバグがあってまともに動作しなかったり、ネットワークが使えなかったりと、どれもとても使用に耐える環境ではありませんでした。 また、STATICモードは爆速なのですが、規模の大きめなパッケージをビルドしようとすると、途端に QEMU STATICモジュール のバグに遭遇してうまくビルドできません。 ちなみに、Dockerベースのクロスコンパイルを提案している多くの記事は、Dockerのバックグラウンドで QEMU の STATICモジュール を使用していますので、ビルド対象によっては失敗します。 私はビルドスピードを向上することを目的としているわけではなく、ビルドを完走させることが本質と考えていますので、あえて低速なハードウェアエミュレーションモードを採用しています。

今回も、必要なリソース一式を全て公式サイトからダンロードすると遅すぎて日が暮れてしまいますので、私の Google Drive に必要なものをアップロードしました。 QEMUを除く大容量のリソースは私の Google Drive から高速にダウンロードできるようにしてあります。

今回の手順を実施済みのイメージはこの記事の **[こちらのリンク](#%EF%BC%95resources)** からダウンロード可能です。

# ２．Environment

- Ubuntu 16.04 x86_64 (Host PC)
- QEMU 4.0.0
- Debian Buster armhf/armv7l (Python 3.7.3)

# ３．Procedure
## ３−１．Build and install QEMU 4.0.0.

```bash:Setting_of_QEMU_4.0.0
$ 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-arm --version

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

## ３−２．Installing Debian Buster armhf

```bash:Run_the_Debian_Buster_armhf_installer
$ 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
```
![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-21 22:11:11.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/194769/81491c46-23c9-5369-19e1-0817783144dc.png)
![Screenshot 2019-07-21 22:11:18.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/194769/54b43316-73d4-80f6-3f7b-fca66f773c6c.png)
![Screenshot 2019-07-21 22:11:32.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/194769/66202570-9169-4cc4-1e54-967bec05b7ee.png)
![Screenshot 2019-07-21 22:12:02.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/194769/8940fc91-f49e-22cb-c134-c5f758514f58.png)
![Screenshot 2019-07-21 22:12:29.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/194769/1f75a7c0-2e0c-f805-2518-5b905cda9697.png)
![Screenshot 2019-07-21 22:13:24.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/194769/c27af458-0f1f-644c-8e8b-e819beb6d930.png)
![Screenshot 2019-07-21 22:14:15.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/194769/eecda4ea-2373-ae20-339c-fb1140833b46.png)

## ３−３．Extract kernel for running Debian Buster armhf

```bash:Kernel_extraction
$ sudo apt-get install -y libguestfs-tools

$ cd ~/qemu-system-debian-armhf
$ sudo virt-ls -a hda.qcow2 /boot/

System.map-4.19.0-5-armmp-lpae
config-4.19.0-5-armmp-lpae
initrd.img
initrd.img-4.19.0-5-armmp-lpae
initrd.img.old
lost+found
vmlinuz
vmlinuz-4.19.0-5-armmp-lpae
vmlinuz.old

$ sudo virt-copy-out -a hda.qcow2 /boot/vmlinuz-4.19.0-5-armmp-lpae /boot/initrd.img-4.19.0-5-armmp-lpae .
```
![Screenshot 2019-07-21 22:27:11.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/194769/f64d9b99-dd7e-4677-9102-f4a43212249b.png)

## ３−４．Start Debian Buster armhf (CPU 4core, RAM 4GB)

```bash:Start_Debian_Buster_armhf_with_4GB_RAM_and_CPU_4core_configuration
$ 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
```

![Screenshot 2019-07-25 22:56:09.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/194769/3aaafcb0-ae49-b910-63df-502165f12c94.png)

## ３−５．Install sudo command

```console:Enable_sudo_command
$ su -
# apt-get update
# apt-get install sudo
# visudo

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

# exit
```


# ４．Finally

CPU 4core かつ RAM 4GB の環境、最高！！
RaspberryPi4、早く技適通して日本で販売して欲しい。。。

# ５．Resources

**Installation kernel**
https://drive.google.com/open?id=15cwDe68vMRoPmz2z789C0_LDElDVHDIx
https://drive.google.com/open?id=1bTMiZ9Nmi1pjguf4wHRkaYaNb_Jb9Pe7

**Boot kernel**
https://drive.google.com/open?id=1VYQLbATeLxBM30mfGllqvC5tldjAaAxr
https://drive.google.com/open?id=1-i6-bsv8ZNIc4a3wtM1pVnz8B9nVXCn4

**Debian Buster installed qcow2 file**
**<font color="red">【caution】 Change your password to something strong.**
**debian / p[ssw0rd**
英語キーボード設定になっていますので <kbd>[</kbd> は、日本語キーボードの <kbd>@</kbd> に読み替える必要があります。
https://drive.google.com/open?id=1Q6TQ0sDGjucdiUfvmn6ZqXHoSQoMWL6E

# ６．Appendix (Build Tensorflow for RaspberryPi3/4)
Tensorflow build procedure.

## ６−１．Expansion of SWAP area (100MB -> 3GB)

```bash:Install_dphys-swapfile
$ sudo apt-get install dphys-swapfile
$ free -m
              total        used        free      shared  buff/cache   available
Mem:           4042          53        3780           5         208        3822
Swap:          3021           0        3021
```

## ６−２．pip command installation

```bash:Install_pip_command
$ sudo apt-get install -y python3-pip
$ sudo pip3 install pip --upgrade
```

## ６−３．Installation of various tools

```bash:Install_tools
$ sudo apt-get install -y cmake make zip unzip git wget curl
```

## ６−４．Tensorflow build

```bash:Build_Tensorflow
$ sudo apt-get install -y libhdf5-dev libc-ares-dev libeigen3-dev openjdk-11-jdk
$ sudo pip3 install keras_applications==1.0.7 --no-deps
$ sudo pip3 install keras_preprocessing==1.0.9 --no-deps
$ wget https://github.com/PINTO0309/Tensorflow-bin/raw/master/packages/numpy-1.16.4-cp37-cp37m-linux_armv7l.whl
$ wget https://github.com/PINTO0309/Tensorflow-bin/raw/master/packages/h5py-2.9.0-cp37-cp37m-linux_armv7l.whl
$ sudo pip3 install numpy-1.16.4-cp37-cp37m-linux_armv7l.whl
$ sudo pip3 install h5py-2.9.0-cp37-cp37m-linux_armv7l.whl
$ sudo apt-get install -y openmpi-bin libopenmpi-dev
$ sudo -H pip3 install -U --user six numpy wheel mock
$ sudo apt update;sudo apt upgrade

$ cd ~
$ git clone https://github.com/PINTO0309/Bazel_bin.git
$ Bazel_bin/0.24.1/Raspbian_Buster_armhf/install.sh

$ cd ~
$ git clone -b v1.14.0 https://github.com/tensorflow/tensorflow.git
$ cd tensorflow
$ git checkout -b v1.14.0
```

The following problem was solved.
**[#15062](https://github.com/tensorflow/tensorflow/issues/15062), [#21574](https://github.com/tensorflow/tensorflow/issues/21574), [#21855](https://github.com/tensorflow/tensorflow/issues/21855),  [#23082](https://github.com/tensorflow/tensorflow/issues/23082), [#25120](https://github.com/tensorflow/tensorflow/issues/25120), [#25748](https://github.com/tensorflow/tensorflow/pull/25748), [#29617](https://github.com/tensorflow/tensorflow/issues/29617), [#30359](https://github.com/tensorflow/tensorflow/issues/30359)**

```python:tensorflow/lite/python/interpreter.py
# Add the following two lines to the last line
  def set_num_threads(self, i):
    return self._interpreter.SetNumThreads(i)
```

```cpp:tensorflow/lite/python/interpreter_wrapper/interpreter_wrapper.cc
// Corrected the vicinity of the last line as follows
PyObject* InterpreterWrapper::ResetVariableTensors() {
  TFLITE_PY_ENSURE_VALID_INTERPRETER();
  TFLITE_PY_CHECK(interpreter_->ResetVariableTensors());
  Py_RETURN_NONE;
}

PyObject* InterpreterWrapper::SetNumThreads(int i) {
  interpreter_->SetNumThreads(i);
  Py_RETURN_NONE;
}

}  // namespace interpreter_wrapper
}  // namespace tflite
```

```cpp:tensorflow/lite/python/interpreter_wrapper/interpreter_wrapper.h
  // should be the interpreter object providing the memory.
  PyObject* tensor(PyObject* base_object, int i);

  PyObject* SetNumThreads(int i);

 private:
  // Helper function to construct an `InterpreterWrapper` object.
  // It only returns InterpreterWrapper if it can construct an `Interpreter`.
```

```python:tensorflow/lite/tools/make/Makefile
BUILD_WITH_NNAPI=false
```

```python:tensorflow/contrib/__init__.py
from tensorflow.contrib import checkpoint
#if os.name != "nt" and platform.machine() != "s390x":
#  from tensorflow.contrib import cloud
from tensorflow.contrib import cluster_resolver
```

```python:tensorflow/contrib/__init__.py
from tensorflow.contrib.summary import summary

if os.name != "nt" and platform.machine() != "s390x":
  try:
    from tensorflow.contrib import cloud
  except ImportError:
    pass

from tensorflow.python.util.lazy_loader import LazyLoader
ffmpeg = LazyLoader("ffmpeg", globals(),
                    "tensorflow.contrib.ffmpeg")
```

```bash:configure
$ ./configure 
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.google.protobuf.UnsafeUtil (file:/home/debian/.cache/bazel/_bazel_debian/install/f61ff4d38c27bd5cacd410a0fc62f7e0/_embedded_binaries/A-server.jar) to field java.nio.Buffer.address
WARNING: Please consider reporting this to the maintainers of com.google.protobuf.UnsafeUtil
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
WARNING: --batch mode is deprecated. Please instead explicitly shut down your Bazel server using the command "bazel shutdown".
You have bazel 0.24.1- (@non-git) installed.


Please specify the location of python. [Default is /usr/bin/python]: /usr/bin/python3

Found possible Python library paths:
  /usr/local/lib/python3.7/dist-packages
  /usr/lib/python3/dist-packages
Please input the desired Python library path to use.  Default is [/usr/local/lib/python3.7/dist-packages]

Do you wish to build TensorFlow with XLA JIT support? [Y/n]: n
No XLA JIT support will be enabled for TensorFlow.

Do you wish to build TensorFlow with OpenCL SYCL support? [y/N]: n
No OpenCL SYCL support will be enabled for TensorFlow.

Do you wish to build TensorFlow with ROCm support? [y/N]: n
No ROCm support will be enabled for TensorFlow.

Do you wish to build TensorFlow with CUDA support? [y/N]: n
No CUDA support will be enabled for TensorFlow.

Do you wish to download a fresh release of clang? (Experimental) [y/N]: n
Clang will not be downloaded.

Do you wish to build TensorFlow with MPI support? [y/N]: n
No MPI support will be enabled for TensorFlow.

Please specify optimization flags to use during compilation when bazel option "--config=opt" is specified [Default is -march=native -Wno-sign-compare]: 


Would you like to interactively configure ./WORKSPACE for Android builds? [y/N]: n
Not configuring the WORKSPACE for Android builds.

Preconfigured Bazel build configs. You can use any of the below by adding "--config=<>" to your build command. See .bazelrc for more details.
	--config=mkl         	# Build with MKL support.
	--config=monolithic  	# Config for mostly static monolithic build.
	--config=gdr         	# Build with GDR support.
	--config=verbs       	# Build with libverbs support.
	--config=ngraph      	# Build with Intel nGraph support.
	--config=numa        	# Build with NUMA support.
	--config=dynamic_kernels	# (Experimental) Build kernels into separate shared objects.
Preconfigured Bazel build configs to DISABLE default on features:
	--config=noaws       	# Disable AWS S3 filesystem support.
	--config=nogcp       	# Disable GCP support.
	--config=nohdfs      	# Disable HDFS support.
	--config=noignite    	# Disable Apache Ignite support.
	--config=nokafka     	# Disable Apache Kafka support.
	--config=nonccl      	# Disable NVIDIA NCCL support.
Configuration finished
```

High speed build with 4GB of RAM and 2core CPU.

```bash:Build_Tensorflow
$ sudo bazel build \
--config=opt \
--config=noaws \
--config=nogcp \
--config=nohdfs \
--config=noignite \
--config=nokafka \
--config=nonccl \
--local_resources=4096.0,2.0,1.0 \
--copt=-mfpu=neon-vfpv4 \
--copt=-ftree-vectorize \
--copt=-funsafe-math-optimizations \
--copt=-ftree-loop-vectorize \
--copt=-fomit-frame-pointer \
--copt=-DRASPBERRY_PI \
--host_copt=-DRASPBERRY_PI \
//tensorflow/tools/pip_package:build_pip_package
```
![Screenshot 2019-07-26 20:37:35.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/194769/593bad03-5e36-b486-5feb-225c60c0e60c.png)
![Screenshot 2019-07-28 17:41:36.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/194769/6d6546c9-1239-8052-02a2-8d628972d2bf.png)

## ６−５．Generation of Wheel and Installation of Tensorflow

```bash:Build_pip_package_and_Install_Tensorflow
$ su --preserve-environment
# ./bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg
# exit
$ sudo cp /tmp/tensorflow_pkg/tensorflow-1.14.0-cp37-cp37m-linux_arm7l.whl ~
$ cd ~
$ sudo pip3 uninstall tensorflow
$ sudo -H pip3 install tensorflow-1.14.0-cp37-cp37m-linux_armv7l.whl

$ sudo poweroff
```

## ６−６．Extract Tensorflow Wheel File from QEMU Virtual Environment

```bash:Extract_Tensorflow_Wheel_File_from_QEMU_Virtual_Environment
$ sudo virt-ls -a hda.qcow2 /home/debian
.bash_history
.bash_logout
.bashrc
.cache
.gnupg
.local
.profile
Bazel_bin
h5py-2.9.0-cp37-cp37m-linux_armv7l.whl
numpy-1.16.4-cp37-cp37m-linux_armv7l.whl
tensorflow
tensorflow-1.14.0-cp37-cp37m-linux_armv7l.whl

$ sudo virt-copy-out -a hda.qcow2 /home/debian/tensorflow-1.14.0-cp37-cp37m-linux_armv7l.whl .
```

## ６−７．Tensorflow Wheel file for RaspberryPi built with QEMU 4.0.0 + Debian Buster armhf

**Tensorflow v1.14.0 Wheel file built with QEMU 4.0.0 + Debian Buster armhf**
**https://drive.google.com/open?id=1mUP6t4o7xBXhXDTTkS91uluZstqcnQj5**

# ７．Appendix (QEMU4.0.0 STATIC module build procedure)

```bash:QEMU4.0.0_STATIC_module_build_procedure
$ wget https://download.qemu.org/qemu-4.0.0.tar.xz
$ tar xvJf qemu-4.0.0.tar.xz
$ rm qemu-4.0.0.tar.xz
$ cd qemu-4.0.0
$ mkdir build;cd build
$ ../configure \
  --prefix=$(cd ..; pwd)/qemu-user-static \
  --disable-bsd-user \
  --disable-guest-agent \
  --disable-strip \
  --disable-werror \
  --disable-gcrypt \
  --disable-debug-info \
  --disable-debug-tcg \
  --disable-docs \
  --disable-tcg-interpreter \
  --enable-attr \
  --disable-brlapi \
  --disable-linux-aio \
  --disable-bzip2 \
  --disable-bluez \
  --disable-cap-ng \
  --disable-curl \
  --disable-fdt \
  --disable-glusterfs \
  --disable-gnutls \
  --disable-nettle \
  --disable-gtk \
  --disable-rdma \
  --disable-libiscsi \
  --disable-vnc-jpeg \
  --disable-kvm \
  --disable-lzo \
  --disable-curses \
  --disable-libnfs \
  --disable-numa \
  --disable-opengl \
  --disable-vnc-png \
  --disable-rbd \
  --disable-vnc-sasl \
  --disable-sdl \
  --disable-seccomp \
  --disable-smartcard \
  --disable-snappy \
  --disable-spice \
  --disable-libssh2 \
  --disable-libusb \
  --disable-usb-redir \
  --disable-vde \
  --disable-vhost-net \
  --disable-virglrenderer \
  --disable-virtfs \
  --disable-vnc \
  --disable-vte \
  --disable-xen \
  --disable-xen-pci-passthrough \
  --disable-xfsctl \
  --enable-linux-user \
  --disable-system \
  --disable-blobs \
  --disable-tools \
  --static \
  --disable-pie
$ make -j8
$ sudo make install
$ cd ../qemu-user-static/bin
$ for i in *; do mv $i $i-static; done
```