8
7

More than 5 years have passed since last update.

Raspberry Pi 初期設定

Last updated at Posted at 2019-02-23

Raspberry Pi の初期設定手順のメモ。

microSD カードに OS をインストールしてから、Raspberry Pi に SSH 接続し、初期設定を行う。

環境

  • Raspberry Pi 3 Model B+
    • OS: Raspbian Stretch Lite(2018-11-13)
  • MacBook Pro

OS インストール by Mac

GUI は必要ないので、CUI である Raspbian Stretch Lite をインストールする。

OS イメージファイルのダウンロード

公式サイトから OS イメージファイル(Raspbian Stretch Lite: zip形式)をダウンロードする。

// ダウンロード結果
$ ls ~/Downloads
2018-11-13-raspbian-stretch-lite.zip

// zip ファイル展開
$ cd ~/Downloads
$ unzip 2018-11-13-raspbian-stretch-lite.zip 
Archive:  2018-11-13-raspbian-stretch-lite.zip
  inflating: 2018-11-13-raspbian-stretch-lite.img

// zip ファイル展開結果
$ ls
2018-11-13-raspbian-stretch-lite.img 2018-11-13-raspbian-stretch-lite.zip

OS イメージの書き込み

公式サイトの手順を参考に OS イメージを microSD カードに書き込む。

// microSD カードが mount されたパスを確認
$ diskutil list
...省略
/dev/disk2 (external, physical):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:     FDisk_partition_scheme                        *31.9 GB    disk2
   1:                 DOS_FAT_32 BOOT                    31.9 GB    disk2s1

// microSD カードをアンマウントする
$ sudo diskutil umount /dev/disk2s1
Volume BOOT on disk2s1 unmounted

// microSD カードに OS イメージを書き込む
$ sudo dd bs=1m if=2018-11-13-raspbian-stretch-lite.img of=/dev/rdisk2 conv=sync
1780+0 records in
1780+0 records out
1866465280 bytes transferred in 312.505139 secs (5972591 bytes/sec)

SSH の有効化

Raspberry Pi はデフォルトでは SSH が無効になっている。(参考)
boot ディレクトリ以下に ssh という名前のファイルを作成しておくと、Raspberry Pi の起動時に SSH が有効になる。

$ touch /Volumes/boot/ssh

初期設定

Raspberry Pi に SSH 接続し、初期設定を行う。

起動

Raspberry Pi に microSD カードを挿入し、LAN ケーブルを接続した状態で電源を接続する。

SSH 接続

Mac からであれば Bonjour によってホスト名でアクセスすることができる。

ホスト名: raspberrypi
ユーザ名: pi
パスワード: raspberry

$ ssh pi@raspberrypi.local

初期設定

Raspberry Pi で、個人的に行っておきたい初期設定。
raspi-config は利用していない。

パスワード変更

pi ユーザのパスワードを変更する。

$ sudo passwd pi

パッケージ更新

$ sudo apt update
$ sudo apt upgrade -y

Vim インストール

$ sudo apt install vim -y

Locale 設定

$ sudo dpkg-reconfigure locales

ja_JP.UTF-8 UTF-8 にチェックを入れる。
Default localeja_JP.UTF-8 にする。

Timezone 設定

$ sudo dpkg-reconfigure tzdata

Asia/Tokyo を選択。

swap 無効

microSD カードで swap を利用すると負担が大きくなり、寿命が短くなるので、swap を無効にする。

$ sudo dphys-swapfile swapoff
$ sudo dphys-swapfile uninstall
$ sudo update-rc.d dphys-swapfile remove

IP アドレス固定

$ sudo vi /etc/dhcpcd.conf

ファイル内に以下のような設定例が記述されているので、設定を追記する。

# Example static IP configuration:
#interface eth0
#static ip_address=192.168.0.10/24
#static ip6_address=fd51:42f8:caae:d92e::ff/64
#static routers=192.168.0.1
#static domain_name_servers=192.168.0.1 8.8.8.8 fd51:42f8:caae:d92e::1

ホスト名変更

$ sudo vi /etc/hostname

// /etc/hosts も修正しておく
$ sudo vi /etc/hosts

電源 LED 点滅

Raspberry Pi は電源の ON/OFF に関わらず、LED が常に点灯しているので、電源が ON のときは LED が点滅するようにし、LED によって電源の ON/OFF を判別できるようにする。

$ sudo vi /boot/config.txt

// 以下を追記
# turn power LED into heartbeat
dtparam=pwr_led_trigger=heartbeat
8
7
0

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
8
7