Booting from CompactFlash

Integration of CompactFlash as target filesystem for systems having a CompactFlash adapter is still incomplete, as up to now a portable and scriptable tool for setting up partitions is missing. If you know some utility working with *BSD as well as with linux, please let me (n0-1 AT freewrt DOT org) know.

Till integration is complete, follow this guide as I will describe below how to set it up manually.

Prerequisites

What you will need is:

  • CompactFlash card and reader
  • a partitioning utility of your choice (I prefer Linux fdisk)
  • FreeWRT Rootfs and a kernel ready for booting from CompactFlash

Partitioning the CompactFlash Card

Using the card reader, create two partitions on the card. For later examples I assume the CompactFlash disk is recognized as device "sda".

The first partition will contain the kernel only, so a size of ~3MB should be far enough for most cases.

The second partition will contain the rootfs, so I recommend using all remaining space on the disk for it.

Toggle the types of the first partition to 0x27, of the second partition to 0x83.

Compiling FreeWRT

Currently the only hardware supporting CompactFlash as target filesystem is Documentation/Hardware/RouterBoard532. Choosing read-write filesystem for compact flash (ext2), you'll get a kernel with support for either booting from CompactFlash and ext2, as it is the standard filesystem for CompactFlash disks.

Installing everything to disk

After the build has been completed, kernel image (with name vmlinux) and rootfs (with name root) are found inside build_mipsel/linux-2.4-rb/. (RouterBoard's bootloader does not understand gzipped kernel images, so we use an image in standard elf format.)

The kernel image has to be copied into the first partition of the CompactFlash disk. There is no need for a filesystem inside this partition'' To be sure everything is written as expected, use dd for the job:

$ dd if=build_mipsel/linux-2.4-rb/vmlinux of=/dev/sda1

For installing the rootfs a filesystem has to be created first:

$ mke2fs /dev/sda2

Then, (as root) you can mount and fill the partition:

# mount /dev/sda2 /mnt
# rsync -avP build_mipsel/linux-2.4-rb/root/ /mnt

NOTE: the trailing slash ('/') of the first argument to "rsync" is mandatory, else you will create a directory called "root" inside "/mnt".

BEWARE: the rootfs is not functional yet. An initial set of device nodes has to be created, and the ownership should be changed recursively. All these jobs are done by the script called 'instprep-rb.sh' in the RootFS's topdir. Just execute it and all should be prepared well.

That's it, you should be done. umount the disk, insert it into the slot of your embedded device and power it on. Maybe you have to reconfigure your bootloader to get it booting from CompactFlash.