3.4. Create compressed Root File System (rootfs.gz)

An initial RAM disk (rootfs) is used as the root file system for the router. The boot loader will load the kernel and root file system to RAM memory. That implies that once the kernel starts, it does not need to access the relatively slow flash memory.

All examples in this document assume that the directory structure starting at $ROOTFS_DIR will be written to the initial RAM disk. This section describes how to achive this.

The compressed root filesystem is created using tar and gzip. To conserve disk space, the static libraries, man pages and include files are omitted. The commands below create the compressed initial RAM disk. [17]

dd if=/dev/zero of=$ROOTFS_FILE bs=1k count=8192
mke2fs -q -F -m 0 -i 1024 $ROOTFS_FILE

mkdir -p $FLASH_MNT
sudo mount -t ext2 -o loop $ROOTFS_FILE $FLASH_MNT
  tar --exclude="*/lib*\.a" --exclude="*/man/*" --exclude="*/include/*" -cpf - * | \
    sudo tar -C $FLASH_MNT -xf -
  du -sh $ROOTFS
  sudo chown -h -R 0:0 $FLASH_MNT
sudo umount $FLASH_MNT

gzip -9 -c $ROOTFS_FILE > $ROOTFS_FILE.gz

[17] If the file system size exceeds the 8192 kBytes, then consider removing unsused files such as /lib/modules/ objects for operating system versions that are no longer used.