Skip to content

Instantly share code, notes, and snippets.

@clicube
Last active April 30, 2024 00:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save clicube/54380508516bf933f813 to your computer and use it in GitHub Desktop.
Save clicube/54380508516bf933f813 to your computer and use it in GitHub Desktop.
Raspberry Pi セットアップ記録

ミニマム

Bullseye

Disabling services, reducing footprint and I/O

/etc/fstab

...
tmpfs           /tmp            tmpfs   defaults,size=32m,noatime,mode=1777  0      0
tmpfs           /var/tmp        tmpfs   defaults,size=32m,noatime,mode=1777  0      0
tmpfs           /var/log        tmpfs   defaults,size=32m,noatime,mode=0755  0      0
$ sudo rm -rf /tmp/* /var/tmp/* /var/log/*
$ sudo reboot

(create) /etc/systemd/journald.conf.d/030-journal.conf

[Journal]
Storage=persistent
ForwardToSyslog=no
systemctl disable triggerhappy.service
systemctl disable triggerhappy.socket
systemctl disable rsyslog.service
systemctl disable ModemManager

systemctl disable ssh.service
systemctl enable ssh.socket

systemctl disable wpa_supplicant.service
systemctl enable wpa_supplicant@wlan0.service
sudo apt install rng-tools5
(replaces rng-tools)

Last update: 2024/04/07

Raspberry Pi 4B

インストール

Arch ARM

初期設定

mDNS有効化

/etc/systemd/network/en.network

[Network]
...
MulticastDNS=yes

ホスト名・ユーザー名変更

/etc/hostname

arch4

(rootのsshを許可するなどして) rootで直接

# usermod -l pi alarm
# usermod -d /home/pi -m pi

ログ領域のオンメモリ化

/etc/fstab

...
tmpfs           /tmp            tmpfs   defaults,size=32m,noatime,mode=1777  0      0
tmpfs           /var/tmp        tmpfs   defaults,size=32m,noatime,mode=1777  0      0
tmpfs           /var/log        tmpfs   defaults,size=32m,noatime,mode=0755  0      0
$ sudo rm -rf /tmp/* /var/tmp/* /var/log/*
$ sudo reboot

NTP設定 /etc/systemd/timesyncd.conf

[Time]
NTP=2404:1a8:1102::a 2404:1a8:1102::b
FallbackNTP=time.google.com
PollIntervalMaxSec=1d
SaveIntervalSec=infinity

memo cmdline.txt interfaces wpa_supplicant wext log

最終更新: 2022/2/4

インストール

http://www.raspberrypi.org/downloads/

初期設定

raspi-config

  • hostname変更
  • UART有効化
  • コンソール無効化
  • GPUメモリ 16M
  • overscan_* 24 (config.txt直接編集)

ネットワーク設定

/etc/network/interfaces

# interfaces(5) file used by ifup(8) and ifdown(8)
# Include files from /etc/network/interfaces.d:

auto wlan0
iface wlan0 inet dhcp
	wpa-driver wext
	wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

source /etc/network/interfaces.d/*

/etc/dhcpcd.conf

interface eth0
static ip_address=192.168.1.4/24
static routers=192.168.1.1
static domain_name_servers=192.168.1.1 8.8.8.8

/etc/wpa_supplicant/wpa_supplicant.conf

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=JP
network={
	ssid="my-ssid"
	psk=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
}

dhclient が固定IPを上書きするので削除

# apt remove isc-dhcp-client

ログ領域のオンメモリ化

Before

pi@rpi1b:~ $ ls -l /var/log
total 2724
-rw-r--r--  1 root root                 0 Sep 22 09:23 alternatives.log
drwxr-xr-x  2 root root              4096 Sep 22 09:07 apt
-rw-r-----  1 root adm              41256 Feb  5 10:46 auth.log
-rw-r--r--  1 root root                 0 Sep 22 09:23 bootstrap.log
-rw-rw----  1 root utmp               768 Sep 22 10:00 btmp
-rw-r-----  1 root adm             375377 Feb  5 10:50 daemon.log
-rw-r-----  1 root adm              20181 Feb  5 02:08 debug
-rw-r--r--  1 root root                 0 Sep 22 09:23 dpkg.log
-rw-r--r--  1 root root                 0 Sep 22 09:23 faillog
drwxr-sr-x+ 3 root systemd-journal   4096 Sep 22 09:23 journal
-rw-r-----  1 root adm             613317 Feb  5 02:08 kern.log
-rw-rw-r--  1 root utmp            292292 Feb  5 10:46 lastlog
-rw-r-----  1 root adm             608898 Feb  5 02:08 messages
drwx------  2 root root              4096 Sep 22 09:24 private
drwxr-xr-x  3 root root              4096 Sep 22 09:06 runit
-rw-r-----  1 root adm             999183 Feb  5 10:50 syslog
-rw-r-----  1 root adm              11542 Feb  5 02:07 user.log
-rw-rw-r--  1 root utmp             54144 Feb  5 10:46 wtmp

/ect/rc.local

mkdir -p /var/log/apt
mkdir -p /var/log/journal
chown -R root.systemd-journal /var/log/journal
mkdir -p /var/log/private
touch /var/log/lastlog
touch /var/log/wtmp
touch /var/log/btmp
chown root.utmp /var/log/lastlog
chown root.utmp /var/log/wtmp
chown root.utmp /var/log/btmp

mkdir -p /var/log/datadog
chown -R dd-agent.root /var/log/datadog

/etc/fstab

proc            /proc           proc    defaults          0       0
/dev/mmcblk0p1  /boot           vfat    defaults          0       2
/dev/mmcblk0p2  /               ext4    defaults,noatime  0       1
# a swapfile is not a swap partition, so no using swapon|off from here on, use  dphys-swapfile swap[on|off]  for that
tmpfs           /tmp            tmpfs   defaults,size=32m,noatime,mode=1777  0      0
tmpfs           /var/tmp        tmpfs   defaults,size=32m,noatime,mode=1777  0      0
tmpfs           /var/log        tmpfs   defaults,size=32m,noatime,mode=0755  0      0
# rm -rf /var/log/*
# reboot

Datadog ageent(iot)

公式バイナリはarmv6は対応してないので自分でビルドしたものを使用

useradd dd-agent
chown -R dd-agent.root /opt/datadog-agent/run
chown -R dd-agent.root /etc/datadog-agent
cp -r ~/agent/dist/conf.d ~/agent/dist/datadog.conf /etc/datadog-agent

/etc/systemd/timesyncd.conf

[Time]
NTP=ntp.jst.mfeed.ad.jp ntp.nict.jp
FallbackNTP=time.google.com

/ect/rc.local

mkdir -p /var/log/apt

touch /var/log/lastlog
touch /var/log/wtmp
touch /var/log/btmp
chown root.utmp /var/log/lastlog
chown root.utmp /var/log/wtmp
chown root.utmp /var/log/btmp

/etc/fstab

proc            /proc           proc    defaults          0       0
/dev/mmcblk0p1  /boot           vfat    defaults          0       2
/dev/mmcblk0p2  /               ext4    defaults,noatime  0       1
# a swapfile is not a swap partition, so no using swapon|off from here on, use  dphys-swapfile swap[on|off]  for that
tmpfs           /tmp            tmpfs   defaults,size=32m,noatime,mode=1777  0      0
tmpfs           /var/tmp        tmpfs   defaults,size=32m,noatime,mode=1777  0      0
tmpfs           /var/log        tmpfs   defaults,size=32m,noatime,mode=0755  0      0

/etc/rsyslog

編集しなくて良い

シリアルポート設定

sudo raspi-config
cat /boot/cmdline.txt
sudo adduser pi root
sudo adduser pi dialout
sudo cu -b 9600 -s /dev/serial0

/boot/cmdline.txt

dwc_otg.lpm_enable=0 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait

console=ttyAMA0,115200 がないことを確認

Last update: 2024/02/03

Raspberry Pi 3B

インストール

Raspberry imager

OSイメージ

Rapberry OS Lite (64bit)

設定項目

  • ホスト名
  • ユーザー名/パスワード

初期設定

ログ領域のオンメモリ化

Before

pi@rpi3b:~ $ ls -l /var/log
total 32
-rw-r--r--  1 root root                 0 Dec 11 13:54 alternatives.log
drwxr-xr-x  2 root root              4096 Dec 11 13:39 apt
-rw-r--r--  1 root root                 0 Dec 11 13:54 bootstrap.log
-rw-rw----  1 root utmp                 0 Dec 11 13:54 btmp
-rw-r--r--  1 root root                 0 Dec 11 13:54 dpkg.log
-rw-r--r--  1 root root                 0 Dec 11 13:54 faillog
drwxr-sr-x+ 3 root systemd-journal   4096 Dec 11 13:54 journal
-rw-rw-r--  1 root utmp            296296 Feb  3 10:33 lastlog
drwx------  2 root root              4096 Dec 11 13:35 private
lrwxrwxrwx  1 root root                39 Dec 11 13:35 README -> ../../usr/share/doc/systemd/README.logs
drwxr-xr-x  3 root root              4096 Dec 11 13:38 runit
-rw-rw-r--  1 root utmp              9600 Feb  3 10:33 wtmp

/etc/fstab (編集)

proc            /proc           proc    defaults          0       0
PARTUUID=4a45cd85-01  /boot/firmware  vfat    defaults          0       2
PARTUUID=4a45cd85-02  /               ext4    defaults,noatime  0       1
# a swapfile is not a swap partition, no line here
#   use  dphys-swapfile swap[on|off]  for that
tmpfs           /var/tmp        tmpfs   defaults,size=128m,noatime,mode=1777  0      0
tmpfs           /var/log        tmpfs   defaults,size=32m,noatime,mode=0755  0      0

/etc/rc.local

とりあえず不要

ログ出力のために事前にフォルダが必要な場合にここで作成する

設定後に再起動

$ sudo rm -rf /var/log/*
$ sudo rm -rf /var/tmp/*
$ sudo reboot

NTP設定 /etc/systemd/timesyncd.conf

[Time]
NTP=ntp.nict.jp
FallbackNTP=time.google.com

Last update: 2024/03/20

Raspberry Pi 3B

インストール

Raspberry imager

OSイメージ

Rapberry OS Lite Legacy (32bit)

設定項目

  • ホスト名
  • ユーザー名/パスワード
  • Wifi

初期設定

ログ領域のオンメモリ化

$ cat /etc/fstab
proc            /proc           proc    defaults          0       0
PARTUUID=93a0e013-01  /boot/firmware  vfat    defaults          0       2
PARTUUID=93a0e013-02  /               ext4    defaults,noatime  0       1
# a swapfile is not a swap partition, no line here
#   use  dphys-swapfile swap[on|off]  for that
tmpfs           /tmp            tmpfs   defaults,size=32m,noatime,mode=1777  0      0
tmpfs           /var/tmp        tmpfs   defaults,size=32m,noatime,mode=1777  0      0
tmpfs           /var/log        tmpfs   defaults,size=32m,noatime,mode=0755  0      0
$ sudo rm -rf /var/log/* /var/tmp/* /tmp/*
$ sudo reboot

コンソール経由でログインできるように

$ sudo systemctl enable serial-getty@ttyGS0.service

/boot/firmware/config.txt の最終行に dtoverlay=dwc2 を追記

/boot/firmware/cmdline.txtrootwait の後に modules-load=dwc2,g_serial を追記

$ sudo reboot

スワップ無効化

$ free
$ sudo dphys-swapfile swapoff
$ sudo systemctl stop dphys-swapfile
$ sudo systemctl disable dphys-swapfile
$ free

NTP設定 /etc/systemd/timesyncd.conf

[Time]
#NTP=ntp.nict.jp
NTP=2404:1a8:1102::a 2404:1a8:1102::b
FallbackNTP=time.google.com

...

PollIntervalMaxSec=1d
SaveIntervalSec=infinity

サービス無効化

$ sudo systemctl disable ModemManager
$ sudo systemctl disable triggerhappy
$ sudo systemctl disable bluetooth.service
$ sudo systemctl disable rsyslog.service
pi@rpizw:/var/log $ ls -l
total 752
-rw-r--r-- 1 root root 0 Sep 26 09:24 alternatives.log
drwxr-xr-x 2 root root 4096 Sep 26 09:12 apt
-rw-r----- 1 root adm 7545 Dec 18 21:21 auth.log
-rw-r--r-- 1 root root 0 Sep 26 09:24 bootstrap.log
-rw-rw---- 1 root utmp 384 Dec 18 00:00 btmp
-rw-r----- 1 root adm 129676 Dec 18 21:23 daemon.log
-rw-r----- 1 root adm 6546 Dec 18 21:14 debug
-rw-r--r-- 1 root root 0 Sep 26 09:24 dpkg.log
-rw-r--r-- 1 root root 0 Sep 26 09:24 faillog
-rw-r----- 1 root adm 147010 Dec 18 21:14 kern.log
-rw-rw-r-- 1 root utmp 292292 Dec 18 21:15 lastlog
-rw-r----- 1 root adm 139325 Dec 18 21:14 messages
drwx------ 2 root root 4096 Sep 26 09:24 private
-rw-r----- 1 root adm 97473 Dec 18 21:23 syslog
-rw-r----- 1 root adm 184951 Dec 18 20:19 syslog.1
-rw-r----- 1 root adm 310 Dec 18 21:13 user.log
-rw-rw-r-- 1 root utmp 13440 Dec 18 21:15 wtmp

2404:1a8:1102::a 2404:1a8:1102::b

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment