Initramfs
“An initial RAM filesystem, or initramfs, is a compressed cpio archive. cpio is an old Unix archive format, similar to TAR and ZIP but easier to decode and so requiring less code in the kernel. You need to configure your kernel with CONFIG_BLK_DEV_INITRD to support initramfs.”
Create an initramfs
To create the archive, compress it and add a U-Boot header, run these commands:
cd ~/rootfs
find . | cpio -H newc -ov --owner root:root > ../initramfs.cpio
cd ..
gzip initramfs.cpio
mkimage -A arm -O linux -T ramdisk -d initramfs.cpio.gz uRamdisk
To embed the initramfs into the kernel, set the CONFIG_INITRAMFS_SOURCE kernel configuration to the full path of the just created cpio archive. With menuconfig, this step is done in General setup | Initramfs source file(s). The file has to be an uncompressed cpio file ending in .cpio, not .gzip, .zip, etc.
Booting the initramfs
Here are two options displayed on how to boot the initramfs. The first one is QEMU on the host system, the other one on the board itself.
Booting with QEMU
QEMU_AUDIO_DRV=none \
qemu-system-arm -m 256M -nographic -M versatilepb \
-kernel zImage
-append "console=ttyAMA0 rdinit=/bin/sh" \
-dtb versatile-pb.dtb
Booting the BeagleBoneBlack
Needed to boot the image on the BeagleBoneBlack is the previously prepared SD-Card with the Kernel, Bootloader and Rootfs built, using the arm-cortex_a8-linux-gnueabihf toolchain. The previously created uRamdisk shall be copied onto the boot partition on the microSD card. Then the board should be booted, up to the point where the U-Boot prompt comes in. Booting it this way will need us to enter these commands:
fatload mmc 0:1 0x80200000 zImage
fatload mmc 0:1 0x80f00000 am335x-boneblack.dtb fatload mmc 0:1 0x81000000 uRamdisk
setenv bootargs console=ttyO0,115200 rdinit=/bin/sh
bootz 0x80200000 0x81000000 0x80f00000
To avoid entering this everytime the board boots, just chain them all into one String called “bootcmd” and enter “saveenv” after. Bootcmd is the initial command that U-Boot runs at boot. More about U-Boot here!
setenv bootcmd "fatload mmc 0:1 0x80200000 zImage; fatload mmc 0:1 0x80f00000 am335x-boneblack.dtb fatload mmc 0:1 0x81000000 uRamdisk; setenv bootargs console=ttyO0,115200 rdinit=/bin/sh; bootz 0x80200000 0x81000000 0x80f00000"
saveenv
run bootcmd
After this is done, the procfs has to be mounted.
#!/bin/sh
/bin/mount -t proc proc /proc
# Other boot-time commands go here
/bin/sh
This process can be automized, as explained in the following.
Init Programm
The init program starts by reading the config file under /etc/inittab. It can look something like this:
::sysinit:/etc/init.d/rcS
::askfirst:-/bin/ash
The first line starts the script rcS under /etc/init.d when init is started. The second line prints the message “Please press Enter to activate this console” to the console and starts a shell when Enter is pressed. The dash before the following path means that it will become a login shell, which sources /etc/profile and ~/.profile before giving the shell prompt.
BusyBox init provides a default inittab if none is present in the root filesystem. It is a little more extensive than the preceding one.
The file /etc/init.d/rcS can look something like this:
#!/bin/sh
mount -t proc proc /proc
mount -t sysfs sysfs /sys
The rcS script must be executable!
source: Mastering Embedded Linux Programming - Third Edition By Frank Vasquez, Chris Simmonds