Raspberry Pi 4 で Ubuntu 20.04 LTS をモニターやキーボード無しのヘッドレス起動した時のまとめです.
OS の準備
Raspberry Pi に電源を入れるまでは以下の通りの一般的な手順で行います.
- OSイメージ (Ubuntu) をダウンロード
- SDカードをSD Card Formatter でフォーマット
- balenaEtcher で Ubuntu を SDカードに 焼き込む
起動と接続
PC と Raspberry Pi を有線LANで繋いで,Raspberry Pi を起動します.
Raspberry Pi 用の Ubuntu はホスト名で接続できません.
そのため, Raspberry Pi の IPアドレスを調べる必要があります.
今回は ipコマンドを使います.
Mac の場合は以下のコマンドで homebrew を使ってインストールできます.
brew install iproute2mac
次のコマンドで, PC に繋がっている端末のIPアドレスを表示します.
ip neigh
検索方法がわからなかったので,総当たりのつもりでしたが,今回はMacのIPアドレスがわかっていたので,それ以外に1つしか無かった192.168.4.2で確定できました.
力業になりますが, PC から Raspberry Pi 以外の端末を外したり, sshを総当たりすれば繋がると思います.
IP アドレスがわかったら,次のように ssh で接続します.
ssh ubuntu@[raspberry pi's ip address]
僕の場合は ssh ubuntu@192.168.4.2
でログインしました (pwはubuntu).
途中でパスワードを変更しろと言われるので変更します (もう一度ubuntuにしようとすると単純すぎると怒られます).
Botamochi-MacBook-Pro:~ botamochi$ ssh ubuntu@192.168.4.2
The authenticity of host '192.168.4.2 (192.168.4.2)' can't be established.
ECDSA key fingerprint is SHA256:****************************************.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.4.2' (ECDSA) to the list of known hosts.
ubuntu@192.168.4.2's password:
Warning: No xauth data; using fake authentication data for X11 forwarding.
X11 forwarding request failed on channel 0
You are required to change your password immediately (administrator enforced)
Welcome to Ubuntu 20.04 LTS (GNU/Linux 5.4.0-1008-raspi aarch64)
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage
System information as of Mon May 18 10:43:56 UTC 2020
System load: 0.39 Temperature: 57.9 C
Usage of /: 6.7% of 29.04GB Processes: 133
Memory usage: 7% Users logged in: 0
Swap usage: 0% IPv4 address for eth0: 192.168.4.2
* MicroK8s passes 9 million downloads. Thank you to all our contributors!
https://microk8s.io/
11 updates can be installed immediately.
0 of these updates are security updates.
To see these additional updates run: apt list --upgradable
The programs included with the Ubuntu system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.
Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by
applicable law.
WARNING: Your password has expired.
You must change your password now and login again!
Changing password for ubuntu.
Current password:
New password:
Retype new password:
passwd: password updated successfully
Connection to 192.168.4.2 closed.
パスワードを変えると自動的に再起動するので,再度 ssh でログインします.
これで Raspberry Pi のヘッドレス起動成功です!
ホスト名でログインできるようにする
毎回ipアドレスを検索するのは面倒なので,ホスト名でログインできるようにします.
ssh で Raspberry Pi にログインした状態で,いつも通りライブラリを更新します.
sudo apt-get update
sudo apt-get upgrade
avahi-daemon
をインストールします.
sudo apt-get install avahi-daemon
これで再起動すれば,次回からホスト名 (デフォルトは ubuntu
)でログインできるようになります.
References



コメント