LoginSignup
34
36

More than 3 years have passed since last update.

RaspberryPi 3 model B に CentOS7をインストール

Last updated at Posted at 2017-08-12

RaspberryPi 3 model B に CentOS7をインストール

はじめに

いままでCentOS7にほとんど触れたことがなかったため、せっかく新しく OS をインストールするならと選んでみました。
セットアップ自体は難しくないものの、今後インストールしたいものが yum リポジトリにあるかで面倒さがあるかもしれません。

準備する物

前提条件

  • OS イメージの取得と microSD カードへの書き込みは MacBookPro 上で行う手順を記載しています。
  • OS イメージのバージョンや yum update の結果は 2017年6月時点のものです。

参考情報

OS イメージの取得と microSD カードへの書き込み

CentOS7 OS イメージ取得

MacBookPro 上に適当なディレクトリを作成し、OS イメージを取得します。
取得したxzファイルを展開します。

$ mkdir raspberryPi3
$ cd raspberryPi3
$ wget https://buildlogs.centos.org/centos/7/isos/armhfp/CentOS-Userland-7-armv7hl-Minimal-1611-test-RaspberryPi3.img.xz
$ xz -d CentOS-Userland-7-armv7hl-Minimal-1611-test-RaspberryPi3.img.xz
$ ls .
CentOS-Userland-7-armv7hl-Minimal-1611-test-RaspberryPi3.img

microSD カードに OS イメージを書き込む

SDカードのフォーマット

使用前にSDカードをフォーマットします。
フォーマットツールをSD Memory Card Formatter のサイトからダウンロード、インストールします。
SD Memory Card Formatterを起動すると、SDカードリーダに挿されたSDカードを自動的に認識します。
Format をクリックします。

OS イメージの書き込み

MacBookPro に接続した SD カードリーダー上の microSD カードのデバイスドライブを確認します。
umount したうえで dd コマンドで OS イメージを書き込みます。

of=/dev/rdisk2 のように、disk2の前にrを付けてることでアンバッファードになり書き込み速度が速くなります。

$ df -h 
Filesystem                 Size   Used  Avail Capacity iused      ifree %iused  Mounted on
(省略)
/dev/disk2s1              3.7Gi  1.1Mi  3.7Gi     1%       0          0  100%   /Volumes/NO NAME

$ diskutil umount /dev/disk2s1
$ sudo dd if=CentOS-Userland-7-armv7hl-Minimal-1611-test-RaspberryPi3.img of=/dev/rdisk2 bs=1m
393216+0 records in
393216+0 records out
3221225472 bytes transferred in 263.451237 secs (12227027 bytes/sec)

microSD を RaspberryPi 3 に挿して起動

OSイメージ書き込みの完了後、microSD カードをRaspberry Pi 3 に挿して電源をON。
CentOS7のrootアカウントは以下のとおりです。
login : root
Password : centos

CentOS7 セットアップ

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

4GB の microSD カードを使用してるものの、2GB しか認識していないので README にそって対処します。

起動直後の状態を確認します。

[root@centos-rpi3 ~]# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/root       2.0G  762M  1.1G  42% /
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   43M  457M   9% /boot
tmpfs            93M     0   93M   0% /run/user/0

実際のパーティションサイズを確認すると4GBあるようです。

[root@centos-rpi3 ~]# parted /dev/mmcblk0
GNU Parted 3.1
Using /dev/mmcblk0
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) p
Model: SD USD (sd/mmc)
Disk /dev/mmcblk0: 4036MB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:

Number  Start   End     Size    Type     File system     Flags
 1      1049kB  525MB   524MB   primary  fat16           lba
 2      525MB   1062MB  537MB   primary  linux-swap(v1)
 3      1062MB  4036MB  2974MB  primary  ext4

(parted) quit

README に書かれている手順を参照します。

# less /root/README

一部抜粋

== CentOS 7 userland ==

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

上記のとおり実行してみます。

 # /usr/local/bin/rootfs-expand
Extending partition 3 to max size ....
CHANGED: partition=3 start=2074624 old: size=4194304 end=6268928 new: size=5808128,end=7882752
Resizing ext4 filesystem ...
resize2fs 1.42.9 (28-Dec-2013)
Filesystem at /dev/mmcblk0p3 is mounted on /; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 1
The filesystem on /dev/mmcblk0p3 is now 726016 blocks long.
Done.

root のサイズを確認します。
parted コマンドで確認した際のパーティション 3とおよそ同じサイズとなりました。

[root@centos-rpi3 ~]# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/root       2.7G  762M  1.8G  30% /
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   43M  457M   9% /boot
tmpfs            93M     0   93M   0% /run/user/0

ネットワークの設定

ネットワークの設定(有線LAN)

RaspberryPi 3 model B は無線LANが使えます。
無線LANのセットアップをおこなうためにモジュールのダウンロードが必要になるので、有線LANを先にセットアップします。
nmcli コマンドでネットワーク設定を行います。

