久しぶりにRaspberry Piをセットアップしようとしたら色々詰まった話
問題点
- 2017-09-07-raspbian-stretch-liteのイメージをSDに焼いたところsshが出来なかった
- local IPを固定しようとしたらinterfaces周りの設定がDebian 8系と違った
手順
セットアップ手順を振り返る
イメージの入手
上記から2017-09-07-raspbian-stretch-lite.zipをダウンロードしました
SDに書き込み
MacbookでSDを焼くので下記リポジトリのシェルスクリプトを使うととても楽でした。
$ wget https://downloads.raspberrypi.org/raspbian_lite_latest -o ~/Downloads/2017-09-07-raspbian-stretch-lite.zip $ unzip ~/Downloads/2017-09-07-raspbian-stretch-lite.zip $ git clone https://github.com/RayViljoen/Raspberry-PI-SD-Installer-OS-X.git $ cd Raspberry-PI-SD-Installer-OS-X $ sudo ./install ~/Downloads/2017-09-07-raspbian-stretch-lite.img
マウントされているディスクの一覧が表示されるのでSDカードを選択します。
書き込みは数分で終わりました。
Rasberry Pi を起動
USB-Ethernetの変換ケーブルだけ差して電源を入れる。適当にIPを調べてsshしようとした。
$ ssh pi@10.0.0.14 ssh: connect to host 10.0.0.14 port 22: Connection refused
はて、馬鹿なのでこの後しばらく何も調べずにsshd周りと格闘していました。30分くらいしてから調べればいいやと気づきました。
2016-11-25のリリースノートによると、デフォルトでsshが無効になるようになったそうです。(下記リンク)有効にするにはブートパーティーションにからのssh
というファイルを作成して起動すれば良いらしい。
http://downloads.raspberrypi.org/raspbian/release_notes.txt
再度、MacbookにSDをマウントしてsshファイルを作成
$ touch /Volumes/boot/ssh
$ ssh pi@10.0.0.14
ログインできました。
IPアドレスを固定
今後Amethystを走らせようかと思うのでIPを固定します。
Debian8系のつもりで/etc/network/interfaces
を編集しようとしたところ以下のようなコメントが
# Please note that this file is written to be used with dhcpcd # For static IP, consult /etc/dhcpcd.conf and 'man dhcpcd.conf'
なるほど、ということで/etc/dhcpcd.conf
を覗いてみます
$ cat /etc/dhcpcd.conf # A sample configuration for dhcpcd. # See dhcpcd.conf(5) for details. # Allow users of this group to interact with dhcpcd via the control socket. #controlgroup wheel # Inform the DHCP server of our hostname for DDNS. hostname # Use the hardware address of the interface for the Client ID. clientid # or # Use the same DUID + IAID as set in DHCPv6 for DHCPv4 ClientID as per RFC4361. # Some non-RFC compliant DHCP servers do not reply with this set. # In this case, comment out duid and enable clientid above. #duid # Persist interface configuration when dhcpcd exits. persistent # Rapid commit support. # Safe to enable by default because it requires the equivalent option set # on the server to actually work. option rapid_commit # A list of options to request from the DHCP server. option domain_name_servers, domain_name, domain_search, host_name option classless_static_routes # Most distributions have NTP support. option ntp_servers # Respect the network MTU. This is applied to DHCP routes. option interface_mtu # A ServerID is required by RFC2131. require dhcp_server_identifier # Generate Stable Private IPv6 Addresses instead of hardware based ones slaac private # interface eth0 # static ip_address=192.168.1.23/24 # #static ip6_address=fd51:42f8:caae:d92e::ff/64 # static routers=192.168.1.1 # static domain_name_servers=192.168.1.1 8.8.8.8 # It is possible to fall back to a static IP if DHCP fails: # define static profile #profile static_eth0 #static ip_address=192.168.1.23/24 #static routers=192.168.1.1 #static domain_name_servers=192.168.1.1 # fallback to static profile on eth0 #interface eth0 #fallback static_eth0
ifconfig
したところIFnameはeth0っぽいのでそこら辺のコメントを外せば良さそう。DNSなども任意で設定
$ sudo shutdown -r now
とりあえず使えるようになったと思います。