1
0

More than 3 years have passed since last update.

Coral Edge TPU (USB type) を Pi4 + Ubuntu Server 19.10.1 (64 bit) で動作させる : 前編

Last updated at Posted at 2019-12-15
  • 旬なネタが降ってきてくれたおかげで、今年も無事に
    Qiita Advent Calendar に参加することができました。

  • 今年は、ようやく日本で遊ぶことができるようになった
    Pi4 を使って戯れてみたいと思います。

    • 長くなったので、前後編に分割します。
    • 前編では、Pi4 に Ubuntu Server 19.10.1 を install し、
      初期設定を完了するまでを行います。
  • 2020/02/15 追記:

    • Ubuntu 18.04.4 がリリースされ、
      Pi4 でも bionic (LTS) が利用可能になったため、
      そちらでも通用する内容に一部修正しました。

12/13 日のこと

  • 今年は Advent Calendar に乗り遅れちゃったなぁなどと思う、
    ある日の朝、

  • Pi4 向けの 64 bit OS の選択肢は、これまでにもいくつかありましたが、
    4 GB RAM モデルで USB の動作がおかしくなる不具合が報告されており、
    今回の Ubuntu Server 19.10.1 では、それが改善されているとのこと。

  • 早速、見てみます。

Ubuntu Server 19.10.1 for Pi4

  • 公式配布サイト

    • 一応、32 bit OS 版もあるようです。
    • You can install a desktop if you like
      • Server なのにこの心遣い…泣けますね。
  • とりま、download しましょう。

$ export URL='http://ftp.jaist.ac.jp/pub/Linux/ubuntu-cdimage/ubuntu/releases/19.10.1/release'
$ export IMG='ubuntu-19.10.1-preinstalled-server-arm64+raspi3.img.xz'
$ wget -c -t 0 ${URL}/${IMG}
... downloading ... then finished.
$ md5sum $IMG
00a09c3cbf45245dcc43132ba7cf671c
  • 19.10.1 ではなく 18.04.4 を利用する場合はこちら
$ export URL='http://ftp.jaist.ac.jp/pub/Linux/ubuntu-cdimage/ubuntu/releases/18.04.4/release'
$ export IMG='ubuntu-18.04.4-preinstalled-server-arm64+raspi3.img.xz'
$ wget -c -t 0 ${URL}/${IMG}
... downloading ... then finished.
$ md5sum $IMG
2d26ee632a949d8a7f4474350d31b303

install to your micro SD (@ Mac)

  • micro SD に image を焼いていきます。

    • 基本的には Raspbian と同じなので、
      皆様は既に勝手を十分にご存知だと思いますが、
      私の Mac 環境での手順を記載しておきます。
  • micro SD を入れる前に、
    disk の device file 名を確認しておきます。

$ ll /dev/disk*
brw-r-----  1 root  operator    1,   0 12 14 13:54 /dev/disk0
brw-r-----  1 root  operator    1,   1 12 14 13:54 /dev/disk0s1
brw-r-----  1 root  operator    1,   2 12 14 13:54 /dev/disk0s2
brw-r-----  1 root  operator    1,   3 12 14 13:54 /dev/disk0s3
  • micro SD を入れた後、再度 disk の device file 名を確認します。
$ ll /dev/disk*
brw-r-----  1 root  operator    1,   0 12 14 13:54 /dev/disk0
brw-r-----  1 root  operator    1,   1 12 14 13:54 /dev/disk0s1
brw-r-----  1 root  operator    1,   2 12 14 13:54 /dev/disk0s2
brw-r-----  1 root  operator    1,   3 12 14 13:54 /dev/disk0s3
brw-r-----  1 root  operator    1,   4 12 14 14:46 /dev/disk1
brw-r-----  1 root  operator    1,   6 12 14 14:46 /dev/disk1s1
  • /dev/disk1 が新たに現れたので、これが
    挿入した SD の device file だと分かります。
    • image 書き込みの準備のために unmount しておきます。
$ diskutil unmount /dev/disk1s1
$ export DISK='/dev/rdiskX'
$ unxz -c $IMG | sudo dd of=${DISK} bs=16m; sync; echo finished
  • $IMG 変数は先程 download したものを使用しています。
  • finished と出たら、SD を取り出して Pi4 に挿入します。

Pi4 の起動

  • 普通に起動します。

    • Ubuntu Server for RasPi では、login name が
      pi ではなく ubuntu なのでご注意ください。
  • 初期 password も raspberry ではなく ubuntu ですが、
    初回起動時は打ち込んでも通らない場合があります。

    • 焦りますが、boot 処理が一段落してから
      再トライすると通りますので、ご安心ください。
    • ログインに成功すると、新しい password への変更を求められます。