設定する値は以下のものとします。

項目
IPアドレス 192.168.1.1
ネットマスク 24bit
デフォルトゲートウエイ 192.168.1.1
DNSリゾルバ 192.168.1.1

現在のネットワークデバイスを確認します。ここでは、eth0

# nmcli d
DEVICE  TYPE      STATE      CONNECTION
eth0    ethernet  connected  eth0
lo      loopback  unmanaged  --
# nmcli c mod eth0 ipv4.addresses 192.168.1.110/24
# nmcli c mod eth0 ipv4.gateway 192.168.1.1
# nmcli c mod eth0 ipv4.dns 192.168.1.1

IPアドレスを固定とします。

# nmcli c mod eth0  ipv4.method manual

設定を反映します。

# nmcli c down eth0 && nmcli c up eth0

設定を確認します。

# nmcli con show eth0
(省略)
ipv4.method:                            manual
ipv4.dns:                               192.168.1.1
ipv4.dns-search:
ipv4.dns-options:                       (default)
ipv4.dns-priority:                      100
ipv4.addresses:                         192.168.1.110/24
ipv4.gateway:                           192.168.1.1
(省略)

ネットワークの設定(無線LAN)

ネットワークデバイスには無線LANのデバイスが認識されていません。

# nmcli d
DEVICE  TYPE      STATE         CONNECTION
eth0    ethernet  connected     eth0
lo      loopback  unmanaged     --

README に書かれている手順を参照します。

# less /root/README

一部抜粋

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

上記のとおり実行してみます。

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

ネットワークデバイスを確認すると、無線LAN デバイスが認識されているのがわかります。

# nmcli d
DEVICE  TYPE      STATE         CONNECTION
eth0    ethernet  connected     eth0
wlan0   wifi      disconnected  --
lo      loopback  unmanaged     --

アクセスポイント一覧を確認します。

# nmcli d wifi
*  SSID             MODE   CHAN  RATE       SIGNAL  BARS  SECURITY
   aterm-xxxxxx-g   Infra  1     54 Mbit/s  100     ****  WPA2

接続情報を設定します。

# nmcli c add con-name wlan0 ifname wlan0 type wifi ssid aterm-xxxxxx-g

設定を確認します。

# cat /etc/sysconfig/network-scripts/ifcfg-wlan0
ESSID="aterm-xxxxxx-g"
MODE=Managed
MAC_ADDRESS_RANDOMIZATION=default
TYPE=Wireless
BOOTPROTO=dhcp
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=wlan0
UUID="xxxx-xxxx-xxxx-xxxx-xxxx"
DEVICE=wlan0
ONBOOT=yes

次に暗号化方式を設定します。

# nmcli con modify wlan0 wifi-sec.key-mgmt wpa-psk

KEY_MGMT=WPA-PSKが追加されました。

# cat /etc/sysconfig/network-scripts/ifcfg-wlan0
ESSID="aterm-3de3ef-g"
MODE=Managed
TYPE=Wireless
BOOTPROTO=dhcp
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=wlan0
UUID=9905ec72-7336-4214-9ee0-a2330269cc5b
DEVICE=wlan0
ONBOOT=yes
KEY_MGMT=WPA-PSK
MAC_ADDRESS_RANDOMIZATION=default
PEERDNS=yes
PEERROUTES=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes

最後にアクセスポイントの接続パスワードを設定します。

# nmcli c modify wlan0  wifi-sec.psk xxxxxxxxxx

アクセスポイントに接続します。

# nmcli c up wlan0
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/4)

接続状況を確認します。
接続しているSSIDの行頭に * がついています。複数のアクセスポイントがある環境では、どれに接続しているかを * の有無で確認できます。

# nmcli d wifi
*  SSID             MODE   CHAN  RATE       SIGNAL  BARS  SECURITY
*  aterm-xxxxxx-g   Infra  1     54 Mbit/s  100     ****  WPA2

有線LANも含めて、ネットワークデバイス一覧を確認します。

# nmcli d
DEVICE  TYPE      STATE      CONNECTION
eth0    ethernet  connected  eth0
wlan0   wifi      connected  wlan0
lo      loopback  unmanaged  --

無線LANのネットワーク詳細情報をみてみます。

# nmcli d show wlan0
GENERAL.DEVICE:                         wlan0
GENERAL.TYPE:                           wifi
GENERAL.HWADDR:                         xx:xx:xx:xx:xx:xx
GENERAL.MTU:                            0
GENERAL.STATE:                          100 (connected)
GENERAL.CONNECTION:                     aterm-xxxxxx-g
GENERAL.CON-PATH:                       /org/freedesktop/NetworkManager/ActiveConnection/1
IP4.ADDRESS[1]:                         192.168.1.13/24
IP4.GATEWAY:                            192.168.1.1
IP4.DNS[1]:                             192.168.1.1
IP6.ADDRESS[1]:                         fe80::f8a5:39b9:d16:e826/64
IP6.GATEWAY:

