ใช้ Banana Pi M5 แทน Raspberry Pi 4 (ลง Raspbian)

Somsak Lima
10 min readOct 25, 2022

--

ปัญหาการหาซื้อ Raspberry PI ยากและมีราคาแพง เราลองมาใช้ Banana Pi M5 แทน

สามารถใช้ กล่องอาครีลิกที่ใช้กับ Raspberry Pi3 B+ ได้โดยการคว้านรู USB Type C ให้ใหญ่ขึ้น

Hardware Spec

Tip! แนะนำให้ติดตั้ง Armbian แทนการใช้ Raspbian เพราะจะมีปัญหาการทำงานกับ Docker น้อยกว่า โดยเฉพาะอย่างยิ่งการติดตั้งบน eMMC อ่านวิธีลงในอีกตอนหนึ่ง

เปิดเวป https://wiki.banana-pi.org/Banana_Pi_BPI-M5#Raspbian

และ Download img ไฟล์ Raspbian จาก google drive

เช่น 2022–04–09-raspios-bullseye-arm64-bpi-m5-m2pro-k5.17-sd-emmc.img.xz

ใช้ winrar แตกไฟล์ออกมาเป็น

2022–04–09-raspios-bullseye-arm64-bpi-m5-m2pro-k5.17-sd-emmc.img

0.เปิดโปรแกรม Raspberry Pi Imager หรือใช้ Win32 Disk Imager

CHOOSE OS ให้เลือก Use custom

เลือก ไฟล์ .img ที่แตกออกมา

Choose Storage

เลือก USB SDcard ให้ถูกต้องแล้ว กด write

หรือใช้ Wind32 Disk Imager

เมื่อเขียน SDCard เสร็จ นำ SDcard ไปใส่ใน Banana PI M5 แล้วเปิดไฟเข้า

เปิดไฟแล้วจะเห็น LED ติดสามดวง เขียวน้ำเงินแดง สักครู่ไฟเขียวจะดับ เหลือไฟน้ำเงินกระพริบ และไฟแดงติดค้าง

1. ใช้ user pi password bananapi

2. sudo raspi-config เปิด SSH Service เมนู 3 interface option
I2 SSH

3.ให้ expand file system ให้ใหญ่เต็ม SDCard

sudo raspi-config
เลือก 6.Advanced option เลือก A1 Expand Filesystem

4.เพิ่ม USER ทั่วไป กำหนดให้เป็น SUDOER หรือใช้คำสั่ง sudo ได้
sudo adduser slvp
เพิ่มเข้าไป Group sudoer
sudo usermod -aG sudo slvp แล้ว Reboot ต้องทำไม่นั้นจะใช้ Remote Desptop เพื่อ SDcopy ด้วย User ธรรมดาไม่ได้

อาจใช้วิธียากกว่าโดยแก้ไขไฟล์ด้วยคำสั่ง
sudo visudo

วิธีลบ user
sudo userdel -r -f slvp
sudo deluser -r slvp

5.pi@raspberrypi:~ $ cat /etc/os-release

PRETTY_NAME=”Debian GNU/Linux 11 (bullseye)”
NAME=”Debian GNU/Linux”
VERSION_ID=”11"
VERSION=”11 (bullseye)”
VERSION_CODENAME=bullseye
ID=debian
HOME_URL=”https://www.debian.org/"
SUPPORT_URL=”https://www.debian.org/support"
BUG_REPORT_URL=”https://bugs.debian.org/"

6. ปรับปรุงโปรแกรมที่ติดตั้งให้ทันสมัย

สั่ง upgrade รวดเดียวโดยใช้
sudo apt update -y && sudo apt upgrade -y

หรือสั่งทีละขั้นตอนดังนี้

sudo apt update
sudo apt upgrade
sudo apt full-upgrade -y
sudo apt upgrade -y
sudo apt upgrade — fix-missing
sudo apt autoremove

หาก install ไม่สำเร็จให้ใช้คำสั่ง

sudo apt — fix-broken install

install ไม่สำเร็จเพราะพื้นที่อาจจะเต็ม

7.pi@raspberrypi:~ $ uname -a
Linux raspberrypi 4.9.241-BPI-M5 #2 SMP PREEMPT Mon Jun 21 16:29:40 HKT 2021 aarch64 GNU/Linux

8. install ไม่สำเร็จอาจจะพื้นที่เต็ม E: You don’t have enough free space in /var/cache/apt/archives/.

sudo apt autoremove
sudo apt autoclean

อาจจะเป็นเพราะ SD card เสียหรือเต็ม

9. ติดตั้งโปรแกรมที่มีประโยชน์

sudo apt install xrdp locate lrzsz mc wget git finger -y
sudo updatedb
locate filename

ตั้งค่า Config ใหม่ sudo -AE piwiz

10. ตั้งค่า PI ให้ Ethernet เป็น FIX IP

sudo nano /etc/dhcpcd.conf
interface eth0
static ip_address=192.168.1.100/24
static routers=192.168.1.1
static domain_name_servers=192.168.1.1

11.ติดตั้ง DOCKER (ไม่ต้องใช้ sudo) ใช้ User Pi ห้ามติดตั้งด้วย User ธรรมดา

curl -sSL https://get.docker.com | sh
#sudo groupadd docker
sudo usermod -aG docker $USER
newgrp docker
docker ps
sudo reboot

คำสั่งต่อไปนี้ไม่จำเป็นแล้ว
$ sudo systemctl enable docker.service
$ sudo systemctl enable containerd.service

ถ้าจะทดสอบ

Docker run hello-world

pi@raspberrypi:~ $ sudo docker run hello-world
Unable to find image ‘hello-world:latest’ locally
latest: Pulling from library/hello-world
7050e35b49f5: Pull complete
Digest: sha256:bfea6278a0a267fad2634554f4f0c6f31981eea41c553fdf5a83e95a41d40c38
Status: Downloaded newer image for hello-world:latest

ถ้าจะ update
sudo apt upgrade docker docker-compose

12 sudo docker version

Client: Docker Engine — Community
Version: 20.10.20
API version: 1.41
Go version: go1.18.7
Git commit: 9fdeb9c
Built: Tue Oct 18 18:19:53 2022
OS/Arch: linux/arm64
Context: default
Experimental: true
Server: Docker Engine — Community
Engine:
Version: 20.10.20
API version: 1.41 (minimum version 1.12)
Go version: go1.18.7
Git commit: 03df974
Built: Tue Oct 18 18:18:16 2022
OS/Arch: linux/arm64
Experimental: false
containerd:
Version: 1.6.8
GitCommit: 9cd3357b7fd7218e4aec3eae239db1f68a5a6ec6
runc:
Version: 1.1.4
GitCommit: v1.1.4–0-g5fd4c4d
docker-init:
Version: 0.19.0
GitCommit: de40ad0

13 sudo docker info

