Raspberry Pi3にCentOS7をインストール

どうやらRaspberry piCentOSを入れることができるようなので 手順を残しておく。

必要なもの

  • PC (mac想定)
  • Raspberry pi3
  • MicroSD (16GB以上あれば大丈夫だと思う)
  • SDカードスロット (pcについてればそれでもいい)
  • LANケーブル
  • HDMIケーブル
  • ACアダプタ
あったほうが便利 (なくてもルーターからローカルIPを調べれば sshで操作可能 )
  • モニター
  • USBキーボード

CentOSをインストールする

まずはRaspberry Pi3用のCentOS7をダウンロードする

https://wiki.centos.org/Download

上記リンクからダウンロードできる
リンク先からRaspberry Pi3用を探してダウンロードする

2017年2月現在では以下のファイル名 CentOS-Userland-7-armv7hl-Minimal-1611-RaspberryPi3.img.xz

ダウンロード後、上記を解凍する アプリを使ってもいいしコマンドでも可

コマンドの場合

#homebrewでインストールできる
$brew install xz
#以下で解凍
xz -d CentOS-Userland-7-armv7hl-Minimal-1611-RaspberryPi3.img.xz

MicroSDに書き込みます
pcにMicroSDを指す

#マウントされてるMicroSDを調べる
$diskutil list


/dev/disk0
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        *121.3 GB   disk0
   1:                        EFI EFI                     209.7 MB   disk0s1
   2:          Apple_CoreStorage                         120.5 GB   disk0s2
   3:                 Apple_Boot Recovery HD             650.1 MB   disk0s3
/dev/disk1
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:                  Apple_HFS Macintosh HD           *120.1 GB   disk1
                                 Logical Volume on disk0s2
                                 2117A7C6-F20D-4E5F-92D2-0B352281C440
                                 Unlocked Encrypted
/dev/disk2
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:     FDisk_partition_scheme                        *15.8 GB    disk2
   1:             Windows_FAT_32 boot                    66.1 MB    disk2s1
   2:                      Linux                         15.7 GB    disk2s2
#一旦アンマウントする (※`disk2s1`を指定)
$diskutil umount /dev/disk2s1
#書き込む 結構時間かかるので待つ(※`disk2s1`ではなく`disk2`を指定)
$sudo dd if=CentOS-Userland-7-armv7hl-Minimal-1611-RaspberryPi3.img of=/dev/disk2 bs=8192; sync

393216+0 records in
393216+0 records out
3221225472 bytes transferred in 1423.262396 secs (2263269 bytes/sec)

Rasberry pi の起動とログイン

MicroSDカードをセット。LANなどを差し込んで最後にACアダプタを差す
しばらく待つと起動するのでログインする
キーボード、モニターがない場合はローカルipを調べてsshでログインしても良い

#初期値は以下
login: root
password: centos

sshでログイン

# centosでipを調べる
$ip a
#mac側でsshでログインする
$ssh root@192.168.xxx
password 

タイムゾーンの設定

# タイムゾーンを`Asia/Tokyo`に変更する
$timedatectl set-timezone Asia/Tokyo
# 確認
$timedatectl status
      Local time: 日 2017-02-26 22:56:44 JST
  Universal time: 日 2017-02-26 13:56:44 UTC
        RTC time: n/a
       Time zone: Asia/Tokyo (JST, +0900)
     NTP enabled: yes
NTP synchronized: yes
 RTC in local TZ: no
      DST active: n/a

Rootパーティションのサイズ拡張

デフォルトではSDカードの容量を全て使用していないため拡張する必要があるらしい
これについては root/README に書いてある

#  root/ 配下のREADME

If you want to automatically resize your / partition, just type the following (as root user):
/usr/local/bin/rootfs-expand

For wifi on the rpi3, just proceed with those steps : 

curl --location https://github.com/RPi-Distro/firmware-nonfree/raw/master/brcm80211/brcm/brcmfmac43430-sdio.bin > /usr/lib/firmware/brcm/brcmfmac43430-sdio.bin

curl --location https://github.com/RPi-Distro/firmware-nonfree/raw/master/brcm80211/brcm/brcmfmac43430-sdio.txt > /usr/lib/firmware/brcm/brcmfmac43430-sdio.txt

systemctl reboot
#  READMEに書いてある通りに以下を実行
$/usr/local/bin/rootfs-expand

Extending partition 3 to max size ....
/usr/bin/growpart: 行 170: シリンダ数*416*: 構文エラー: オペランドが予期されます (エラーのあるトークンは "シリンダ数*4、16*")
Resizing ext4 filesystem ...
resize2fs 1.42.9 (28-Dec-2013)
The filesystem is already 524288 blocks long.  Nothing to do!

Done.

どうやらシェルのLANGの設定の問題らしい。

$locale

LANG=ja_JP.UTF-8

上記のようになっていたら

$export LANG="en_US.UTF-8"

で変更。もう一度

$/usr/local/bin/rootfs-expand

終わったら戻しておく

$export LANG="ja_JP.UTF-8"

再起動した後に確認する

$reboot

#拡張されているか確認
$df -h
ファイルシス   サイズ  使用  残り 使用% マウント位置
/dev/root         14G  2.4G   11G   19% /
devtmpfs         459M     0  459M    0% /dev
tmpfs            463M     0  463M    0% /dev/shm
tmpfs            463M   12M  451M    3% /run
tmpfs            463M     0  463M    0% /sys/fs/cgroup
/dev/mmcblk0p1   500M   49M  452M   10% /boot
tmpfs             93M     0   93M    0% /run/user/0

パッケージの更新

最後にyumを利用してシステムにインストールされているパッケージのバージョンアップを行う

$yum update -y

参考