244

When doing an apt-get upgrade on my RPi 3, many lines of output show up like this:

Adding 'diversion of /boot/bcm2708-rpi-b-plus.dtb to /usr/share/rpikernelhack/bcm2708-rpi-b-plus.dtb by rpikernelhack'
Adding 'diversion of /boot/bcm2708-rpi-b.dtb to /usr/share/rpikernelhack/bcm2708-rpi-b.dtb by rpikernelhack'
Adding 'diversion of /boot/bcm2708-rpi-cm.dtb to /usr/share/rpikernelhack/bcm2708-rpi-cm.dtb by rpikernelhack'
Adding 'diversion of /boot/bcm2709-rpi-2-b.dtb to /usr/share/rpikernelhack/bcm2709-rpi-2-b.dtb by rpikernelhack'
Adding 'diversion of /boot/bcm2710-rpi-3-b.dtb to /usr/share/rpikernelhack/bcm2710-rpi-3-b.dtb by rpikernelhack'
Adding 'diversion of /boot/kernel.img to /usr/share/rpikernelhack/kernel.img by rpikernelhack'
Adding 'diversion of /boot/kernel7.img to /usr/share/rpikernelhack/kernel7.img by rpikernelhack'
Adding 'diversion of /boot/COPYING.linux to /usr/share/rpikernelhack/COPYING.linux by rpikernelhack'
...
...
...

I'm not very educated on Linux kernel features and this looks pretty specific to the RPi.

My question is: What is all this?

What is a 'diversion'? What do all these files (as a group) that are being referenced, actually do? What is 'rpikernelhack'?

I did a little bit of googling and couldn't easily find anything interesting. I figure I'm not the only one who's curious about this so I hope this is an appropriate question!

