Raspberry Pi Model 1B

Many of you probably already heard of the credit card sized pocket computer, the Raspberry Pi, so I’ll just skip the introduction. Instead, I will share my thoughts and some experience with it since I got it a couple of months ago. I got my hands on an old Model B (thanks, bro), which sports twice the amount of RAM (512 MB) over Model A. This fact makes it possible to run a fully functional Gentoo system on it, so this is what I just did. But let’s rewind the wheel of time a bit.

Right after receiving this Pi, my first obvious choice was to install the well known Raspbian system onto it, as it is as good a start point as any when familiarizing yourself with the Pi for the first time. After booting up the system, my very first impression was that it is bloated. Sorry, fellas, but that is what I felt. After going through the menus, my first impression got solidified. This OS contains a lot of packages that seem completely unnecessary on low power computers such as this, like the full blown LibreOffice suite, Timidity, Jack, etc. So, instead of sanitizing the system of unnecessary packages, or follow the top-down approach (to borrow a word from the scientific field), I opted for the bottom-up method to build a system that would ultimately suit my own needs best.

To do that, I chose a distro that excels at tuning the system to your needs, namely Gentoo. I was already familiar with the system at the time, as I use it on a daily basis on my laptop, so getting a basic system on the Pi up and running was a breeze. There were some caveats though. According to some recommendations online, I chose to format the root partition of the SD card with F2FS, as it was designed with flash media in mind right from the beginning, but that turned out to be a mistake. To cut a long story short, the filesystem got flagged for checking for no apparent reason and the system wouldn’t boot normally until fixed. I ran the proper fsck utility to no avail, so it had to be reformatted with something proven and tested. I chose ext4.

Ext4 is an excellent filesystem, but it makes one wonder if it is as good a choice on an SD card as it is for more common boot storage devices, like SSDs. Gentoo for instance, is so much reliant on disk performance for certain tasks like system updating, that using the fastest possible storage is of paramount importance. For this reason, people having enough RAM in their computers simply mount the /tmp folder (where most disk activity happens during updates) to a ramdisk called tmpfs to achieve the highest possible speeds. Since the Pi has a limited amount of total RAM, using tmpfs for /tmp is not something one should try right away, so one needs to solely rely on the rather slow data throughput of the SD card itself. In order to do that, one needs to make sure, that there are no unnecessary bottlenecks originating from things like the filesystem.

To find out if ext4 is having a significant effect on I/O performance, I did some tests on two almost identical ext4 partitions, where one had the journal turned on while the other off. The tool I used for testing is dd and fio, where the latter allows to fine-tune every detail of the IO test, like the size of blocks to read/write, the ratio of reads and writes, the amount of total data to write, etc. Basically it is a Swiss knife of IO tests. Since both tools resulted in similar results, I’ll just post the fio related stuff, as it is more interesring than plain dd. I used the following command to benchmark both partitions (see the man pages for further explanations) with fio:

shell

 fio --randrepeat=1 --ioengine=posixaio --direct=1 --gtod_reduce=1 --name=test --filename=test --bs=4k --iodepth=8 --size=256M --readwrite=randrw –rwmixread=50

ext4 with journal off:

shell

 read : io=130768KB, bw=247263B/s, iops=60, runt=541553msec  
 write: io=131376KB, bw=248413B/s, iops=60, runt=541553msec

ext4 with journal on:

shell

 read : io=130768KB, bw=246615B/s, iops=60, runt=542976msec  
 write: io=131376KB, bw=247762B/s, iops=60, runt=542976msec

As you can see, there was basically no difference in performance between the two filesystems, so it can be safely assumed that turning off the journal will only increase the lifetime of the card due to the reduced amount of disk IO, but there is nothing more to be gained here. Knowing all this, one can safely leave the /tmp folder in its original place. One thing to consider though: many SD cards come with wear leveling, but by far not all of them. If you are unsure if your card really does have that, it would be wise to mount /tmp to a separate partition, so that most writing occurs at sectors that are outside of your system partition.

Observant readers might’ve already asked a very reasonable question: If I fiddled with filesystems after installing the system, did I need to reinstall it after F2FS gave me all the headache? Well, not exactly. Fortunately, the Linux operating system is flexible enough not to care about the physical location of files on disks, which makes it is extra easy to back up and reinstate the whole thing if need be, as the simplest of tools like tar can be used to achieve this. I used the following command to back up the whole system:

shell

 tar -cpjf /tmp/Rpi-img.tar.bz2 .

Please note, that for this command to work, you need to cd to the root of your partition you are trying to back up. Also, you should be really careful what command you are using to unpack your tarball in case the system needs to be restored. This is what I use:

shell

 tar -xpjf Rpi-img.tar.bz2 -C /run/media/username/sdcardrootpart –numeric-owner

After fiddling around with some extra tool installations and upgrades, let’s see the resulting base system: The system boots up with initial RAM usage of 13 MiB (+33 MiB cached) and disk usage of 2.4 GiB, which are pretty sleek in my opinion. One could say that 2.4 gigs of disk usage is a bit too much for a basic system like this. Let’s remember though that Gentoo stores all tarballs of installed packages by design, so removing those would shave off disk usage by about 491 MiB, resulting in a much more friendly system size of 2.0 GiB. Compressing the whole system (with source tarballs included) to a bzip2 archive, we get a tarball of size no bigger than 865 MiB. After getting rid of all source tarballs, this very same compressed archive file would probably be less than half the size, which makes it very easy to carry it around.

Memory usageMemory and disk usage of a freshly installed minimalistic Gentoo system on a Raspberry Pi

So what’s next? Well, it is about time to set up a couple of things, like distcc, hw random number generator, a little bit of tmpfs fiddling, make.conf fine tuning, do some performance evaluations etc. I hope you enjoyed it so far, so please remember to check back semi-regularly for new posts. Thanks for reading.