Client:
Context: default
Debug Mode: false
Plugins:
app: Docker App (Docker Inc., v0.9.1-beta3)
buildx: Docker Buildx (Docker Inc., v0.9.1-docker)
compose: Docker Compose (Docker Inc., v2.12.0)
Server:
Containers: 4
Running: 0
Paused: 0
Stopped: 4
Images: 2
Server Version: 20.10.20
Storage Driver: overlay2
Backing Filesystem: extfs
Supports d_type: true
Native Overlay Diff: true
userxattr: false
Logging Driver: json-file
Cgroup Driver: systemd
Cgroup Version: 2
Plugins:
Volume: local
Network: bridge host ipvlan macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
Swarm: inactive
Runtimes: runc io.containerd.runc.v2 io.containerd.runtime.v1.linux
Default Runtime: runc
Init Binary: docker-init
containerd version: 9cd3357b7fd7218e4aec3eae239db1f68a5a6ec6
runc version: v1.1.4–0-g5fd4c4d
init version: de40ad0
Security Options:
apparmor
seccomp
Profile: default
cgroupns
Kernel Version: 4.9.241-BPI-M5
Operating System: Debian GNU/Linux 11 (bullseye)
OSType: linux
Architecture: aarch64
CPUs: 4
Total Memory: 3.625GiB
Name: raspberrypi
ID: URKI:GB7O:VBEK:VOET:VHYC:6RB6:HBIV:RAJZ:XDT2:2GLL:SLCQ:N7UF
Docker Root Dir: /var/lib/docker
Debug Mode: false
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:
127.0.0.0/8
Live Restore Enabled: false
WARNING: No swap limit support
WARNING: No cpu cfs quota support
WARNING: No cpu cfs period support
WARNING: No cpu shares support
WARNING: No cpuset support
WARNING: No io.weight support
WARNING: No io.weight (per device) support
WARNING: No io.max (rbps) support
WARNING: No io.max (wbps) support
WARNING: No io.max (riops) support
WARNING: No io.max (wiops) support

14. lsb_release -a

No LSB modules are available.
Distributor ID: Debian
Description: Debian GNU/Linux 11 (bullseye)
Release: 11
Codename: bullseye

15.ติดตั้ง Portainer:9000

ถ้าใช้ Raspbian 64bit

sudo docker pull portainer/portainer-ce:linux-arm64
sudo docker run -d --restart always -p 9000:9000 -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer-ce:linux-arm64

เรียกใช้โดยใช้ Port 9000
http://[RASPBERRY_PI_IP_ADDRESS]:9000

ตั้ง User Name/Password admin/ยาว 8/12 ตัวอักษร
เช่น admin/m2mlorawan หรือ m2mlorawan123

คลิก ICON รูปเรือ

16.Container dont start: ‘setting cgroup config for procHooks process caused: bpf_prog_query(BPF_CGROUP_DEVICE) failed: operation not permitted:

ปัญหาต้องใช ้kernal ใหม่ 5 ขึ้นไป raspbian บางเวอร์ชั่นที่แจกอยู่ที่เวป bananapi อาจจะมีปัญหา

17. ทดสอบ Docker

sudo docker run hello-world

pi@raspberrypi:~ $ sudo docker run hello-world
Unable to find image ‘hello-world:latest’ locally
latest: Pulling from library/hello-world
7050e35b49f5: Pull complete
Digest: sha256:18a657d0cc1c7d0678a3fbea8b7eb4918bba25968d3e1b0adebfa71caddbc346
Status: Downloaded newer image for hello-world:latest
Hello from Docker!
This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the “hello-world” image from the Docker Hub.
(arm64v8)
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.
To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash
Share images, automate workflows, and more with a free Docker ID:
https://hub.docker.com/
For more examples and ideas, visit:
https://docs.docker.com/get-started/

18.ติดตั้ง DOCKER COMPOSER

อาจจะต้องติดตั้ง pip3 ก่อนหากเป็น Armbiam

sudo apt-get install python3-pip

แล้ว

sudo pip3 install docker-compose

เช็ค Version DOCKER COMPOSER

pi@raspberrypi:~ $ docker-compose version
docker-compose version 1.29.2, build unknown
docker-py version: 5.0.3
CPython version: 3.7.3
OpenSSL version: OpenSSL 1.1.1d 10 Sep 2019

19.ติดตั้ง Chirpstack บน Docker ติดตั้ง Chirpstack V.4X

ใช้ user pi

ติดตั้งเลยโดย

git clone https://github.com/brocaar/chirpstack-docker.git
cd chirpstack-docker

แก้ความถี่ https://www.chirpstack.io/gateway-bridge/install/config/

nano ~/chirpstack-docker/configuration/chirpstack-gateway-bridge/chirpstack-gateway-bridge.toml# See https://www.chirpstack.io/gateway-bridge/install/config/ for a full
# configuration example and documentation.
[integration.mqtt.auth.generic]
servers=[“tcp://mosquitto:1883”]
username=””
password=””
[integration.mqtt]
event_topic_template=”as923/gateway/{{ .GatewayID }}/event/{{ .EventType }}”
state_topic_template=”as923/gateway/{{ .GatewayID }}/state/{{ .StateType }}”
command_topic_template=”as923/gateway/{{ .GatewayID }}/command/#”

และแก้เพิ่มความถี่ให้ครบ 8 ช่องความถี่

pico /root/chirpstack-docker/configuration/chirpstack/region_as923.toml

เพิ่มตรงด้านล่างสุดของไฟล์

[[regions.network.extra_channels]]
frequency=923600000
min_dr=0
max_dr=5

[[regions.network.extra_channels]]
frequency=923800000
min_dr=0
max_dr=5

[[regions.network.extra_channels]]
frequency=924000000
min_dr=0
max_dr=5

[[regions.network.extra_channels]]
frequency=924200000
min_dr=0
max_dr=5

[[regions.network.extra_channels]]
frequency=924400000
min_dr=0
max_dr=5

[[regions.network.extra_channels]]
frequency=924600000
min_dr=0
max_dr=5

เสร็จแล้วสั่งเริ่มสร้าง Container

cd /home/pi/chirpstack-docker/
sudo docker-compose up -d

เรียกใช้ Chirp ที่ Port:8080
admin/admin

20.การจัดการ eMMc

ฺBPI จะ Boot ด้วย OS ใน eMMC ก่อนหากบูทไม่ได้แล้วจึงจะบูทด้วย SDCard ดังนั้นถ้าจะให้ Boot จาก SDCard ต้องลบ eMMC ก่อน

ให้ โหลดโปรแกรม aml_usb_burning_tool_V2_setup_v2.2.3.3.zip โดย คลิก แตกไฟล์จะได้ไฟล์ชื่อ V2_setup.exe ทำการติดตั้งบน PC ให้เรียบร้อย

ระหว่างติดตั้งโปรแกรมจะถามว่าจะติดตั้ง Driver ด้วยหรือไม่

ให้ติดตั้งด้วยเลย

เรียก USB Burning Tool
กด SW4 button ข้าง 40pin header เสียบสาย type-c usb เข้า PC

pi@raspberrypi:~ $ sudo fdisk -l
Disk /dev/mmcblk0: 28.89 GiB, 31016878080 bytes, 60579840 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: 0xd97ff7f7
Device Boot Start End Sectors Size Id Type
/dev/mmcblk0p1 8192 532479 524288 256M c W95 FAT32 (LBA)
/dev/mmcblk0p2 532480 60579839 60047360 28.6G 83 Linux
Disk /dev/mmcblk1: 14.56 GiB, 15634268160 bytes, 30535680 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: 0xd97ff7f7
Device Boot Start End Sectors Size Id Type
/dev/mmcblk1p1 8192 532479 524288 256M c W95 FAT32 (LBA)
/dev/mmcblk1p2 532480 30535679 30003200 14.3G 83 Linux
Disk /dev/mmcblk1boot0: 4 MiB, 4194304 bytes, 8192 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
Disk /dev/mmcblk1boot1: 4 MiB, 4194304 bytes, 8192 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

หรือใช้ lsblk

pi@raspberrypi:~ $ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
mmcblk0 179:0 0 28.9G 0 disk
mmcblk0p1 179:1 0 256M 0 part /boot
mmcblk0p2 179:2 0 28.6G 0 part /
mmcblk1 179:32 0 14.6G 0 disk
mmcblk1boot0 179:64 0 4M 1 disk
mmcblk1boot1 179:96 0 4M 1 disk

21.ติดตั้ง gparted

sudo apt install gparted -y

22. ลบ eMMC เพื่อให้ boot จาก SDcard
เช็คก่อนว่า eMMC ใช้ชื่ออะไร ถ้า boot จาก SDcard จะชื่อ /dev/mmcblk1

22.1กรณี eMMC ติดตั้ง Raspbian หรือ Linux บูทจาก eMMC จะชื่อ /dev/mmcblk0

sudo dd if=/dev/zero of=/dev/mmcblk0 bs=1M count=1sync

22.2ใช้ USB_Burning_Tool ลบ

กด SW4 เสียบสาย เรียกโปรแกรม USB_Burning_Tool เปิด Image (Android image) คลิก Erase Flash, Erase Bootloader แล้วคลิก Start
****ต้องทำให้ครบไม่นั้นปุ่ม start จะกดไม่ได้

หน้าจอขึ้น 7% Formatting ให้ดึงสายออก

23. Copy Image to eMMC

ติดตั้ง bpi-tools ก่อน

sudo apt-get install pv
curl -sL https://github.com/BPI-SINOVOIP/bpi-tools/raw/master/bpi-tools 20 | sudo -E bash

แล้ว unzip img ด้วย winrar แล้วใช้ filezilla sftp ไปยัง SDcard ก่อนใช้คำสั่ง bpi-copy เวอร์ชั่น Image ที่ใช้ได้ เช่น 2022–05–25-raspios-bullseye-arm64-hdmi-edid-bpi-m5-m2pro-sd-emmc.img

pi@raspberrypi:~ $ sudo bpi-copy 2022-05-25-raspios-bullseye-arm64-hdmi-edid-bpi-m5-m2pro-sd-emmc.img /dev/mmcblk1
SRC=2022–09–06-ubuntu-20.04-mate-desktop-bpi-m5-m2pro-aarch64-sd-emmc.img
DST=/dev/mmcblk1
COPYMODE=imagetodisk
imagetodisk
bpi-copy(v1.3.4(github)), bananapi image & disk tools
Usage: bpi-copy [OPTIONS]…
bpi-copy [ — help | -v | — version ]
bpi-copy IMGFILE
bpi-copy IMGDIR
bpi-copy IMGFILE DEVICE
bpi-copy DEVICE IMGFILE
Warning: Try to write 2022–09–06-ubuntu-20.04-mate-desktop-bpi-m5-m2pro-aarch64-sd-emmc.img to BOOTDISK /dev/mmcblk1
==============================================================
Thu 10 Nov 2022 09:18:36 AM +07
*** start COPY (blue led on ) …..
INFO: /dev/mmcblk1 : SD/eMMC !!
umount device: /dev/mmcblk1
umount /dev/mmcblk1p1
==============================================================
IMGFILE=2022–09–06-ubuntu-20.04-mate-desktop-bpi-m5-m2pro-aarch64-sd-emmc.img
==============================================================

หากลง Ambian ใช้
sudo bpi-copy Armbian_22.08.7_Bananapim5_bullseye_edge_5.19.16_gnome_desktop.img /dev/mmcblk1

ขนาดไฟล์บูทครั้งแรก

pi@raspberrypi:~ $ df
Filesystem 1K-blocks Used Available Use% Mounted on
udev 1892132 0 1892132 0% /dev
tmpfs 380076 968 379108 1% /run
/dev/mmcblk0p2 3964736 3412432 362012 91% /
tmpfs 1900376 0 1900376 0% /dev/shm
tmpfs 5120 4 5116 1% /run/lock
/dev/mmcblk0p1 258095 51960 206136 21% /boot
tmpfs 380072 20 380052 1% /run/user/1000

ให้ใช้ rasp-config ขยาย Partition หลังจากขยายจะได้พื้นที่ใช้งานเพิ่มขึ้น

pi@raspberrypi:~ $ df
Filesystem 1K-blocks Used Available Use% Mounted on
udev 1892132 0 1892132 0% /dev
tmpfs 380076 980 379096 1% /run
/dev/mmcblk0p2 14700004 3714876 10362556 27% /
tmpfs 1900376 0 1900376 0% /dev/shm
tmpfs 5120 4 5116 1% /run/lock
/dev/mmcblk0p1 258095 51960 206136 21% /boot
tmpfs 380072 20 380052 1% /run/user/1000

จะเห็น /dev/mmcblk0p2 มีขนาดใหญ่ขึ้น

หรืออาจจะใช้คำสั่ง dd (ไม่แนะนำ) แทน BPI-TOOL

sudo dd if=2022–04–09-raspios-bullseye-arm64-bpi-m5-m2pro-k5.17-sd-emmc.img of=/dev/mmcblk1 bs=10MB status=progress

24. วิธี Clone

sudo dd if=/dev/mmcblk0 of=/dev/mmcblk1 bs=10MB status=progress

25. sftp ด้วย Filezilla

เปิด Site Manager

23. eMMC Setup การติดตั้ง OS บน eMMC

จะต้องติดตั้งสองครั้ง คือ ครั้งแรกติดบน SDcard และใช้ OS บน SDcard ฺBPI-Copy Image ไปลงบน eMMC การส่ง image เข้า SDcard ให้ใช้ sftp
- Erase eMMC /dev/mmcblkX
- Write OS image to micro SD card
- Boot Banana Pi M5 from micro SD card
- Write OS image to eMMC (BPI Tools)
- So Linux installation is a two-stage process

24. เช็ค speed HD

sudo hdparm -t — direct /dev/mmcblk0

25.uname -a
Linux raspberrypi 4.9.241-BPI-M5 #2 SMP PREEMPT Mon Jun 21 16:29:40 HKT 2021 aarch64 GNU/Linux
pi@raspberrypi:~ $ sudo rpi-update
VCHI initialization failed
VCHI initialization failed
*** Raspberry Pi firmware updater by Hexxeh, enhanced by AndrewS and Dom
*** Performing self-update
*** Relaunching after update
VCHI initialization failed
VCHI initialization failed
*** Raspberry Pi firmware updater by Hexxeh, enhanced by AndrewS and Dom
*** We’re running for the first time
*** Backing up files (this will take a few minutes)
*** Backing up firmware
*** Backing up modules 4.9.241-BPI-M5
#############################################################
WARNING: This update bumps to rpi-5.15.y linux tree
See: https://forums.raspberrypi.com/viewtopic.php?t=322879

‘rpi-update’ should only be used if there is a specific
reason to do so — for example, a request by a Raspberry Pi
engineer or if you want to help the testing effort
and are comfortable with restoring if there are regressions.

DO NOT use ‘rpi-update’ as part of a regular update process.
##############################################################
Would you like to proceed? (y/N)

sudo reboot

ปัญญาหาที่พบ

  1. สั่ง sudo reboot แล้วค้างที่ไฟติดสามดวง
  2. Boot ตรงจาก SSD ที่ต่อผ่าน USB ไม่ได้
  3. การใช้ Wifi หรือ BT ต้องซื้อ Expansion board มาติดเพิ่ม

Ref.

1.https://wiki.banana-pi.org/Getting_Started_with_M5/M2Pro#Introduction

2.https://www.youtube.com/watch?v=D-UidaSiyeQ

3.https://github.com/bpi-sinovoip/bpi-tools

4.https://forum.banana-pi.org/t/how-to-install-ubuntu-server-20-04-to-m5-emmc/13389/4

--

--

Somsak Lima
Somsak Lima

Written by Somsak Lima

สนับสนุนและส่งเสริมให้ผู้สนใจสามารถใช้งานเทคโนโลยี LoRa และ LoRaWAN ได้ โดยนำความรู้ที่ได้ไปต่อยอดเพื่อใช้งาน

No responses yet