I 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
- Raspberry Pi 2
- SD card intended for Raspberry Pi OS
- Another machine with an SD Card reader
- CentOS 7 Raspberry Pi image
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.
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.
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.
NTP isn’t setup by default, but you can do it manually.
yum install chrony systemctl start chronyd
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
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
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.
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 EPEL repositories yet for CentOS7 on the armv7hl, but it’s definitely in progress. This means if you want packages outside of base you’ll need to compile them yourselves or use Fedora versions for some things for now.
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.
There are many useful Raspberry Pi / CentOS resources available, here’s a few: