Raspberry Pi 4のUSB-SSDにubuntu serverをインストールする話

ubuntu serverをRaspberry piにインストールします、と言っても普通に入るので、USB-SSDにインストールします。
っと。USB-SSDブートです

いろいろな方法がありますが、今回は激烈シンプルです。

公式ツール「Raspberry Pi Imager for macos」を使います。
ダウンロードの途中にUbuntu Server for Paspberry pi イメージ(ubuntu-20.04.1-preinstalled-server-arm64+raspi.img.xz)があるので注意な!
それではございません

ダウンロードするのはimagerだぁ!

https://ubuntu.com/tutorials/how-to-install-ubuntu-on-your-raspberry-pi#2-prepare-the-sd-card

起動するとこんな感じ

ツールの使い方は簡単です。OSを選択してSDカードを選択すればWRITE出来ます。OSの種類からUbuntu Server 20.04 LTSを選択します

選べばOKなんですが、今回は「Ubuntu 20.04 LTS 64-bit server」を選びます。
desktopは要りませんw

SDカードと書いていますが、USB-SSDにが選べます。

WRITEすると…

鬼ほど時間がかかります;;

インストールが完了すると、Raspberry piに接続します

ポイントですが、SDカードを抜いて、USBにUSB-SSDを接続します

起動すると… DHCPでネットワークに接続されます…
HDMIを接続していれば問題ないのですが、私は怠惰ですので、DHCPサーバに接続します。
MACのプレフィックスは「dc:a6:32」なので、検索します…

IPv4アドレス/ネットマスクMACアドレスリース時間(秒)
192.168.1.22/24dc:a6:32:70:1c:0386343

192.168.1.22っす

早速、SSHで接続…

ん?アカウントは何ぞなもし?pi/raspberry?とか思っていたらubuntu/ubuntuでしたw

$ ssh ubuntu@192.168.1.22
ubuntu@192.168.1.22's password: 
You are required to change your password immediately (administrator enforced)
Welcome to Ubuntu 20.10 (GNU/Linux 5.8.0-1006-raspi aarch64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

  System information as of Mon Dec 21 12:18:56 UTC 2020

  System load:           1.27
  Usage of /:            1.7% of 117.06GB
  Memory usage:          6%
  Swap usage:            0%
  Temperature:           48.7 C
  Processes:             135
  Users logged in:       0
  IPv4 address for eth0: 192.168.1.22
  IPv6 address for eth0: 2409:250:40c0:2500:dea6:32ff:fe70:1c03


0 updates can be installed immediately.
0 of these updates are security updates.


The list of available updates is more than a week old.
To check for new updates run: sudo apt update

Last login: Mon Dec 21 12:18:36 2020 from 192.168.1.11
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: 
Bad: new password is too simple
New password: 
Retype new password: 
passwd: password updated successfully
Connection to 192.168.1.22 closed.

初期接続すると、パスワードを強制的に更新させられます。
ちなみに、単純なパスワードはNGですw
Bad: new password is too simple

っと、サーバ用途なのでDHCPはNGなので変更します

IPの管理が変わっていたので、泣きそうでしたが、次に設定がありました

/etc/netplan/50-cloud-init.yaml

デフォルトはDHCPなので、削除します

sudo rm /etc/netplan/50-cloud-init.yaml

はい、次に新規を作成します

sudo vi /etc/netplan/99-netcfg.yaml

内容…

network:
    version: 2
    ethernets:
        eth0:
            addresses: [192.168.1.221/24]
            gateway4: 192.168.1.1
            nameservers:
                addresses: [192.168.1.254]
                search: []
            optional: true

次に、反映!!

sudo netplan apply

… もちろん SSHセッションが切れますw
無応答で困ります…

$ ssh ubuntu@192.168.1.221
The authenticity of host '192.168.1.221 (192.168.1.221)' can't be established.
ECDSA key fingerprint is SHA256:LxOWj1RkVooHiZnPy2ZAyY3uBATEDMV8airuDwdqYUg.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '192.168.1.221' (ECDSA) to the list of known hosts.
ubuntu@192.168.1.221's password: 
Welcome to Ubuntu 20.10 (GNU/Linux 5.8.0-1006-raspi aarch64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

  System information as of Mon Dec 21 12:40:57 UTC 2020

  System load:           0.94
  Usage of /:            1.7% of 117.06GB
  Memory usage:          7%
  Swap usage:            0%
  Temperature:           48.7 C
  Processes:             138
  Users logged in:       1
  IPv4 address for eth0: 192.168.1.221
  IPv6 address for eth0: 2409:250:40c0:2500:dea6:32ff:fe70:1c03


0 updates can be installed immediately.
0 of these updates are security updates.


The list of available updates is more than a week old.
To check for new updates run: sudo apt update

Last login: Mon Dec 21 12:28:36 2020 from 192.168.1.11

はい、SSHを新しいIPで接続できるのを確認

sudo apt-get -y install nginx

でWebサーバをインストール…

んで、接続… NG? サービス起動をチェック

$ service --status-all
 [ + ]  apparmor
 [ + ]  apport
 [ + ]  atd
 [ - ]  console-setup.sh
 [ + ]  cron
 [ - ]  cryptdisks
 [ - ]  cryptdisks-early
 [ + ]  dbus
 [ - ]  hwclock.sh
 [ + ]  irqbalance
 [ - ]  iscsid
 [ - ]  keyboard-setup.sh
 [ + ]  kmod
 [ - ]  lvm2
 [ - ]  lvm2-lvmpolld
 [ + ]  multipath-tools
 [ + ]  nginx
 [ - ]  open-iscsi
 [ + ]  plymouth
 [ + ]  plymouth-log
 [ + ]  procps
 [ - ]  rsync
 [ + ]  rsyslog
 [ - ]  screen-cleanup
 [ + ]  ssh
 [ + ]  udev
 [ + ]  ufw
 [ + ]  unattended-upgrades
 [ - ]  uuidd

起動しています。

と言うことはfirewall?
ufwを利用…

$ sudo ufw allow http
Rules updated
Rules updated (v6)

これで接続可能に!(IP間違っていてFirewallが必要なのかは不明w)

今回はubuntu USB-SSDにインストールし、raspberry pi 4 にSDカードレスで動きました。

これでOK!うむぅ〜Raspberry pi のクラスタ ubuntu にするか悩むなw