Installing CentOS on the Raspberry Pi 2

centosraspbianI recently acquired a Raspberry Pi 2 and wanted to run CentOS7 on it.  Here’s how I got CentOS installed and setup.  There are now official Raspberry Pi 2 CentOS ARMv7hl images available for your enjoyment.  Let’s get started.


Stuff You’ll Need

Obtain the CentOS Media
First you’ll want to pull down the latest minimal CentOS image.  The main download page is located here under AltArch.

curl http://mirror.centos.org/altarch/7/isos/armhfp/CentOS-Userland-7-armv7hl-Minimal-1611-RaspberryPi2.img.xz > centos.img.xz

Extract the Image
Next you’ll want to extract the image somewhere.

unxz centos.img.xz

Copy the Image to an SD Card
Next you’ll need to insert the Raspberry Pi SD card and use dd to copy the CentOS image over.  If you have multiple SD cards be sure you’re using the right device or you might run into trouble.  On my machine, it looked like this prior:

fdisk -l /dev/mmcblk0
Disk /dev/mmcblk0: 14.9 GiB, 15931539456 bytes, 31116288 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x00000000

Device         Boot Start      End  Sectors  Size Id Type
/dev/mmcblk0p1       8192 31116287 31108096 14.9G  c W95 FAT32 (LBA)

If you’re unsure at all, just run this command prior to plugging in your SD card, it never hurts to double check.

watch lsblk

If all looks good, proceed with the disk copy.

dd if=centos.img of=/dev/mmcblk0 bs=4M

Survey the Landscape
At this point you should have a working CentOS system that should boot.  Hook up a keyboard and something that takes HDMI input if you have it, plug in an network cable and put the SDcard into the Pi and plug it in.  If you don’t have a display don’t worry, if all goes well SSHD will attempt to obtain an DHCP address.

  • root password : centos
  • eth0 setting : DHCP
  • selinux status : permissive or disabled (see below)
  • no ntp/chronyd setup
uname -a
Linux skidmarks.funcamp.net 4.1.11-v7+ #822 SMP PREEMPT Fri Oct 23 16:22:18 BST 2015 armv7l armv7l armv7l GNU/Linux
cat /etc/redhat-release
Derived from Red Hat Enterprise Linux 7.2 (Source)

Resize your Disk
When you dd over a disk image to a larger disk image, your partition table changes to that of the disk image.  This means you won’t be able to use the full allotted space of your SD card without resizing things.  Luckily CentOS team has included the root-resize tool so you don’t need to do this manually.

touch /.rootfs-repartition
systemctl reboot

Now your Raspberry Pi will reboot, load kernel/initrd, expand the partition, resize it and reboot. Once done, you’ll be using your whole SD card.

Setup NTP
NTP isn’t setup by default, but you can do it manually.

yum install chrony
systemctl start chronyd

Fix: Firewall
Despite generally not caring for firewalld and the over-engineered approach to “zones” I’ve found it does not work reliably on ARMv7 in either CentOS or Fedora.  Let’s remove it and move back to trusty old iptables.

systemctl stop firewalld
systemctl mask firewalld

Install the iptables service.

dnf install iptables-services

Now set things up.

systemctl enable iptables
service iptables save

Now edit your firewall rules like a sane human in /etc/sysconfig/iptables and when you’re done you can save them.

systemctl start iptables.service

Fix: irqbalance
I’ve noticed the irqbalance process will incur heavy memory usage after some time, this seems to be a bug.  For now you can simply restart it once a day with no ill effect.

cat > /etc/cron.daily/irqbalance <<EOF
#!/bin/sh
/bin/systemctl restart irqbalance.service
EOF

Setup Python-Pip
Python-pip is included in EPEL however there aren’t currently EPEL repos for CentOS7 on the armv7 architecture, but noarch rpm’s will work fine.  Pip will let you sandbox install a lot of Python libraries needed to do other things so it’s very useful to have.  For now you’ll need to do this manually:

curl https://dl.fedoraproject.org/pub/epel/7/x86_64/p/python-pip-7.1.0-1.el7.noarch.rpm > python-pip-7.1.0-1.el7.noarch.rpm
yum localinstall python-pip-7.1.0-1.el7.noarch.rpm -y

Other Noarch Packages
If you need more noarch packages and you have a normal CentOS7/EL system simply install yum-utils and use yumdownloader to pull them down and copy over, this might be faster than browsing EPEL mirrors.  For example:

yum install yum-utils -y
yumdownloader python-pip

Known Issues and Limitations

Check your Cables
The Raspberry pi seems to be picky about the USB cables it uses for power, I encountered boot loops until I simply switched the USB cable connecting to the power supply.  Strange.

