Skip to main content.

9.5.4. Root File System on a Read-Only ext2 File System

When storing the root file system in on-board flash memory it seems only natural to look for special flash filesystems like JFFS2, or for other file system types that are designed for such environments like cramfs. It seems to be a bad idea to use a standard ext2 file system because it contains neither any type of wear leveling which is needed for writable file systems in flash memory, nor is it robust against unorderly shutdowns.

The situation changes if we use an ext2 file system which we mount read-only. Such a configuration can be very useful in some situations.



To create an ext2 image that can be used as a read-only root file system the following steps are necessary:

  1. Create a directory tree with the content of the target root filesystem. We do this by unpacking our master tarball:
    $ mkdir rootfs
    $ cd rootfs
    $ tar -zxf /tmp/rootfs.tar.gz
  2. Like with the cramfs root file system, we use "tmpfs" for cases where a writable file system is needed and add the following lines to the /etc/ script:
    # mount TMPFS because root-fs is readonly
    /bin/mount -t tmpfs -o size=2M tmpfs /tmpfs
    We also create the same symbolic links for device files that must be placed in a writable filesystem:
    dev/ptyp0 /tmpfs/dev/ptyp0     dev/ttyp0 /tmpfs/dev/ttyp0
    dev/ptyp1 /tmpfs/dev/ptyp1     dev/ttyp1 /tmpfs/dev/ttyp1
    dev/ptyp2 /tmpfs/dev/ptyp2     dev/ttyp2 /tmpfs/dev/ttyp2
    dev/ptyp3 /tmpfs/dev/ptyp3     dev/ttyp3 /tmpfs/dev/ttyp3
    dev/ptyp4 /tmpfs/dev/ptyp4     dev/ttyp4 /tmpfs/dev/ttyp4
    dev/ptyp5 /tmpfs/dev/ptyp5     dev/ttyp5 /tmpfs/dev/ttyp5
    dev/ptyp6 /tmpfs/dev/ptyp6     dev/ttyp6 /tmpfs/dev/ttyp6
    dev/ptyp7 /tmpfs/dev/ptyp7     dev/ttyp7 /tmpfs/dev/ttyp7
    dev/ptyp8 /tmpfs/dev/ptyp8     dev/ttyp8 /tmpfs/dev/ttyp8
    dev/ptyp9 /tmpfs/dev/ptyp9     dev/ttyp9 /tmpfs/dev/ttyp9
    dev/ptypa /tmpfs/dev/ptypa     dev/ttypa /tmpfs/dev/ttypa
    dev/ptypb /tmpfs/dev/ptypb     dev/ttypb /tmpfs/dev/ttypb
    dev/ptypc /tmpfs/dev/ptypc     dev/ttypc /tmpfs/dev/ttypc
    dev/ptypd /tmpfs/dev/ptypd     dev/ttypd /tmpfs/dev/ttypd
    dev/ptype /tmpfs/dev/ptype     dev/ttype /tmpfs/dev/ttype
    dev/ptypf /tmpfs/dev/ptypf     dev/ttypf /tmpfs/dev/ttypf
    tmp /tmpfs/tmp     var /tmpfs/var
    dev/log /var/log/log        
    In case you use dhclient also:
    etc/dhclient.conf /tmpfs/var/lib/dhclient.conf     etc/resolv.conf /tmpfs/var/lib/resolv.conf

    To place the corresponding directories and device files in the tmpfs file system, the following code is added to the /etc/ script:
    mkdir -p /tmpfs/tmp /tmpfs/dev \
             /tmpfs/var/lib/dhcp /tmpfs/var/lock /tmpfs/var/run
    while read name minor
            mknod /tmpfs/dev/ptyp$name c 2 $minor
            mknod /tmpfs/dev/ttyp$name c 3 $minor
    done <<__EOD__
    0  0    
    1  1    
    2  2    
    3  3    
    4  4    
    5  5    
    6  6    
    7  7    
    8  8    
    9  9    
    a 10    
    b 11    
    c 12    
    d 13    
    e 14    
    f 15    
    chmod 0666 /tmpfs/dev/*
  3. Like we did for the ramdisk, we now create an ext2 file system image using the genext2fs tool:
    $ ROOTFS_DIR=rootfs                 # directory with root file system content
    $ ROOTFS_SIZE=3700                  # size of file system image
    $ ROOTFS_FREE=100                   # free space wanted
    $ ROOTFS_INODES=380                 # number of inodes
    $ # device description file
    $ ROOTFS_IMAGE=ext2.img             # generated file system image
    $ genext2fs -U \
            -d ${ROOTFS_DIR} \
            -D ${ROOTFS_DEVICES} \
            -b ${ROOTFS_SIZE} \
            -r ${ROOTFS_FREE} \
            -i ${ROOTFS_INODES} \
  4. We can again use the same setup as before for the JFFS2 filesystem, just changing the boot argument to "rootfstype=ext2" (or simply omit it completely as this is the default anyway), and we must change the "rw" argument into "ro" to mount our root file system really read-only:
    Linux version 2.4.25 (wd@xpert) (gcc version 3.3.3 (DENX ELDK 3.1.1 3.3.3-9)) #1 Sun Jun 12 18:32:18 MEST 2005
    On node 0 totalpages: 4096
    zone(0): 4096 pages.
    zone(1): 0 pages.
    zone(2): 0 pages.
    Kernel command line: root=/dev/mtdblock6 ro rootfstype=ext2 ip= panic=1
    Decrementer Frequency = 187500000/60
    Calibrating delay loop... 49.86 BogoMIPS
9.5.3. Root File System on a cramfs File System 1. Abstract 9.5.5. Root File System on a Flash Card
Prev Home Next