WLAN の設定 : netplan.io

  • Ubuntu Desktop ではおなじみの NetworkManager が、なんと
    Ubuntu Server では入っていないということで、少し狼狽しました。

  • どうやら Ubuntu Server の Network Setting は
    netplan.io というやつが仕切っているようなので、
    無線 LAN の設定をしていきます。

~$ sudo cp -a /etc/netplan/50-cloud-init.yaml /etc/netplan/51-wifi-init.yaml
~$ sudo vi /etc/netplan/51-wifi-init.yaml
  • example を参考に必要な変更を行います。
    • 以下はルーターが IPv4DHCP 運用、
      無線 AP が WPA2-PSK の場合の設定例です。
    • wlan0 の行、変えるのを結構忘れがちなのでご注意を。
~$ cat /etc/netplan/51-wifi-init.yaml 
network:
  wifis:
    wlan0:
      dhcp4: yes
      dhcp6: no
      access-points:
        "your-ssid":
          password: "your-secret-passphrase"
  version: 2
  • 設定後、変更を適用し、再起動します。
    • ↓ exit は ~/.bash_history に
      コマンドログを記帳するためにしています。
~$ sudo netplan apply
~$ sudo reboot; exit
  • 再起動後、無事に接続できていました。
~$ networkctl list
IDX LINK             TYPE               OPERATIONAL      SETUP     
  1 lo               loopback           carrier          unmanaged 
  2 eth0             ether              no-carrier       configuring
  3 wlan0            wlan               routable         configured

3 links listed.

~$ ip a show wlan0
3: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether dc:a6:32:xx:xx:xx brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.117/24 brd 192.168.1.255 scope global dynamic wlan0
       valid_lft 85510sec preferred_lft 85510sec

$ netplan ip leases wlan0
# This is private data. Do not parse.
ADDRESS=192.168.1.117
NETMASK=255.255.255.0
ROUTER=192.168.1.1
SERVER_ADDRESS=192.168.1.1
T1=43200
T2=74044
LIFETIME=86400
DNS=192.168.1.1

apt の設定

  • package を最新にするため、apt の設定を行います。

  • RasPi の CPU は ARM の Cortex-A シリーズなので、
    通常の PC とは package server が異なります。

    CPU architecture package server
    x86_64 (amd64) jp.archive.ubuntu.com
    aarch64, armhf ports.ubuntu.com
  • default の更新 server である ports.ubuntu.com は
    世界中のたくさんの人が利用するので、mirror に変更しましょう。

    • ※文末に mirror server との response 比較しています。
  • 日本の mirror である jp.archive.ubuntu.com でも
    ARM 用の ubuntu-ports/ が用意されているのですが、LTS しかない
    ので、もっともご近所の台湾の mirror を使わせて頂きます。

    • 台湾さんありがとうございます!
~$ cd /etc/apt/ && sudo gzip -k sources.list && cd -
~$ sudo vi /etc/apt/sources.list
  • こんな感じになれば OK です。↓
~$ cat /etc/apt/sources.list | grep ^deb
deb http://ftp.ubuntu-tw.org/ubuntu-ports eoan main restricted universe multiverse
deb http://ftp.ubuntu-tw.org/ubuntu-ports eoan-updates main restricted universe multiverse
deb http://ftp.ubuntu-tw.org/ubuntu-ports eoan-backports main restricted universe multiverse
deb http://ftp.ubuntu-tw.org/ubuntu-ports eoan-security main restricted universe multiverse
  • 続いて apt update, upgrade します。
    まだリリースされて間もないので、ほとんど更新はありませんでした。
~$ sudo apt update && sudo apt upgrade

apt install lubuntu-desktop

  • せっかく desktop package の案内もされていますし、
    まだ LXQt に移行してからの Lubuntu を試したことが無かったので、
    ここでは Lubuntu Desktop を入れてみました。
~$ sudo apt install lubuntu-desktop
  • deb packages の fetch が終わった頃に、こんな CUI Dialog が出ます。
 ┌─────────────────────────────────────┤ Configuring gdm3 ├──────────────────────────────────────┐
 │ A display manager is a program that provides graphical login capabilities for the X Window    │ 
 │ System.                                                                                       │ 
 │                                                                                               │ 
 │ Only one display manager can manage a given X server, but multiple display manager packages   │ 
 │ are installed. Please select which display manager should run by default.                     │ 
 │                                                                                               │ 
 │ Multiple display managers can run simultaneously if they are configured to manage different   │ 
 │ servers; to achieve this, configure the display managers accordingly, edit each of their      │ 
 │ init scripts in /etc/init.d, and disable the check for a default display manager.             │ 
 │                                                                                               │ 
 │ Default display manager:                                                                      │ 
 │                                                                                               │ 
 │                                             gdm3                                              │ 
 │                                             sddm                                              │ 
 │                                                                                               │ 
 │                                                                                               │ 
 │                                            <Ok>                                               │ 
 │                                                                                               │ 
 └───────────────────────────────────────────────────────────────────────────────────────────────┘ 