SELinux Support
Due to some complications with some of the board builds, SELinux does not ship as enforcing.  Depending on your board you can set it up post-install, but for the current image (kernel 4.1.11-v7) it’s noted as not working in the release notes.

General Package Availability
There are no official EPEL repositories yet for CentOS7 on the armv7hl, but there are automated builds of EPEL ARM you can add as a repo (these do not pass through QA/test and are unsigned)  Anything else you’ll need to compile yourself.

Adding Unsigned Automated EPEL Package Repo

cat > /etc/yum.repos.d/epel-unsigned.repo << EOF
[epel]
name=Epel rebuild for armhfp
baseurl=https://armv7.dev.centos.org/repodir/epel-pass-1/
enabled=1
gpgcheck=0

EOF

While expedient, using out-of-distribution packages isn’t the best long-term solution.  You can find packages on any official Fedora mirror in a pinch but you may get library conflicts for some things because of differing versions (don’t force anything).  The following worked for me for now:

htop-2.0.0-2.fc23.armv7hl
pkcs11-helper-1.11-7.fc23.armv7hl
openvpn-2.3.10-1.fc22.armv7hl
murmur-1.2.11-2.fc22.armv7hl

If you think you think you’ll need a lot of non-base applications, libraries and things that might be in EPEL land you’re probably better off running Fedora for now on the Raspberry Pi.

CentOS Kernel versus rpi-update
As of CentOS 7.3.1611 there are now CentOS kernels and firmware available, they seem to be locked down to 4.4.26 whereas the Raspberry Pi kernels provided via rpi-update are currently 4.4.43-v7+.

[centos-kernel]
name=CentOS Kernels for armhfp
baseurl=http://mirror.centos.org/altarch/7/kernel/$basearch/kernel-$kvariant
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
 file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-AltArch-Arm32

You can still use rpi-update to keep in sync with the Raspberry Pi2 upstream kernel and firmware but I’ve chosen to stop using this and simply use the CentOS provided firmware and kernels.

================================================================================
 Package                       Arch     Version            Repository      Size
================================================================================
Installing:
 raspberrypi2-kernel           armv7hl  4.4.26-v7.1.el7    centos-kernel   17 M
Updating:
 raspberrypi2-firmware         armv7hl  4.4.26-v7.1.el7    centos-kernel  5.5 M
 raspberrypi2-kernel-firmware  armv7hl  4.4.26-v7.1.el7    centos-kernel  1.0 M
[sadsfae@skidmarks ~]$ uname -a
Linux skidmarks.funcamp.net 4.4.26-v7.1.el7 #1 SMP Sat Oct 22 16:14:43 UTC 2016 armv7l armv7l armv7l GNU/Linux

This does not extend to Fedora on Raspberry Pi which should still utilize rpi-update.

Resources
There are many useful Raspberry Pi / CentOS resources available, here’s a few:

About Will Foster

hobo devop/sysadmin, all-around nice guy.
This entry was posted in open source, sysadmin and tagged , , , , , , . Bookmark the permalink.

9 Responses to Installing CentOS on the Raspberry Pi 2

  1. baz00r says:

    Trying to make this image use network.service instead of NetworkManager seems to be a bit of a headache. I don’t want the device to take a DHCP address, and even though I have disabled this in /etc/sysconfig/network-scripts/ifcfg-eth0 , the device still takes DHCP.

    I have attempted to disable the NetworkManager and enabled network.service but it spits out an error about not being able to start LSB. Frustrating, static IP is essential for so many services.

    Like

  2. devnull says:

    Hey,

    thank you for the detailed instructions. Unfortunately the Pi won’t boot after
    touch /.rootfs-repartition
    systemctl reboot

    Has anyone else experienced this problem?

    Like

    • Bob Rodriguez says:

      I had this same error trying to resize the partition. I’m using a 64GB memory card, and I’ve seen some posts that say it’ll only work on 32GB or less. Any way around this? Also, how do I get the GUI to work similarly to the PC version?

      Like

  3. Jonathan says:

    I’ve really enjoyed your Blog. I’m going to try and install CentOS onto my Raspberry Pi 2 tomorrow. Thanks for posting this!

    Like

  4. mike Kim says:

    Not download image, correct link is “http://mirror.centos.org/altarch/7/isos/armhfp/?C=S;O=A”

    Like

  5. Matt Niswonger says:

    Hi, there does appear to be an EPEL repo now for arm32 that I was able to get working on my Pi3. Note – the packages have no QA done after they’re built and they’re not signed.
    https://wiki.centos.org/SpecialInterestGroup/AltArch/Arm32#head-f2a772703b3caa90cc284e01bc87423ce9a87bcd

    Like

Have a Squat, Leave a Reply ..

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s