A memo series for Raspberry Pi-related work. This continues the initial setup: changing the hostname, setting a static IP address, and creating a swap file.
Test Environment
Raspberry Pi 3
Ubuntu 18.04.04 LTS 32-bit
Change the Hostname
$ sudo hostnamectl set-hostname rpi3.nosubject.io
Configure a Static IP Address
I wrote about configuring this from a PC before booting in [Raspberry Pi 3] Installing Ubuntu 18.04 LTS (No Keyboard or Display Required), but if you are already logged in to Ubuntu, do the following.
$ sudo vi /etc/netplan/50-cloud-init.yaml # 内容を編集 $ sudo netplan apply # 設定を反映
# This file is generated from information provided by the datasource. Changes
# to it will not persist across an instance reboot. To disable cloud-init's
# network configuration capabilities, write a file
# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
# network: {config: disabled}
network:
ethernets:
eth0:
addresses:
- 192.168.11.5/24
dhcp4: false
gateway4: 192.168.11.254
nameservers:
addresses:
- 192.168.11.254
version: 2
wifis:
wlan0:
access-points:
myssid012345:
password: mypassword012345
addresses:
- 192.168.11.3/24
dhcp4: false
gateway4: 192.168.11.254
nameservers:
addresses:
- 192.168.11.254
optional: falseCreate Swap
Frequent writes apparently affect the life of the SD card, so you only need to configure swap if it is necessary.
$ sudo apt-get install dphys-swapfile # パッケージ入れる $ sudo dphys-swapfile install # Swapファイルを作って適用 computing size, want /var/swap=1724MByte, checking existing: keeping it $ sudo vi /etc/dphys-swapfile # サイズを変更するにはここを直す --- CONF_SWAPSIZE= +++ CONF_SWAPSIZE=2048
Change Locale and Time Zone
By default it is UTC, so change it to JST. Also add the Japanese locale.
$ date Sat Mar 14 14:51:20 UTC 2020 $ sudo timedatectl set-timezone Asia/Tokyo $ date Sat Mar 14 23:51:33 JST 2020
$ locale -a C C.UTF-8 POSIX en_US.utf8 $ sudo locale-gen ja_JP.UTF-8 Generating locales (this might take a while)… ja_JP.UTF-8… done Generation complete. $ locale -a C C.UTF-8 POSIX en_US.utf8 ja_JP.utf8

Would it be good to write these settings in system-boot's user-data and have them run automatically too?
TODO: Backups, SD Card Life Extension Measures, and Similar Tasks
If you use it as a server without thinking about anything, the SD card will fail in one or two years even without that much access. Brute-force attacks against SSHd come constantly, so log writes from that may be part of the cause.
Take measures like the following.
Extend the Life of a Raspberry Pi SD Card / microSD Card
Complete measures for Raspberry Pi microSD card life
Update
These settings can be run automatically on first boot using the method I wrote about in [Raspberry Pi 4] Headless Install of Ubuntu 20.10: How to Install Without a Keyboard or Display.