アプリケーション開発ポータルサイト
ServerNote.NET
Amazon.co.jpでPC関連商品タイムセール開催中!
カテゴリー【RaspberryPIDebian
【Raspberry Piメモ・2】Raspbian初期設定
POSTED BY
2023-05-16

【Raspberry Piメモ・1】機材準備、Raspbianインストール、SSH接続

続きです。

1、etcバックアップとパッケージアップデート

いろいろいじる前に、初回ログイン直後にやるのは表題の作業です。

sudo -s
cd /
cp -Rp etc etc.default # 初期値バックアップ
cat /etc/debian_version
10.4 # 現バージョン確認
apt update
apt -y upgrade
apt -y dist-upgrade
sync
reboot # 再起動
cat /etc/debian_version
10.4 # バージョンが上がってる場合あり
apt --purge autoremove # 不要パッケージのクリーンアップ

2、raspi-config 基礎情報の設定

raspi-config

目的によって異なるが、当方は以下のような感じで設定

3 Boot Options -> B2 Wait for Network boot -> No

4 Localisation Options -> I2 Change Timezone -> Asia Tokyo
 -> I4 Change Wi-fi Country -> JP

5 Interfacing Options -> P1 Camera -> No
 -> P2 SSH -> Yes
 -> P3 VNC -> No
 -> P4 SPI -> No
 -> P5 I2C -> Yes
 -> P6 Serial -> Yes
 -> P7 1-Wire -> No
 -> P8 Remote GPIO -> No

6 Overclock -> 設定不要

7 Advanced Options -> A1 Expand Filesystem を選択
これで、SDカードの残り容量がフルで使えるようになる

 -> A2 Overscan -> No
 -> A3 Memory Split -> 16 を入力(64は不要と思われる)
 -> A4 Audio -> 0 Auto
 -> A5 Resolution -> Default
 -> A6 Screen Blanking -> No
 -> A7 Pixel Doubling -> No
 -> A8 GL Driver -> 設定不要
 -> A9 Compositor -> No
 -> AA Pi 4 Video Output -> 設定不要
 -> AB Overlay FS -> No -> No

Finish で再起動

3、ファームウェア更新

rpi-update

 *** Raspberry Pi firmware updater by Hexxeh, enhanced by AndrewS and Dom
 *** Performing self-update
 *** Relaunching after update
 *** 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.19.97-v7+
#############################################################
WARNING: This update bumps to rpi-5.4.y linux tree
See: https://www.raspberrypi.org/forums/viewtopic.php?f=29&t=269769

'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)
 *** Downloading specific firmware revision (this will take a few minutes)
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   168  100   168    0     0   1302      0 --:--:-- --:--:-- --:--:--  1312
100  114M    0  114M    0     0  1200k      0 --:--:--  0:01:37 --:--:--  160k
 *** Updating firmware
 *** Updating kernel modules
 *** depmod 5.4.35-v7+
 *** depmod 5.4.35-v7l+
 *** depmod 5.4.35+
 *** depmod 5.4.35-v8+
 *** Updating VideoCore libraries
 *** Using HardFP libraries
 *** Updating SDK
 *** Running ldconfig
 *** Storing current firmware revision
 *** Deleting downloaded files
 *** Syncing changes to disk
 *** If no errors appeared, your firmware was successfully updated to 8d64ec7016906fb1f2bbe937dd7401705c5acf33
 *** A reboot is needed to activate the new firmware

sync

reboot

4、/boot/config.txtの直接編集

raspi-configでは操作できない設定は、/boot/config.txtを直接編集します。
設定可能項目は、/boot/overlays/READMEに記載されています。
たとえばBluetooth、WiFiがらみの設定に何があるか調べるには

sudo -s
cd /boot

cat overlays/README | grep bt
        See: github.com/notro/fbtft/wiki/FBTFT-on-Raspian
