1. Initrd
Creation of Initrd:
To create an (initially empty) initrd use the following steps:
note: you can change the count to your required file system size. e.g: count = 16384
you will get a 16MB ramdisk.
$ mkdir Ramdisk
$ cd Ramdisk
$ sudo dd if = /dev/zero of=/dev/ram0 bs=1k count=16834
$ sudo mke2fs -vm0 /dev/ram0 16384
$ sudo tune2fs -c 0 /dev/ram0
$ sudo dd if=/dev/ram0 bs=1k count=16384 | gzip -v9 > ramdisk.gz
$ ls
ramdisk.gz
Now we have a (empty) gzipped ramdisk image with (extracted) size of 16384.
Filling Initrd:
To fill empty ramdisk created above with all files needed for ramdisk, mount the
image and fill it. Content would be e.g: Busybox and/or other applications and/or
libraries.
$ sudo mkdir mnt
$ gunzip ramdisk.gz
$ ls
ramdisk
$ sudo mount -o loop ramdisk mnt/
$ ls
mnt ramdisk
Now create below files in 'mnt' directory:
bin, dev, etc, lib, proc, root , sbin, sys, appmount, tmp, usr, usr/bin, usr/sbin.
After creating files in 'mnt' directory, copy the busybox executable and init file in
mnt/bin/.
Note : contents of sd card, creation of busybox
executable and init file is described later in this
document.
1
2. Initrd
$ cd mnt
$ sudo mkdir bin
$ sudo mkdir dev
$ sudo mkdir etc
$ sudo mkdir lib
$ sudo mkdir proc
$ sudo mkdir root
$ sudo mkdir sbin
$ sudo mkdir sys
$ sudo mkdir appmount
$ sudo mkdir tmp
$ sudo mkdir usr
$ sudo mkdir -p usr/bin
$ sudo mkdir -p usr/sbin
$ ls
appmount bin dev etc lib proc root sbin sys tmp usr
Now copy the busybox executable and init file in bin,
$ cp <busybox directory path>/busybox bin/busybox
$ cp <init file created directory path>/init bin/init
$ cd bin
$ ls
init busybox
$ cd ..
$ sudo umount mnt
$ gzip -v9 ramdisk
$ ls
mnt ramdisk.gz
Now copy this ramdisk.gz to sd card in boot partition,
$ cp ramdisk.gz /media/boot
Using this ramdisk.gz, we are going to boot beaglebone black through sd card.
2
3. Initrd
Booting BBB using Ramdisk:
Insert micro SD card, by holding the user boot button power up the board, Press the
space bar for booting u-boot.
Uboot# setenv bootargs console=tty00, 115200n8 root=/dev/ram0 rw
ramdisk_size=16384 initrd=0x81000000, 16M rootfstype=ext2
uboot# fatload mmc 0:1 0x81000000 ramdisk.gz
uboot# fatload mmc 0:1 0x80200000 uImage
uboot# fatload mmc 0:1 0x82000000 am335x-boneblack.dtb
uboot# bootm 0x80200000 – 0x82000000
kernel will be successfully loaded and kernel mounts the filesystem(busybox) you
will get terminal with symbol like this ' /# '
/# ls
appmout etc sbin usr
bin lib proc sys
dev linuxrc root tmp
Contents of SD card:
For booting BBB using Ramdisk, it should contains following contents:
# ramdisk.gz (use created ramdisk.gz)
# uImage
# am335x-boneblack.dtb
For Kernel image (uImage) and am335x-boneblack.dtb:
$ git clone https://github.com/beagleboard/linux.git
$ cd linux
$ git remote -v
origin https://github.com/beagleboard/linux.git (fetch)
origin https://github.com/beagleboard/linux.git (push)
$ make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- bb.org_defconfig
$ make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- uImage dtbs
LOADADDR=0x80008000
3
4. Initrd
Creation of Busybox executable:
First download busybox code from, https://busybox.net/downloads/
Cross compile busybox for ARM platform
$ make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- menuconfig
Enable the following features:
Busybox settings ---> Build Options --->
[*] Build Busybox as a static binary(no shared libs).
() cross compiler prefix option --> enter “arm-linux-gnueabi-”.
Save and exit configuration.
Building busybox by entering the following command:
$ make
You will get a busybox binary, which is ARM executable and statically linked.
Creation of init file:
Inside ramdisk directory, create a file with init and give executable permissions to it,
and copy the following contents:
#!/bin/busybox sh
/bin/busybox install s
mount t proc none /proc
mount t sysfs none /sys
echo /sbin/mdev > /proc/sys/kernel/hotplug
/sbin/mdev s
mknod /dev/ttyO0 c 5 0
mount t ubifs ubi0:rootfs /appmount
exec /bin/sh
$ chmod 777 init
The busybox executable and init file should be placed inside “bin” which is present in
“mnt”.
4