LoginSignup
7
2

More than 3 years have passed since last update.

[結果は却下] Raspberry PI の headless インストールで提案してみた

Last updated at Posted at 2020-02-04

はじめに

チョットしたことを試してみるには
なにかと便利なRaspberryPI

使っていて不便を感じたので
自分なりに、簡単な改善を実施

ついでに、ダメ元で [RPi-Distro] に提案してみたら
やっぱり、ダメだったって話です

率直に言えば、
小手先の提案(チョットした思いつき)だったので、
却下されるべくして却下されました

小手先だろうが、いろいろ調べて提案したのだから
そのことをメモついでに記事に残そうかと思います
(せっかく転んだのだから、砂でも掴もう)https://www.a-inquiry.com/ijin453/

前提(というか状況)

  • RaspberryPIは、調査や実験などで1台だけ扱っている分には問題ないけど、複数台をセットアップしようと思ったら大変じゃないですか?
    1. OSのインストールは、Imageファイルをダウンロードして SD カードに書き込んでおしまい(簡単なのは、ここまで)
    2. そのあとは、キーボードやディスプレイを接続し、いろいろセットアップ.....
    3. これを必要台数の数だけ繰り返す

具体的にはこんな状況

  • RaspberryPI(3B+とかZero Wとか)を数台設定したい
  • いろいろ試したりしたいので、RaspberryPIを何度も初期化することが想定される
  • 初期化作業のたびに、キーボードやディスプレイを接続(抜き/挿し)したくない
    • Zero W の USB 端子なんか壊れそうで怖い
  • RaspberryPI以外に、作業用のWindows/Linuxマシンが利用可能
  • WiFiネットワークが利用可能
    • 他チームの機器が何台もつながっている(機器の詳細不明)
    • 共用なので、自分勝手な設定変更などはできない

Internetから情報収集

  • Raspberry PI の Headless インストールは多くの人が興味があるのか、関連記事がいっぱいある
  • WiFi アクセスポイント接続設定や SSH サーバの有効化などは、SDカードにImageファイルを書き込んだあとに、ファイルを作成するだけなので、まあ簡単な作業(と思う)
  • ただ、そのあとの処理において DHCP でIPアドレスが割り当て機器に ssh 接続するのはチョット面倒だな~と思う

問題はIPアドレスの確認

  • RaspberryPIの電源をいれたら、基本的にはDHCPでIPアドレスが割り当てられる
  • 多くの場合、DHCPサーバが気をきかせてくれない(苦笑)から、割り当てられたIPアドレスがわからない
    • もしDHCPサーバが利用できない環境だったら.....(涙)

早い段階で固定IPアドレスを割り当て

  • 私は、これ↑ができれば良いと思い、この問題を小手先で解決しようとして [却下] されました

方向性

  • 自分は、/etc/dhcpcd.conf を編集して固定IPアドレスを割り当てている
  • だったら dhcpcd.conf も wpa_supplicant.conf と同じように /boot パーティションに置いたファイルを使ってセットアップして欲しい!

起動時の処理を確認

  • システム起動処理なので /etc/systemd 以下で /boot/ を grep検索したが該当なし
  • ファイルをよく見ると /lib/systemd へのリンクとなっているものがチラホラ
  • /lib/systemd で /boot/ を grep検索したら HIT
    • raspberrypi-net-mods.service は、wpa_supplicant.conf
    • sshswitch.service は、ssh
    • apply_noobs_os_config.service は、知らない [教えてGoogleさん]
console
pi@raspberrypi:/lib/systemd $ grep -r /boot/ *
system/raspberrypi-net-mods.service:ConditionPathExists=/boot/wpa_supplicant.conf
system/raspberrypi-net-mods.service:ExecStart=/bin/mv /boot/wpa_supplicant.conf /etc/wpa_supplicant/wpa_supplicant.conf
system/sshswitch.service:Description=Turn on SSH if /boot/ssh is present
system/sshswitch.service:ConditionPathExistsGlob=/boot/ssh{,.txt}
system/sshswitch.service:ExecStart=/bin/sh -c "systemctl enable --now ssh && rm -f /boot/ssh ; rm -f /boot/ssh.txt"
system/apply_noobs_os_config.service:ConditionPathExists=/boot/os_config.json
  • system/raspberrypi-net-mods.serviceをコピー