MD-7
  • 2,853
  • 2
  • 11
  • 12
  • 11
    Certainly not the only one who's curious - I'd like to know as well. – joan Jul 18 '16 at 18:52
  • Me too. They took a quite long time when i am doing `apt-get upgrade`. – Kong Chun Ho Jul 18 '16 at 18:59
  • 2
    Probably not as exciting as you think -- I think the "hack" here is on the package management system, not the kernel. https://www.debian.org/doc/debian-policy/ap-pkg-diversions.html – goldilocks Jul 18 '16 at 19:24
  • Here's a sample from the `preinst` part: `dpkg-divert --package rpikernelhack --divert /usr/share/rpikernelhack/kernel.img /boot/kernel.img`. @goldilocks' link explains `--package` clearly. – Aloha Jul 20 '16 at 04:53
  • they might have chosen something a little less alarming... –  Sep 11 '16 at 16:39
  • 2
    @qbicdesign I think that hinges on your understanding of the word ["hack"](https://stallman.org/articles/on-hacking.html). One commonplace use would be to refer to something that's perhaps not an ideal or proper solution to a problem but works, at least in a pinch or with minimal effort, so someone is just indicating that explicitly (the one at the beginning of that article isn't a solution to anything, but the common theme would be "improper" = "using something in a way it was not intended" = "not necessarily wrong, maybe even clever"). – goldilocks Sep 11 '16 at 16:48
  • Perhaps at least some comfort is that after it adds the diversion, it eventually reports "Removing diversion of ... by rpikernalhack" – Cyclical Obsessive Nov 12 '17 at 15:12

2 Answers2

321

"rpikernelhack" is a fake package name and a directory name used as part of a hack (in the sense of a dirty but expedient solution to a problem) to work around the fact that the Raspberry Pi foundation decided to make /boot a fat32 partition and dpkg does not get on well with fat32. I was the one who initially came up with the idea, though it was refined later by others.

dpkg will install new files onto a fat32 partition (spewing some warnings along the way), but if it tries to update an existing file on a fat32 partition it will fail (iirc it tries to make a backup of the old file by creating a hardlink and fat32 doesn't support hardlinks).

When people (including me) started trying to make deb packages of Pi kernels and firmware they ran into this problem, a package would install initially but trying to upgrade it would fail, ouch.

My workaround was to (ab)use the "diversion" feature in dpkg. This feature was intended to allow files to be diverted so they could be replaced with either locally modified versions or versions from another package, but I was able to use it from the maintainer scripts in such a way that dpkg would perform its installation tasks on a Linux partition and then move the file to its final location at the end.

Diversions require you to either specify a "package name" or "local". If you specify a package name then the diversion will affect files owned by all packages except the one you specify (the intent here is to allow a package to divert a file owned by another package and then install its own versions). I also needed a directory to divert the files to.

Using the name of the kernel package being installed would have rendered the hack ineffective. Using "local" also seemed wrong, since that is supposed to be reserved for use by the local sysadmin. So I needed a fake package name that was unlikely to conflict with anything. I came up with "rpikernelhack", I also used this same string for the directory name.

Matthias Braun
  • 211
  • 2
  • 7
Peter Green
  • 6,002
  • 1
  • 15
  • 22
  • 56
    Thank you so much for this answer. It was very insightful towards the design and naming decisions. The internet is a magic place for me to have been able to get a response from the guy who actually worked on this specific piece in question. – MD-7 Mar 20 '19 at 15:51
  • 4
    Was just updating my RPi and wondered about this weird log, thanks for the ultimate clarification. – schlump Jun 15 '19 at 19:12
  • 4
    Wouldn't it be cleaner to make dpkg play nicely with FAT32. Here is the MR I suggest: https://salsa.debian.org/cklein-guest/dpkg/merge_requests/1/diffs – user1202136 Oct 05 '19 at 17:54
  • 1
    Fantastic usage of the word refined, that's kind of a nightmare. Why did they chose FAT32? – Tegra Detra May 28 '20 at 13:22
  • 9
    @James I'm not entirely sure but I'd guess to make the partition more widely compatible. There's a lot of setup you can do (such as enabling ssh, adding WiFi networks and general config setup etc.) that you can do by accessing the boot partition. If it was a Linux partition, Windows users would have a much harder time doing this. Since the Raspberry Pi is intended to be an education tool, this is probably the driving factor for making the boot partition FAT32. – NathanielJS Jul 20 '20 at 15:01
  • This explains much - I just happened to glance down at my screen that's going crazy on apt update. Just a bunch of `rpikernelhack` lines. – Wayne Werner Sep 09 '20 at 01:07
  • 3
    I believe this is a very unfortunate name. "Hack" makes people suspicious. – deanresin Jul 30 '21 at 21:07
  • @HeavyGray the raspberry pi bootloader (firmware) has to be able to read the partition and, presumably, that was all that was supported. Not sure about the RPi but EFI System Partitions have to be FAT https://en.wikipedia.org/wiki/EFI_system_partition (some other distros mount this in /boot/efi or similar instead of /boot) – nijave Aug 30 '21 at 18:04
  • What are the reasons that dpkg doesn't work on fat32? – Arrow_Raider Oct 27 '21 at 22:42
  • IIRC it tries to make a hardlink as a backup of the old file so it can restore it when the installation fails and fat32 doesn't support hardlinks. – Peter Green Oct 27 '21 at 22:43
  • Phew, I just updated my pi because it was suffering from unexplainable memory leaks... After seeing this I was afraid it got hacked... thankfully it's a mere workaround. – BitfulByte Feb 11 '22 at 10:03
52

It's just the directory name given by the developers who have created a Raspberry Pi specific set of patches to the Linux kernel.

It is a fix by the Raspbian developers to fix a FAT file-system corruption issue present in the 2016 kernel, this updates to the 2017 kernel and is nothing to worry about. To make this kernel update you need to use sudo apt install -f to fix the dependency issues caused by the bug (the -f in this context means, according to the man page, apt-get(8):

-f, --fix-broken
Fix; attempt to correct a system with broken dependencies in place. ...

)

SlySven
  • 3,621
  • 1
  • 16
  • 44
Rebroad
  • 655
  • 4
  • 10