Name:   disable-bt
Load:   dtoverlay=disable-bt
Name:   miniuart-bt
Load:   dtoverlay=miniuart-bt
Name:   pi3-disable-bt
Info:   This overlay has been renamed disable-bt, keeping pi3-disable-bt as an
Name:   pi3-miniuart-bt
Info:   This overlay has been renamed miniuart-bt, keeping pi3-miniuart-bt as
Info:   Overlay for SH1106 OLED via SPI using fbtft staging driver.
Info:   Overlay for SSD1306 OLED via SPI using fbtft staging driver.
Info:   Overlay for SSD1351 OLED via SPI using fbtft staging driver.

cat overlays/README | grep wifi
Name:   disable-wifi
Load:   dtoverlay=disable-wifi
Name:   pi3-disable-wifi
Info:   This overlay has been renamed disable-wifi, keeping pi3-disable-wifi as

などとすればおおまかにわかります。
試しに、オンボードBluetooth、Wi-Fiを無効に、オンボードLEDの点灯点滅を無効にする設定をしてみます。
以下のようにconfig.txtの先頭に書きます。(当方の環境では末尾の[all]ブロック後への記述では設定が効かなかった)

vi /boot/config.txt

# For more options and information see
# http://rpf.io/configtxt
# Some settings may impact device functionality. See link above for details

# Disable onboard controllers
dtoverlay=disable-wifi
dtoverlay=disable-bt

# LED off settings
dtparam=pwr_led_trigger=none,pwr_led_activelow=off # POWER (RED) LED off
dtparam=act_led_trigger=none,act_led_activelow=off # SD ACCESS (GREEN) LED off
dtparam=eth_led0=14 # ETHER LED off
dtparam=eth_led1=14 # ETHER LED off

rebootして、ifconfigにwlanが居ない、hciconfigの出力が無い、状態であれば、Wi-Fi、Bluetoothを無効にした設定が効いています。

pi@raspberrypi:~ $ ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.1.4  netmask 255.255.255.0  broadcast 192.168.1.255
        inet6 2408:210:cd41:4600:1ce9:184f:a64e:9b19  prefixlen 64  scopeid 0x0<global>
        inet6 fe80::d104:d11f:2495:1f60  prefixlen 64  scopeid 0x20<link>
        ether b8:27:eb:fb:cf:a3  txqueuelen 1000  (Ethernet)
        RX packets 276  bytes 25033 (24.4 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 188  bytes 25181 (24.5 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

pi@raspberrypi:~ $ hciconfig
pi@raspberrypi:~ $

Raspberry Pi固有の初期設定はこれくらいで、あとは普通のDebianサーバーですので、同じように設定します。

【Debian】タイムゾーン設定と時刻同期【FreeBSD】
【Debian初期設定1】CD Insatall,Network,apt Kernel/Package Update【Buster】
【Debian初期設定2】group、passwd、sudo、sshログインルール
【Debian初期設定3】bash系シェル初期設定ファイル
【Debian初期設定4】LDロードパスに/usr/local/libを常時加える
【Debian】Sambaインストール/アンインストールメモ【FreeBSD】
DebianにウェブサーバーApache2をセットアップ
DebianにメールサーバーPostfixをセットアップ

こんなところでしょうか。ラズベリーパイを外部公開サーバーにする予定があるなら、ユーザー名pi変更と↑sshログインルール付与は必須です。

次回以降で、GPIOにアナログDACとスピーカつないでラジオにした記録、iOS SwiftとNode.js使ってBLEの操作をした記録など書いていきたいと思います。

※本記事は当サイト管理人の個人的な備忘録です。本記事の参照又は付随ソースコード利用後にいかなる損害が発生しても当サイト及び管理人は一切責任を負いません。
※本記事内容の無断転載を禁じます。
【WEBMASTER/管理人】
自営業プログラマーです。お仕事ください!
ご連絡は以下アドレスまでお願いします★

☆ServerNote.NETショッピング↓
ShoppingNote / Amazon.co.jp
☆お仲間ブログ↓
一人社長の不動産業務日誌
【キーワード検索】