2

I've followed this tutorial when it comes to compiling a kernel for the Raspberry Pi. I'm installing onto a properly partitioned SD card, which I completely formatted first (it now has a fat32 boot partition and ext4 file system partition). However, I believe that, in the linked tutorial, they are installing their compiled kernel onto an SD card that already contained an image of Rasbpian. This is because when I boot my Pi with my SD card (the only directory in the file system in my SD is the lib/ directory containing firmware/ and modules/), the boot fails, saying:

PANIC: No init found

I figure that this is because there is because of a lack of a file system present on the SD card during the boot (or something of the like, I'm very new to this entire process). I've done some Googling and come across the concept of an initramfs--is my problem that I need one configured to allow the the boot process to continue? Should I be generating an initramfs, or is it best to just load my custom kernels onto SD cards that have already been imaged with the kernel I am customizing from?

SlySven
  • 3,621
  • 1
  • 18
  • 45
npp1993
  • 193
  • 1
  • 9
  • In other comments you mention the Pi 2. If this is the case, don't use the cross-compiler toolchain from elinux.org. The Pi 2 is a different architecture, ARMv7 vs. ARMv6. Fortunately, most linux distros include a pre-built toolchain for arm which is in fact ARMv7; you should be able to find the package by searching, eg. apt-cache search gcc | grep arm. Use that for Pi 2 kernels. You then just have to set the CROSS_COMPILE prefix to the correct tuple (probably arm-linux-gnu-). – goldilocks Aug 10 '15 at 16:06
  • I did use that compiler, yep. – npp1993 Aug 11 '15 at 02:45

1 Answers1

1

No, you do not need an initramfs. The purpose of that is to facilitate the use of a wide variety of hardware; it enables the kernel to pick from a range of (potentially mutually exclusive) drivers needed in order to mount the root filesystem and proceed. Hence, they are the norm on general purpose linux distros because those are intended for use on a broad variety of hardware.

However, the pi uses its own special kernel that can't be used on anything else anyway, and pis are uniform WRT basic hardware, so an initramfs is not used. You could use one, but don't bother unless you have a particular reason to do so.

Init, as the wikipedia article says, is the first non-kernel process on a unix-style operating system. It is also the only one ever actually started by the kernel, and it cannot be killed; all other processes are descendants of init.

Note that an OS kernel all by itself won't do anything once loaded, because there is nothing for it to do.

I believe the linux kernel, after it mounts the root filesystem, looks for init in /sbin/init and if that doesn't exist may try /bin/sh instead. Since you don't have any root filesystem, you get this panic (but at least you know your kernel works).

On Raspbian wheezy, the init program used is a variant of SysV init (also described in that wikipedia article), and the executable is literally /sbin/init. Raspbian jessie, following Debian which switched from SysV after ~20 years, uses systemd; in this case /sbin/init is a symbolic link.

You can use, or at least try, anything via the same technique -- either just name the binary /sbin/init or use a symlink. You do not need to use a static binary since the kernel handles linking.

If you use a normal userland, it does not have to be from the same place as your kernel, but you do need to install the kernel modules onto it. If you built the kernel yourself, you should do this regardless.

goldilocks
  • 58,859
  • 17
  • 112
  • 227
  • Thank you for the detailed answer very much. Just to clarify--should there be a step added to my build process, in which I create /sbin and copy the systemd binary into it? Should this systemd binary be generated in my kernel compilation process? Again, huge thanks. – npp1993 Aug 09 '15 at 19:33
  • A normal operating system consists of two distinct parts, a kernel, and a userland. The kernel is usually a monolithic entity -- such as the linux kernel. However, as already mentioned, a kernel all by itself doesn't do anything. Its purpose is to service the userland. The userland in "linux" distros is actually a completely independent project, hence the more formal term GNU/Linux, since the fundamental parts of the userland are produced by GNU. Linux is actually just an OS kernel, although the term is used colloquially to refer to the whole shebang. – goldilocks Aug 09 '15 at 20:20
  • Anyway, point is, you need a userland. It does not come with the kernel. It would be easier to give you a further suggestion if you explain what you are actually trying to do. Why do you want to compile a kernel from scratch? What are you intending to use the system for? – goldilocks Aug 09 '15 at 20:20
  • Again, huge thanks. The project I'm working on requires me to compile the 3.6.11+ kernel for the Pi 2. The reason for this is that kernel versions past 3.6.11+ broke the USB video capture card functionality our project relies on. I figured I would have to do some custom kernel compilations, and that the best place to start would be compiling a vanilla kernel first. – npp1993 Aug 10 '15 at 12:42
  • So--do you know if it would be even possible to compile the 3.6.11+ kernel for the RPi2? Or, would a better solution be compiling the 3.6.11+ version of the kernel modules that enable this video capture ability for the current version of the RPi2 kernel? – npp1993 Aug 10 '15 at 12:43
  • Okay, in other words you just want a normal userland like Raspbian provides. Create an SD card using which ever pi distro you like. I've written up how to install/use the kernel with that here: http://raspberrypi.stackexchange.com/q/34252/5538 – goldilocks Aug 10 '15 at 13:37
  • BTW, I don't know if the fact that the Pi 2 came out well after 3.6 will make a difference; the only way to know is to try, I guess. If I have time later I'll knock one out quick and let you know. – goldilocks Aug 10 '15 at 16:09
  • So, I actually just got it to work. I flashed the 3.6.11+ release from the RPi foundation to an SD (so I had the GNU userland in place), compiled the 3.6.11+ kernel and modules per the instructions in the tutorial I linked, copied kernel+modules/firmware over, and just booted. Seems to run fine (and the video capture works)!! Thank you very, very much for your detailed help. – npp1993 Aug 10 '15 at 16:37