はじめに
実機でビルドの作業をやり始めたけれども、ストレージやCPUの速度、メモリなどハード面にいろいろな制約を抱えていたため、Windows上でdockerを使いRaspberry Piを動かすことにした。
を参考にした。
手順
以下にその手順を記す。
ホスト側で
# docker pull debian # docker run -itd --name "docker-raspi" --privileged debian # docker exec -it docker-raspi bash
コンテナ側
# apt update # apt-get wget unzip fdisk
Debianコンテナでは、psやviすら使用できないので、以下も必要に応じてインストールしておく。
# apt-get install vim procps
後で使うqemu-user-staticをインストール
# apt-get install qemu-user-static
イメージをloopデバイスにマウントする。
# cd ~ # wget https://downloads.raspberrypi.org/raspbian_full_latest # unzip raspbian_full_latest
マウントポイントの作成し、マウントする際に指定するオフセットは、第2パーティションの開始セクタを使用
# mkdir /mnt/image # cd ~ # fdisk 2020-02-13-raspbian-buster-full.img Command (m for help): p Disk 2020-02-13-raspbian-buster-full.img: 6.82 GiB, 7323254784 bytes, 14303232 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disklabel type: dos Disk identifier: 0x97709164 Device Boot Start End Sectors Size Id Type 2020-02-13-raspbian-buster-full.img1 8192 532479 524288 256M c W95 FAT32 (LBA) 2020-02-13-raspbian-buster-full.img2 532480 14303231 13770752 6.6G 83 Linux
確認できたのでマウント
# mount -o loop,offset=$((512*532480)) 2020-02-13-raspbian-buster-full.img /mnt/image
展開先にqemu-arm-staticを入れる
# mv /mnt/image/etc/ld.so.preload /mnt/image/etc/ld.so.preload.bak # cp /usr/bin/qemu-arm-static /mnt/image/usr/bin
Dockerイメージを作成
# cd /mnt/image # tar cf /root/docker-image-raspbian.tar . # exit
ホスト側で
コンテナIDを調べて、コンテナからファイルのコピー
# docker ps # docker cp 45ab8064f2a0:/root/docker-image-raspbian.tar ./
インポートして起動。
# docker import docker-image-raspbian.tar raspbian-x86_64:opentrackonnxruntime # sudo docker run--privileged -it raspbian-x86_64:opentrackonnxruntime /bin/bash