Creating Initial RAM Disks Under Microsoft Windows

Many Linux software vendors use Cygwin, a Linux-like environment for Microsoft Windows, to satisfy the needs of customers who want identical Linux development functionality on Linux and Windows systems. Cygwin does an excellent job of providing this, and includes an extensive collection of Linux software that has been ported to the Cygwin environment. Most Linux software simply has to be recompiled in order to run under Cygwin, as long as equivalent functionality is available at some level in Windows.


One significant difference between Linux and Windows systems is the concept of loopback devices, which Linux uses to mount files that contain a Linux filesystem image. The most common case in which this is done is when you are creating an initial RAM disk for use by the Linux kernel during the boot process. With the 2.6 Linux kernel, initial RAM disks do not even have to be filesystem images; the new initramfs approach uses a cpio-format archive which is extracted into a RAM disk. However, many initial RAM disks are still ext2 filesystem images, and creating files containing filesystem images is also common when creating filesystems that you will subsequently burn into flash.


As mentioned in the previous article in this series, the traditional mechanism for creating a file containing a filesystem image on Linux systems is to create an empty file of the desired size using the Linux dd command, creating a filesystem in that file using the mkfs command, and then mounting the formatted file using a loopback device. Unfortunately, Windows does not provide any native mechanisms for mounting a file as a filesystem on a Windows system.


Using genext2fs to Create ext2 Filesystems

The genext2fs program solves this problem by enabling you to create an ext2 filesystem image from the contents of a Linux directory. The genext2fs program is very similar to the mkcramfs or mkfs.jffs2 application that creates CRAMFS and JFFS2 filesystem images.

Applications such as TimeSys’s Developer Suite and BusyBox will create a valid filesystem hierarchy for you in a directory, or you can construct it yourself manually. Once you have cxreated a directory containing the files, device nodes, and other directories that you want to appear in your root filesystem, you can create your ext2 filesystem image using a command like the following:

genext2fs -b size-in-blocks -d directory image-file-name

The -b option enables you to specify the size of the filesystem that you want to create in blocks. The -d option identifies the directory that contains your filesystem image, 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 on. Get the complete genext2fs man page.

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 draiver 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. 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.


Summary

Being able to develop Linux applications on a desktop system running Microsoft Windows is a convenient alternative to creating a dedicated Linux development system that actually runs Linux. Cygwin makes this possible, and utilities such as genext2fs make up for the lack of flexibility in the Windows device model. With Cygwin and genext2fs, it is easy to create an ext2 filesystem image even on systems that do not directly support the ext2 filesystem.



author: Bill von Hagen


Return to Coffee House

 

   Home      Products & Subscriptions      Explore      Resource Center      Support & Services      About Timesys      Timesys Partners

   Privacy Policy        Contact Us        Terms of Service        Site Map