yum update

yum update で OS を最新の状態にします。
実行するとエラーが発生しアップデートできないようです。

# yum update
Loaded plugins: fastestmirror
base                                                                        | 3.6 kB  00:00:00
http://mirror.centos.org/altarch/7/kernel/armhfp/kernel-%24kvariant/repodata/repomd.xml: [Errno 14] HTTP Error 404 - Not Found
Trying other mirror.
To address this issue please refer to the below knowledge base article

https://access.redhat.com/articles/1320623

If above article doesn't help to resolve this issue please create a bug on https://bugs.centos.org/



 One of the configured repositories failed (CentOS Kernels for armhfp),
 and yum doesn't have enough cached data to continue. At this point the only
 safe thing yum can do is fail. There are a few ways to work "fix" this:

     1. Contact the upstream for the repository and get them to fix the problem.

     2. Reconfigure the baseurl/etc. for the repository, to point to a working
        upstream. This is most often useful if you are using a newer
        distribution release than is supported by the repository (and the
        packages for the previous distribution release still work).

     3. Run the command with the repository temporarily disabled
            yum --disablerepo=centos-kernel ...

     4. Disable the repository permanently, so yum won't use it by default. Yum
        will then just ignore the repository until you permanently enable it
        again or use --enablerepo for temporary usage:

            yum-config-manager --disable centos-kernel
        or
            subscription-manager repos --disable=centos-kernel

     5. Configure the failing repository to be skipped, if it is unavailable.
        Note that yum will try to contact the repo. when it runs most commands,
        so will have to try and fail each time (and thus. yum will be be much
        slower). If it is a very temporary problem though, this is often a nice
        compromise:

            yum-config-manager --save --setopt=centos-kernel.skip_if_unavailable=true

failure: repodata/repomd.xml from centos-kernel: [Errno 256] No more mirrors to try.
http://mirror.centos.org/altarch/7/kernel/armhfp/kernel-$kvariant/repodata/repomd.xml: [Errno 14] HTTP Error 404 - Not Found

エラーメッセージのヘルプにあるとおり、kernelのアップデートは除外してみます。

# yum --disablerepo=centos-kernel update

アップデート後、kernel のバージョンを確認します。
インストールされている kernel と yum リポジトリのものが同一になりました。

[root@centos-rpi3 ~]# rpm -qa | grep raspberrypi2-kernel
raspberrypi2-kernel-4.4.33-v7.1.el7.armv7hl
raspberrypi2-kernel-firmware-4.9.13-v7.1.el7.armv7hl
raspberrypi2-kernel-4.9.13-v7.1.el7.armv7hl

[root@centos-rpi3 ~]# yum list | grep raspberrypi2-kernel
raspberrypi2-kernel.armv7hl             4.4.33-v7.1.el7         @rpi2-kernel_rbf
raspberrypi2-kernel.armv7hl             4.9.13-v7.1.el7         @kernel
raspberrypi2-kernel-firmware.armv7hl    4.9.13-v7.1.el7         @kernel
raspberrypi2-kernel-devel.armv7hl       4.9.13-v7.1.el7         centos-kernel

起動している kernel のバージョンを確認します。

# uname -a
Linux centos-rpi3 4.4.33-v7.1.el7 #1 SMP Mon Nov 21 18:48:06 UTC 2016 armv7l armv7l armv7l GNU/Linux

さきほどインストールした kernelを反映するため、OS 再起動します。

# reboot

起動しているkernelを確認します。

# uname -a
Linux centos-rpi3 4.9.13-v7.1.el7 #1 SMP Mon Feb 27 10:45:31 UTC 2017 armv7l armv7l armv7l GNU/Linux

NTPdのインストール

時刻同期のため、NTPdをインストールします。

# yum install ntp

NTPdの設定をおこないます。

# vi /etc/ntp.conf

変更前

server 0.centos.pool.ntp.org iburst
server 1.centos.pool.ntp.org iburst
server 2.centos.pool.ntp.org iburst
server 3.centos.pool.ntp.org iburst

変更後

#server 0.centos.pool.ntp.org iburst
#server 1.centos.pool.ntp.org iburst
#server 2.centos.pool.ntp.org iburst
#server 3.centos.pool.ntp.org iburst
pool ntp.nict.jp

NTPdを起動し、タイムゾーンを日本に変更します。

# systemctl enable ntpd
Created symlink from /etc/systemd/system/multi-user.target.wants/ntpd.service to /usr/lib/systemd/system/ntpd.service.

# systemctl start ntpd
# timedatectl set-timezone Asia/Tokyo
# timedatectl
      Local time: Wed 2017-06-14 00:13:51 JST
  Universal time: Tue 2017-06-13 15:13:51 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

OS起動時のNTPdの自動起動を有効にする。

$ sudo systemctl enable ntpd.service

34
36
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
34
36