Specifications
Here is one possible solution: Your software distribution consistes of two files: The first file is the Linux
kernel with a minimal ramdisk image attached (using the multi-file image format for U-Boot); U-Boot can
load and boot such files from a FAT or VFAT file system. The second file is your root file system. For
convenience and speed we use again an image of an ext2 file system. When Linux boots, it will initially use
the attached ramdisk as root file system. The programs in this ramdisk will mount the FAT or VFAT file
system - read-only. Then we can use a loop device (see losetup(8)) to associate the root file system image with
a block device which can be used as a mount point. And finally we use pivot_root(8) to change the root file
system to our image on the CF card.
This sounds not so complicated, and actually it is quite simple once you understand what needs to be done.
Here is a more detailed description:
The root file system image is easy: as mantioned before, we will use an ext2 file system image, and
to avoid wearing the flash storage device we will use it in read-only mode - we did a read-only ext2
root file system image before, and here we can just re-use the existing image file.
1.
The initial ramdisk image that performs the pivot_root step must be created from scratch, but we
already know how to create ramdisk images, so we just have to figure out what to put in it.
The most important tool here is nash, a script interpreter that was specifically designed for such
purposes (see nash(8)). We don't need any additional tools, and if we use static linking, then the
nash binary plus a small script to control it is all we need for our initial ramdisk.
To be precise, we need a couple of (empty) directories (bin, dev, etc, lib, loopfs, mnt, proc,
and sysroot), the bin/nash binary, the linuxrc script and a symbolic link sbin pointing to
bin:
drwxr-xr-x 2 wd users 4096 Apr 13 01:11 bin
-rwxr-xr-x 1 wd users 469512 Apr 11 22:47 bin/nash
drwxr-xr-x 2 wd users 4096 Apr 12 00:04 dev
drwxr-xr-x 2 wd users 4096 Apr 12 00:04 etc
drwxr-xr-x 2 wd users 4096 Apr 12 00:04 lib
-rwxr-xr-x 1 wd users 511 Apr 13 01:28 linuxrc
drwxr-xr-x 2 wd users 4096 Apr 12 00:04 loopfs
drwxr-xr-x 2 wd users 4096 Apr 12 00:09 mnt
drwxr-xr-x 2 wd users 4096 Apr 12 00:04 proc
lrwxrwxrwx 1 wd users 3 Jun 12 18:54 sbin -> bin
drwxr-xr-x 2 wd users 4096 Apr 12 00:04 sysroot
2.
We also need only a minimal device table for creating the initial ramdisk:
#<name> <type> <mode> <uid> <gid> <major> <minor> <start> <inc> <count>
/dev d 755 0 0 - - - - -
/dev/console c 640 0 0 5 1 - - -
/dev/hda b 640 0 0 3 0 - - -
/dev/hda b 640 0 0 3 1 1 1 8
/dev/loop b 640 0 0 7 0 0 1 4
/dev/null c 640 0 0 1 3 - - -
/dev/ram b 640 0 0 1 0 0 1 2
/dev/ram b 640 0 0 1 1 - - -
/dev/tty c 640 0 0 4 0 0 1 4
/dev/tty c 640 0 0 5 0 - - -
/dev/ttyS c 640 0 0 4 64 0 1 4
/dev/zero c 640 0 0 1 5 - - -
3.
To create the initial ramdisk we perform the usual steps:
$ INITRD_DIR=initrd
$ INITRD_SIZE=490
$ INITRD_FREE=0
$ INITRD_INODES=54
$ INITRD_DEVICES=initrd_devices.tab
$ INITRD_IMAGE=initrd.img
4.
9.5.6. Root File System in a Read-Only File in a FAT File System 122