Skip to main content.

9.5.3. Root File System on a cramfs File System

cramfs is a compressed, read-only file system.

Advantages are:

Disadvantages are:

To create a cramfs based root file system please proceed as follows:

  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. Create the required device files. We do this here by unpacking a special tarball which holds only the device file entries. ALERT! Note: this requires root permissions!
    # cd rootfs
    # tar -zxf /tmp/devices.tar.gz
  3. Many tools require some storage place in a filesystem, so we must provide at least one (small) writable filesystem. For all data which may be lost when the system goes down, a "tmpfs" filesystem is the optimal choice. To create such a writable tmpfs filesystem we add the following lines to the /etc/ script:
    # mount TMPFS because root-fs is readonly
    /bin/mount -t tmpfs -o size=2M tmpfs /tmpfs
    Some tools require write permissions on some device nodes (for example, to change ownership and permissions), or dynamically (re-) create such files (for example, /dev/log which is usually a Unix Domain socket). The files are placed in a writable filesystem; in the root filesystem symbolic links are used to point to their new locations:
    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/*
  4. We can now create a cramfs file system image using the mkcramfs tool:
    $ ROOTFS_DIR=rootfs                 # directory with root file system content
    $ ROOTFS_ENDIAN="-r"                # target system has reversed (big) endianess
    $ ROOTFS_IMAGE=cramfs.img           # generated file system image
    Swapping filesystem endian-ness
    -48.78% (-86348 bytes)  in.ftpd
    -46.02% (-16280 bytes)  in.telnetd
    -45.31% (-74444 bytes)  xinetd
    Everything: 1864 kilobytes
    Super block: 76 bytes
    CRC: c166be6d
    warning: gids truncated to 8 bits.  (This may be a security concern.)
  5. We can use the same setup as before for the JFFS2 filesystem, just changing the bootargument to "rootfstype=cramfs"
9.5.2. Root File System on a JFFS2 File System 1. Abstract 9.5.4. Root File System on a Read-Only ext2 File System
Prev Home Next