Tuesday, October 13, 2009

Use busybox to create rootfs.

Since I was involved in the embedded linux world, I had tried to create root file system of my own base on busybox. The details of creating rootfs for my QT2410(S3C2410) board are described as below for my records or maybe for someone's references.

1. Install cross compiler to /usr/local/arm/3.3.2 (my cross compiler is version 3.3.2.)
2. Use busybox to build system application.
2.1. Download busybox from http://www.busybox.net/ (busybox-1.15.2.tar.gz for example).
2.2. tar zxvf busybox-1.15.2.tar.gz
2.3. cd busybox-1.15.2 and make menuconfig
Build Options --->
[*] Build BusyBox as a static binary (no shared libs) //avoid lib link problem
...
(/usr/local/arm/3.3.2/bin/arm-linux-) Cross Compiler prefix //fill in your cross compiler
Shells --->
Choose your default shell (ash) --->
(X) ash
2.4. make ARCH=arm all install
(This will get system applications under _install folder if compile succeeds.)

3. Create structure of root file system
3.1 mkdir rootfs
3.2 cd rootfs
3.3 mkdir bin dev etc lib proc sbin tmp usr var
3.4 chmod 1777 tmp
3.5 mkdir usr/bin usr/lib usr/sbin
3.5 mkdir var/lib var/lock var/log var/run var/tmp
3.7 chmod 1777 var/tmp
3.8 cd dev
3.9 mknod console c 5 1
3.10 mknod tty0 c 4 0
3.11 mknod tty1 c 4 1
3.12 mknod tty2 c 4 2
3.13 mknod tty3 c 4 3
3.14 mknod tty4 c 4 4
3.10 mknod sda1 b 8 1 //for usb
4. Create root file system image (initfs.img)
4.1 mkdir initfs
4.2 dd if=/dev/zero of=initfs.img bs=1k count=3072
4.3 /sbin/mke2fs -F -v -m0 initfs.img
4.4 mount -o loop initfs.img initfs
4.5 cp -av rootfs/* initfs
4.6 umount initfs
5. Using u-boot to write initfs.img to nand flash
5.1 nand erase 200000 300000
5.2 tftp 32000000 initfs.img
5.3 nand write 32000000 200000 300000

5.4 setenv bootargs noinitrd root=/dev/mtdblock2 rw console=ttySAC0,115200 mem=64M init=linuxrc
6. Reboot the system and you will see something like the followings.