Using genext2fs to Create as ext2 Filesystem
One significant difference between Linux and Windows/Cygwin systems is the concept of loopback devices, which makes a file appear to the filesystem to be a mountable block device (for example, a hard disk). Unfortunately, Windows does not provide any native mechanisms for mounting a file as a filesystem on a Windows system. The genext2fs program allows you to create an ext2 filesystem image from the contents of a directory.
After you have collected the packages you want to include, use a command like the following one to create an ext2 filesystem:
genext2fs -b <size_in_blocks> -d <directory> <image_file_name>
The -b option enables you to specify the size (in blocks) of the filesystem that you want to create, the -d option identifies the directory that contains your filesystem, and the last argument on the command line is the name of the filesystem image file that you want to create. The genext2fs application also supports other, optional, arguments that enable you to specify the number of reserved blocks in the filesystem (-r), fill unallocated blocks with a specified value (-e), and so forth. The genext2fs man page describes the other options available for this command.
Creating and Using a Device Table File
Manually creating device nodes in the /dev subdirectory of the directory that holds your filesystem can be tedious, so genext2fs automates this for you by enabling you to provide a device specification file, often referred to as a device table. You supply the name of this file using the -f option. A device specification file is a text file in which each line contains the permissions, major and minor numbers, and the name of the device node that you want to create. Major and minor numbers are used by the kernel to select the device driver to use when accessing that device. The following is a sample section from a device table file:
drwx /dev crw- 4,0 /dev/console crw- 1,2 /dev/kmem crw- 1,1 /dev/mem crw- 1,3 /dev/null crw- 4,64 /dev/ttyS0
The first line creates the /dev directory in your filesystem image. Each subsequent entry creates the specified character device in that directory. For example, the second line creates the Linux console device as a character device with the major number 4 and the minor number 0. Note that the /dev/console and /dev/null devices must exist in your root filesystem even if you are using udev or BusyBox’s mdev to automatically create device nodes in your target filesystem.