console
% sudo cp raspberrypi-net-mods.service raspberrypi-net-mods-dhcpcd.service
  • そして、以下のように修正(要点だけ列挙)
    • 対象ファイル名を wpa_supplicant から dhcpcd に変更
    • dhcpcd.service が実行される前に実行するように変更(Before 行)
    • rfkill の実行は不要なので、関連する行を削除
raspberrypi-net-mods-dhcpcd.service
[Unit]
Description=Override /etc/dhcpcd.conf if /boot/dhcpcd.conf is present
ConditionPathExists=/boot/dhcpcd.conf
Wants=network.target
Before=dhcpcd.service

[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/bin/mv /boot/dhcpcd.conf /etc/dhcpcd.conf
ExecStartPost=/bin/chmod 644 /etc/dhcpcd.conf

[Install]
WantedBy=multi-user.target
  • 使用する dhcpcd.conf は、以下のような内容
    • 有線なら eth0 だし、無線なら wlan0 と記述すればよいはず
/boot/dhcpcd.conf
hostname
clientid
persistent
option rapid_commit
option domain_name_servers, domain_name, domain_search, host_name
option classless_static_routes
option interface_mtu
require dhcp_server_identifier
slaac private

# set your static IP address
interface eth0
static ip_address=192.168.1.123/24
static routers=192.168.1.254
static domain_name_servers=192.168.1.1
#

動作確認

  1. serviceを有効化

    console
    % sudo systemctl enable raspberrypi-net-mods-dhcpcd.service
    
  2. /boot/dhcpcd.conf を作成して RaspberryPI を再起動

  3. 結果、用意した dhcpcd.conf が使用され、固定IPアドレスが割り当てられたようだ

提案準備

ところで、この修正内容を何処の誰に伝えればよいのか?

  1. https://www.raspbian.org/ を見たけど、わからなかった
  2. ファイルが含まれるパッケージ検索してみた

    • パッケージ名は raspberrypi-net-mods
    console
    % sudo apt install -y apt-file
    % sudo apt-file search  /lib/systemd/system/raspberrypi-net-mods.service
    raspberrypi-net-mods: /lib/systemd/system/raspberrypi-net-mods.service
    
  3. GitHub でパッケージ名を検索してみたら見つかった

提案

  1. 自分で実装して PullRequest を出すのが親切かもしれないけど、自分は raspbian をどのようにbuildするのかさえ知らないので、簡単にスグできる Issue を選択した
  2. それほど時間もかからずに返事が来て、Issue は Close されました(涙)

    We can't keep adding config files to /boot like this.
    dhcpcd.conf is one of maybe 100 files people would want to modify, so this just isn't scalable.

  3. 仰る通りです

    • dhcpcd.conf だけでなく、多くのファイルが同じような想いを持っていることは理解できます
    • OSの更新などの結果、ネットワーク設定関連が丸ごと差し替えられたら、dhcpcd.conf の置き換えが無意味になる可能性があることも理解できます
    • ただ、現時点において固定IPアドレスを割り振ることまでできれば、他の設定ファイルを送り込むことは簡単に実現できるとおもうんですよね
  4. 『そう言ったけど、いつかは』

    • Issueがcloseされたあとの probably な一言に期待します

    That being said, it's probably also worth adding that we have some alternative solutions we'd like to implement in the long term.

さいごに(雑記)

今回の件で得たことなど

  • https://github.com/RPi-Distro/repositories/ の存在を知ったこと
  • 提案してみる勇気と却下(reject)慣れへの第一歩を体験したこと
    • 良くわからなければIssueで相談してみること
    • PullRequestは後からでOK(結果的に今回は不要だったし...)
  • 変な英語だろうが気にしないこと
    • Googleさんの翻訳も案外使えること
7
2
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
2