cramfs is a compressed, read-only file system.
Advantages are:
- file system uses compression,
thus making efficient use of flash memory
- Allows for quick boot times as only used files get
loaded and uncompressed
Disadvantages are:
- only the whole image can be replaced (not individual files)
- additional storage needed for writable persistent data
-
mkcramfs tool does not support device table,
so we need root permissions to create the required device files
To create a
cramfs based root file system please proceed as follows:
- 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
- Create the required device files. We do this here by unpacking
a special tarball which holds only the device file entries.
Note: this requires root permissions!
# cd rootfs
# tar -zxf /tmp/devices.tar.gz
- 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/rc.sh 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/rc.sh script:
mkdir -p /tmpfs/tmp /tmpfs/dev \
/tmpfs/var/lib/dhcp /tmpfs/var/lock /tmpfs/var/run
while read name minor
do
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
__EOD__
chmod 0666 /tmpfs/dev/*
- 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
PATH=/opt/eldk/usr/bin:$PATH
mkcramfs ${ROOTFS_ENDIAN} ${DEVICES} ${ROOTFS_DIR} ${ROOTFS_IMAGE}
Swapping filesystem endian-ness
bin
dev
etc
...
-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.)
- We can use the same setup as before for the JFFS2 filesystem,
just changing the bootargument to
"rootfstype=cramfs"