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.math.princeton.edu/pub/centos-altarch/7.6.1810/isos/armhfp/CentOS-Userland-7-armv7hl-RaspberryPI-Minimal-1810-sda.raw.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.
If this does not work you’ll need to insert the SD card in another system and manually remove the partitions and re-create them with fdisk, save, eject.
Be sure to:
- capture the size and block/cylinder count of all partitions via fdisk -l beforehand
- use these values to re-create any smaller partitions as they were exactly (first FAT partition, swap)
- create the root Linux partition using the default start and (new) ending value that correspond to the much larger physical disk
Here is what mine looks like for example for a 32g SD card, only partition /dev/mmcblk0p3 or Linux / needed resizing but I re-created the other two as they previously where in fdisk.
Device Boot Start End Blocks Id System /dev/mmcblk0p1 * 2048 1370111 684032 c W95 FAT32 (LBA) /dev/mmcblk0p2 1370112 2369535 499712 82 Linux swap / Solaris /dev/mmcblk0p3 2369536 62333951 29982208 83 Linux
Then, once inserted back into the the Raspberry Pi you resize your filesystem inside the OS. There’s lots of guides on how to do this on the internet.
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 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.
There are many useful Raspberry Pi / CentOS resources available, here’s a few:
- Official CentOS documentation
- More alternate builds from Johnny Hughes
- #centos-arm on irc.freenode.net
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.
Most folks will use DHCP (static or otherwise) so that’s the focus here but you can switch to static by editing your /etc/sysconfig/network-scripts/* files as needed.
There seems to be an issue with this on the Raspberry Pi2 evident from this stackexchange thread.
It’s been noted the fix is to ensure
BOOTPROTO=noneis used but I have not tested it. Let me know and I’ll update the guide, I’m travelling so not near a pi2 at the moment.
thank you for the detailed instructions. Unfortunately the Pi won’t boot after
Has anyone else experienced this problem?
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?
I’ve really enjoyed your Blog. I’m going to try and install CentOS onto my Raspberry Pi 2 tomorrow. Thanks for posting this!
LikeLiked by 1 person
Not download image, correct link is “http://mirror.centos.org/altarch/7/isos/armhfp/?C=S;O=A”
Thanks for the correction Mike, it’s updated now.
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.
Thanks for pointing this out, I’ll update the guide.