Raspbian and btrfs

I've just got a brand new Raspberry Pi 4. For now I'm just playing around a bit with it. Until openSuSE Leap will be available, I'm using Raspbian Buster which comes by default with ext4. Since I want to have snapshots, the first thing I want to do is to convert the existing root partition into btrfs. So let's do this.

0. Get Raspbian

First, flash Raspbian to a SD card and boot it. I also recommend to run a system update after booting into Raspbian. There are plenty of tutorials on the internet, that are probably far better than what I can write.

1. Prepare initramfs

In Raspbian btrfs is included as module. In order to make the kernel mount a btrfs root filesystem, we need to build the corresponding initramfs. First install the necessary tools

Now we add the btrfs module to /etc/initramfs-tools/modules

Next is to build the initramfs

And tell the bootloader to load the initramfs, by editing /boot/config.txt

And then reboot the device, to check if everything is set up properly.
If the boot succeeds, shutdown the Raspberry and take the SD-Card to another computer. If you run at this stage into trouble, probably a filename is wrong and you should be still able to recover. Otherwise: Just start from scratch - at this point really nothing is lost.

2. Convert ext4 rootfs to btrfs

In my case I insert the SD card into my laptop. The SD card gets recognised as /dev/mmcblk0 and contains the following partitions:

To convert the filesystem to btrfs, we are now doing the following steps:

  1. Optional: Make sure, the rootfs is clean (run fstck)
  2. Convert ext4 to btrfs using btrfs-convert
  3. Mount new btrfs root
  4. Edit /etc/fstab
  5. Edit /boot/cmdline.txt

On my system, I have to do the following steps

Now we edit /etc/fstab and change ext4 to btrfs. We also need to disable the filesystem-check by setting the last two digits in the btrfs line to 0

IMPORTANT: Set the last two settings in /etc/fstab to 0 and 0. The last 0 is especially important for btrfs root, since fsck and btrfs do not go so well together.

Lastly we edit /boot/cmdline.txt. We neet to replace rootfstype=ext4 to rootfstype=btrfs and set fsck.repair=no

IMPORTANT: It is crucial to set fsck.repair=no. I was stuck at some weird "mounting failed: Invalid argument" errors, because the system wanted to perform a fsck and failed.

3. Now the fun starts

This is only the kickoff. Now the funny things, like subvolumes, snapshots ecc. start

Have a lot of fun! 🙂

Caveats

  • After a kernel update, you will need to run mkinitramfs again. Probably it's the best to only do manual kernel updates (even security updates) as otherwise your Raspi might not be able to boot again.

Additional notes

Check those notes, in case something went wrong. Those emphasis the steps I had to to to make this work

  • Fsck had cause me a lot of trouble. In case you run into mount invalid errors, check if you have disable fsck in /etc/fstab (the last zero) and in /boot/cmdline.txt
  • Apperently btrfs-convert doesn't change the UUID. If you find yourself with "device not found" or similar errors, this might has changed and you will need to change the UUIDs
  • After a Kernel update you will need to run mkinitramfs again. Keep that in mind (and maybe disable auto-updates)

Common pitfalls

Crappy image of the console output with the "mounting ... failed: invalid argument" error

I got this error message when I forgot to edit cmdline.txt. Make sure, you have configured /boot/cmdline.txt correctly (especially the rootfstype=btrfs and fsck.repair=no)

Raspberry Pi 3 and H.256

Some time ago I got annoyed by some movies encoded in h.256 are not running smoothly on the Kodi of my Raspberry Pi 3.

h.256 is a block-oriented quite new video compression algorithm, that is unfortunately not supported natively by the hardware decoder on the Raspberry Pi 3. So it has to be done in Software, and apparently the computational power of the Pi is too weak.

Surfing through some fora, I found some people claiming, that overclocking the Raspberry Pi should be the solution. So I decided to give it a try.


Overclocking goal

The goal was to bring the h.265 codec smoothly on the screen, using 1080p@30fps. Some people said, that overclocking the pi to 1300MHz should be enough. So that's where I have to go.

Only do overclocking, with an adequate cooling system! Since the Raspberry ships without any heat sink, I needed to buy one.

Cooling system

I've decided to go with a plain Aluminium heat sink, but monitor the temperature very closely with cputemp and gputemp, two tools that ship by default on the Raspbian and OpenELEC:

Works. During the whole overclocking procedure I was connected to the Raspberry via ssh to monitor the temperatures very closely. At least one readout every second, ready to intervene if something goes nasty.

The goal was to keep the temperature below 85 degrees (soft-limit) and immediately cancel the procedure after 90 degree (hard-limit). During the overclocking procedure I reached the hard-limit.

Overclocking

And here we go. Backup /flash/config.txt before editing, so that you can set it back to default, once you have finished.

There are plenty of examples on this page. You may need to figure out, witch one works for you.

There's also this amazing wiki page about overclocking, the risks and the pitfalls. I think that's the resource you should read before getting started.

The default clocking settings for a Raspberry Pi are commented out, thus if you are unsure about your current configuration, just comment it out, reboot and you'll have the stable plain configuration again.

In the end, I tries to get the system working with the following configuration

System was stable, but heating up a lot, up to more than 85 degrees. That's an important threshold, because at 85 degrees the Raspberry starts to protect itself from the heat death by throttling down the CPU. So in overall you'll have no benefit from overclocking, except a small boost in performance before it throttles you down to worse throughput, than with plain vanilla settings.

Results

The poor Raspberry Pi got really hot during this procedure! 1300 MHz would be too much for a long-period. Also because it throttles itself down, I did not get any benefit from the overclocking procedure.

And although I pushed it to the limit with the available cooling system, I couldn't reach a smooth experience.

So I consider h.265 as not suitable for my Raspberry Pi. Well, seems that I have to encode it to something more Raspberry friendly 🙂

Still, it was a nice project!

 

Weblinks

Mit dem Raspberry Pi Internet Radio horchen

Ein weiterer Einsatzzweck für euren Raspberry: Empfangsstation für Internet-Radio!

Wir realisieren das ganze mit dem Music Player Daemon und einem schicken kleinen Webinterface

Web Interface um die Radiostation zu steuern
Web Interface um die Radiostation zu steuern

Los gehts!

Wir brauchen für den Betrieb drei Pakete: alsa-utils, mpd und mpc

Bei der Installation vom Music Player Daemon (mpd) taucht folgende Fehlermeldung auf, die wir getrost ignorieren können

Starting Music Player Daemon: mpdlisten: bind to ‘[::1]:6600′ failed: Failed to create socket: Address family not supported by protocol (continuing anyway, because binding to ’127.0.0.1:6600′ succeeded)
Failed to load database: Failed to open database file “/var/lib/mpd/tag_cache”: No such file or directory

 Der Dienst läuft nun. Wir müssen ihn nur noch konfigurieren. Dazu editieren wir die Datei /etc/mpd.conf wie folgt:

  • bind_to_address "localhost" mit bind_to_address "127.0.0.1" erstetzen
  • Auskommentieren von audio_buffer_size  und buffer_before_play

Die Änderungen werden erst nach einem Neustart vom mpd wirksam.

Als nächstes müssen wir noch die Radiosender einstellen. Dies geschieht über eine Playlist. Dazu legen wir die Datei /var/lib/mpd/playlists/radio.m3u an. Die Datei beinhaltet lediglich Links zu den Radiosender und kann ganz einfach geschrieben werden:

Eine passable Auswahl an Radiosender findet sich unter http://www.surfmusik.de/

Um die Musik zu starten, muss noch die Playlist geladen werden und der (erste?) Eintrag abgespielt werden. Dazu gebt ihr einfach in die Konsole ein

Beachte: mpc load Lädt m3u-Playlists (ohne Erweiterung eingeben!) vom Ordner /var(lib/mpd/playlist. Die Eingabe von mpc load radio ist damit absolut ausreichend!

Schickes Webinterface

Ich verwende das MPD-Webinterface von sn0opy (GitHub). Die Lösung benötigt einen Webserver mit PHP.

Wir müssen das ganze Downloaden und ins /var/www-Verzeichnis packen. Ich benenne den Ordner noch um, damit ich das ganze unter raspberry/radio finden kann

Fertig 🙂