Creating filesystem images with device tables

The kernel has a utility, gen_init_cpio, that creates a cpio file based on format instructions set out in a text file, called a device table, which allows a non-root user to create device nodes and to allocate arbitrary UID and GID values to any file or directory.

The same concept has been applied to tools that create other filesystem image formats:

  • jffs2: mkfs.jffs2
  • ubifs: mkfs.ubifs
  • ext2: genext2fs

We will look at jffs2 and ubifs in Chapter 7, Creating a Storage Strategy, when we look at filesystems for flash memory. The third, ext2, is a fairly old format for hard drives.

They each take a device table file with the format <name> <type> <mode> <uid> <gid> <major> <minor> <start> <inc> <count> in which the following applies:

  • name: Filename
  • type: One of the following:
    • f: A regular file
    • d: A directory
    • c: A character special device file
    • b: A block special device file
    • p: A FIFO (named pipe)
  • uid The UID of the file
  • gid: The GID of the file
  • major and minor: the device numbers (device nodes only)
  • start, inc, and count: (device nodes only) allow you to create a group of device nodes starting from the minor number in start

You do not have to specify every file, as with gen_init_cpio: you just have to point them at a directory – the staging directory – and list the changes and exceptions you need to make in the final filesystem image.

A simple example which populates static device nodes for us is as follows:

/dev         d  755  0    0  -    -    -    -    -
/dev/null    c  666  0    0    1    3    0    0  -
/dev/console c  600  0    0    5    1    0    0  -
/dev/ttyO0   c  600  0    0   252   0    0    0  -

Then, use genext2fs to generate a filesystem image of 4 MiB (that is 4,096 blocks of the default size, 1,024 bytes):

$ genext2fs -b 4096 -d rootfs -D device-table.txt -U rootfs.ext2

Now, you can copy the resulting image, rootfs.ext, to an SD card or similar.

Putting the root filesytem onto an SD card

This is an example of mounting a filesystem from a normal block device, such as an SD card. The same principles apply to other filesystem types and we will look at them in more detail in Chapter 7, Creating a Storage Strategy.

Assuming that you have a device with an SD card, and that the first partition is used for the boot files, MLO and u-boot.img – as on a BeagleBone Black. Assume also that you have used genext2fs to create a filesystem image. To copy it to the SD card, insert the card and identify the block device it has been assigned: typically /dev/sd or /dev/mmcblk0. If it is the latter, copy the filesystem image to the second partition:

$ sudo dd if=rootfs.ext2 of=/dev/mmcblk0p2

Then, slot the SD card into the device, and set the kernel command line to root=/dev/mmcblk0p2. The complete boot sequence is as follows:

fatload mmc 0:1 0x80200000 zImage
fatload mmc 0:1 0x80f00000 am335x-boneblack.dtb
setenv bootargs console=ttyO0,115200 root=/dev/mmcblk0p2
bootz 0x80200000 – 0x80f00000
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.116.36.194