Installing CentOS on the Raspberry Pi

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 > 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 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.

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/systemctl restart irqbalance.service

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 > 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
name=Epel rebuild for armhfp


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:


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+.

name=CentOS Kernels for armhfp

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
 raspberrypi2-kernel           armv7hl  4.4.26-v7.1.el7    centos-kernel   17 M
 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 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:

About Will Foster

hobo devop/sysadmin/SRE
This entry was posted in open source, sysadmin and tagged , , , , , , , , , , . Bookmark the permalink.

9 Responses to Installing CentOS on the Raspberry Pi

  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.


  2. devnull says:


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

    Has anyone else experienced this problem?


    • 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?


  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!

    Liked by 1 person

  4. mike Kim says:

    Not download image, correct link is “;O=A”


  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.


Have a Squat, Leave a Reply ..

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

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

Facebook photo

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

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.