public_notes/content/20240204184839 raspi4 家サーバー 作業ログ 1.md
2024-02-12 10:32:43 +09:00

7.8 KiB
Executable file
Raw Blame History

20240204184839 raspi4 家サーバー 作業ログ

#tech #raspi #server

買ったもの

  • 【国内正規代理店品】Raspberry Pi4 ModelB 4GB ラズベリーパイ4 技適対応品【RS・OKdo版】 https://amazon.co.jp/dp/B081YD3VL5

  • Smraza Raspberry Pi 4 USB-C (Type C電源、5V 3A ラズベリーACアダプター RPi 4b Model B 1GB / 2GB / 4GB/ 8GB適用 https://amazon.co.jp/dp/B07DN5V3VN

  • Flirc ラズベリーパイ4ケース シルバー https://amazon.co.jp/dp/B07WG4DW52

  • 動作せず変更予定 CFD SSD M.2 NVMe RGAX シリーズ 3D NAND TLC採用 SSD PCIe Gen3×4 (読み取り最大3100MB/S) M.2-2280 NVMe 内蔵SSD1TB CSSD-M2L1TRGAXN 国内メーカー https://amazon.co.jp/dp/B0C4NQWQ4K

  • ORICO M.2 SSDケース USB-C to NVMe M-Key / B&M KeyNvmeのみに対応 USB 3.1 Gen2 10Gbps 外付けケース ABS+アルミ材質 UASPサポート2230/2242/2260/2280 SSD対応 M.2 SSD 変換アダプタ エンクロージャ ケース 黑 M2PV-BK https://amazon.co.jp/dp/B08GC326LL

20240204 最初のセットアップ

Raspberry Pi Imagerを使ってSDカードを作成

Install Raspberry Pi OS using Raspberry Pi Imager のDownload for * で自分の環境用のRaspberry Pi Imagerをダウンロード、インストール

起動したら、

  • Raspberry PIデバイス: RASPBERRY PI4
  • OS: Raspberry Pi OS(other) -> Raspberry Pi OS Lite(64-bit)
  • ストレージ: マイクロSDカードをPCに接続して、それを選ぶ Would you like to apply OS customization settings? で「設定を編集する」ボタンを押す。
  • 一般 ホスト名、ユーザー名とパスワード、ロケールなど適切に設定
  • サービス SSHを有効にする をチェック パスワード認証を使う
  • オプション 編集せず で保存ボタンを押す。 Would you like to apply OS customization settings? で、 「はい」を選んで書き込み。

ルーターの設定

  • DHCPスタティックIP設定 を追加

起動

書きこんだらRaspi 4に挿して、LANケーブルなど繋いで起動。 wsl2上のubuntuから、sshで接続確認。

sshを公開鍵認証にする

以下はwsl2のubuntuでやる。

$ ssh-keygen -t ed25519 
Generating public/private ed25519 key pair.
Enter file in which to save the key (/home/kazbo/.ssh/id_ed25519):
Enter passphrase (empty for no passphrase):(Enterを押す)
Enter same passphrase again:(Enterを押す)
Your identification has been saved in /home/kazbo/.ssh/id_ed25519
Your public key has been saved in /home/kazbo/.ssh/id_ed25519.pub
The key fingerprint is:
SHA256: ...  
The key's randomart image is:
+--[ED25519 256]--+
...
+----[SHA256]-----+

.ssh/に id_ed25519 id_ed25519.pub の2つのファイルができている。

$ cat .ssh/id_ed25519.pub

とやって表示される文字列

ssh-ed25519 ...

をコピーしておく。

raspi側で

$ mkdir .ssh
$ touch .ssh/authorized_keys
$ cat >> .ssh/authorized_keys
ssh-ed25519 ... (をコピペしてEnterを押す)
[ctrl+d]を押す
$ chmod 700 .ssh
$ chmod 600 .ssh/authorized_keys

接続確認。wsl側で

$ ssh -i .ssh/id_ed25519 saipi4(自分で設定したraspiのホスト名)
The authenticity of host 'saipi4 (192.168.1.100)' can't be established.
ECDSA key fingerprint is SHA256:UVgt3CY1o1JYPTf8CX5CLWV2UG6rtlvNHUQ4w6mLd8g.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added 'saipi4' (ECDSA) to the list of known hosts.

Linux saipi4 6.1.0-rpi7-rpi-v8 #1 SMP PREEMPT Debian 1:6.1.63-1+rpt1 (2023-11-24) aarch64

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Sun Feb  4 18:47:22 2024 from 192.168.1.62

無事接続できた。 公開鍵で認証できるようになったので、パスワードログインを無効にする。

$ sudo nano /etc/ssh/ssh

# PasswordAuthentication yes と書かれている所を、先頭の#を外して、 PasswordAuthentication no にする。 $ service sshd restart でsshd再起動。

以降は

ssh saipi4

で接続できるっぽい。最初からできたかも。

cf.

OSを最新に

$ sudo apt update してから、

$ sudo apt full-upgrade
...
$ sudo reboot (最新にしたので再起動)

`

SSD bootに設定

SSDをUSBで接続。認識されると、こんな感じになる。

$ dmesg
[ 2371.382886] sd 0:0:0:0: [sda] Attached SCSI disk
[ 2555.521771] usb 2-2: USB disconnect, device number 3
[ 2555.565777] sd 0:0:0:0: [sda] Synchronizing SCSI cache
[ 2555.801704] sd 0:0:0:0: [sda] Synchronize Cache(10) failed: Result: hostbyte=0x07 driverbyte=DRIVER_OK
[ 2627.619831] usb 2-2: new SuperSpeed USB device number 4 using xhci_hcd
[ 2627.652398] usb 2-2: New USB device found, idVendor=0bda, idProduct=9210, bcdDevice=f0.01
[ 2627.652420] usb 2-2: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[ 2627.652433] usb 2-2: Product: RTL9210
[ 2627.652442] usb 2-2: Manufacturer: Realtek
[ 2627.652451] usb 2-2: SerialNumber: 012345678905
[ 2627.684644] usb 2-2: Enable of device-initiated U1 failed.
[ 2627.685583] usb 2-2: Enable of device-initiated U2 failed.
[ 2627.714973] usb 2-2: Enable of device-initiated U1 failed.
[ 2627.716024] usb 2-2: Enable of device-initiated U2 failed.
[ 2627.720692] scsi host0: uas
[ 2628.284123] scsi 0:0:0:0: Direct-Access     Realtek  RTL9210 NVME     1.00 PQ: 0 ANSI: 6
[ 2628.302746] sd 0:0:0:0: Attached scsi generic sg0 type 0
[ 2628.306857] sd 0:0:0:0: [sda] 500118192 512-byte logical blocks: (256 GB/238 GiB)
[ 2628.308244] sd 0:0:0:0: [sda] Write Protect is off
[ 2628.308260] sd 0:0:0:0: [sda] Mode Sense: 37 00 00 08
[ 2628.310966] sd 0:0:0:0: [sda] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA
[ 2628.312278] sd 0:0:0:0: [sda] Preferred minimum I/O size 512 bytes
[ 2628.312300] sd 0:0:0:0: [sda] Optimal transfer size 33553920 bytes
[ 2628.324088]  sda: sda1 sda2
[ 2628.324372] sd 0:0:0:0: [sda] Attached SCSI disk
[ 2753.358307]  sda: sda1 sda2

fdiskで全部のパーティーションを削除。状況によって異なるので割愛。 bootloaderのバージョン確認

$ vcgencmd bootloader_version
2023/01/11 17:40:52
version 8ba17717fbcedd4c3b6d4bce7e50c7af4155cba9 (release)
timestamp 1673458852
update-time 0
capabilities 0x0000007f

sudo raspi-config A7 Boot ROM Versionを最新に。 E1 Latest Use the latest version boot ROM software を選択して再起動。

$ vcgencmd bootloader_version
2024/01/22 10:41:21
version 51ed67b03b3dde4e76b345370f312d07aabf45b8 (release)
timestamp 1705920081
update-time 1707048097
capabilities 0x0000007f
$ sudo apt install git
$ git clone https://github.com/billw2/rpi-clone.git 
$ cd rpi-clone
$ sudo cp rpi-clone rpi-clone-setup /usr/local/sbin
sudo rpi-clone-setup -t testhostname

cf. ラズパイ4をUSB接続のSSDから起動する方法(USBブート) | ラズパイダ Raspberry PiのバックアップをCLIから作成する | Vogelbarsch Rasberry Piでrpi-cloneを使ってバックアップ | TomoSoft