Processing triggers for libgdk-pixbuf2.0-0:arm64 (2.40.0+dfsg-1build1) ...
Processing triggers for rygel (0.38.1-2ubuntu3.3) ...
Processing triggers for libc-bin (2.30-0ubuntu2) ...
Processing triggers for systemd (242-7ubuntu3.2) ...
Processing triggers for dbus (1.12.14-1ubuntu2) ...
~$ 
  • Lubuntu Desktop を install した後の 16 GB SD の Disk 使用量はこのくらいです。
~$ df -h | sort | grep ^/dev/mmcblk
Filesystem      Size  Used Avail Use% Mounted on
/dev/mmcblk0p1  253M  132M  121M  53% /boot/firmware
/dev/mmcblk0p2   15G  4.9G  8.8G  36% /
  • 8 GB SD でも余裕で入りそうですね!

  • 再起動して、Lubuntu さんが立ち上がるのを待ちます。

~$ sudo reboot; exit

Lubuntu さんのお出まし

  • いつもより少し長めの起動の後、無事に DM が表示されました。

    • gdm3 を選択すると、見慣れた Ubuntu ぽいログイン画面が表示されます。
  • ログイン直後のスクショがこちら↓
    desktop_01.png

    • …Windows 95 かな?
  • Ctrl + Alt + t で QTerminal が起動しました。
    desktop_02.png

    • うむ、User Interface としては、これで十分ですね!

次回予告

  • 次回は、Coral Edge TPU と接続して、
    他の環境とのベンチマークを行なっていきたいと思います。

備考

  • Pi4 で作業している際に wlan0 がよく切れました。

    • dmesg で error: -110 がたくさん出ていたので、
      driver がまだ不安定なのか、はたまた
      5V2A の iPad の AC アダプターが力不足なのか…。
  • reboot すると、またゴキゲンに繋がるのですが、
    時間が経つとほぼ必ず発生するので、有線 LAN に変更しました…。

  • 2020/02/15 追記

    • 久しぶりに 19.10 で起動すると wlan0 が繋がらなかったのですが、
      こちらの対応 :arrow_down: をすると(?)無事に繋がりました。

      $ sudo wpa_cli -i wlan0
      
      > ADD_NETWORK
      > SET_NETWORK 0 ssid "AP_NAME"
      > SET_NETWORK 0 psk "passphrase"
      > ENABLE_NETWORK 0
      > quit
      
      • 18.04 では今の所そのようなことは無いので、
        安定志向の方は 18.04 をお勧めします…

おまけ

ports.ubuntu.com vs ftp.ubuntu-tw.org

  • 一応 response を見てみました。
~$ nslookup ports.ubuntu.com 8.8.8.8
Server:     8.8.8.8
Address:    8.8.8.8#53

Non-authoritative answer:
Name:   ports.ubuntu.com
Address: 91.189.88.150
Name:   ports.ubuntu.com
Address: 2001:67c:1360:8001::22

~$ ping -c 4 91.189.88.150
PING 91.189.88.150 (91.189.88.150) 56(84) bytes of data.
64 bytes from 91.189.88.150: icmp_seq=1 ttl=50 time=248 ms
64 bytes from 91.189.88.150: icmp_seq=2 ttl=50 time=263 ms
64 bytes from 91.189.88.150: icmp_seq=3 ttl=50 time=250 ms
64 bytes from 91.189.88.150: icmp_seq=4 ttl=50 time=264 ms

--- 91.189.88.150 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3001ms
rtt min/avg/max/mdev = 248.189/256.149/263.774/7.211 ms
~$ nslookup ftp.ubuntu-tw.org 8.8.8.8
Server:     8.8.8.8
Address:    8.8.8.8#53

Non-authoritative answer:
ftp.ubuntu-tw.org   canonical name = ftp.ubuntu-tw.net.
ftp.ubuntu-tw.net   canonical name = ncnu.ftp.ubuntu-tw.net.
Name:   ncnu.ftp.ubuntu-tw.net
Address: 163.22.17.70
Name:   ncnu.ftp.ubuntu-tw.net
Address: 2001:e10:6840:17::70

~$ ping -c 4 163.22.17.70
PING 163.22.17.70 (163.22.17.70) 56(84) bytes of data.
64 bytes from 163.22.17.70: icmp_seq=1 ttl=47 time=49.7 ms
64 bytes from 163.22.17.70: icmp_seq=2 ttl=47 time=61.9 ms
64 bytes from 163.22.17.70: icmp_seq=3 ttl=47 time=51.0 ms
64 bytes from 163.22.17.70: icmp_seq=4 ttl=47 time=61.2 ms

--- 163.22.17.70 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3004ms
rtt min/avg/max/mdev = 49.743/55.976/61.928/5.619 ms
  • たぶんこれが一番早いと思います。

EOF

1
0
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
1
0