Using losetup and mke2fs to Create an ext2 Filesystem
After you have collected the packages you want to include, do the following to use losetup and mke2fs to create an ext2 filesystem:
- Set up a loopback device to make the RAM disk file appear to the system to be a block device:
# losetup /dev/loop0 ramdisk.image
You might need to use a different loopback device (for example, /dev/loop1 or /dev/loop2) if /dev/loop0 is already in use.
If the losetup command fails, make sure that the Block devices > Loopback device support option is enabled in your kernel configuration on the host system.
- Create an ext2 filesystem on the loopback device:
# mke2fs -b 1024 /dev/loop0
In this step, you must specify the block size of 1024 bytes (1KB) that was used to create the image file, and you must specify the loopback device associated with the image file.
- Mount the blank RAM disk image:
# mount /dev/loop0 <mount_point>
where <mount_point> is the name of the directory on which you want to temporarily mount the loopback device in order to copy files into it. This mount is temporary, and the location is not important to the RAM disk image.
- Copy the material that you want to include in the initrd image. Delete unwanted files and strip
symbols to save space:
# cp -r <filename_list> /mnt
- Unmount the loopback device and compress the image file:
# umount /mnt # losetup -d /dev/loop0 # gzip -9 ramdisk.image
- Make sure your kernel is configured to support an initrd, as described in Configuring the Kernel to Support RAM Disks, then save the updated kernel configuration and recompile the kernel with the initial RAM disk.
- Do one of the following:
- If your architecture combines the initrd with the kernel using a Makefile target, then
issue the make zImage.initrd command to produce a bootable image containing
both the kernel and the initial RAM disk. Remember that the x86 architecture and some
XScale targets do not support initrds that are part of the kernel image.
- If you are deploying the initrd and kernel image as separate files, then copy the compressed
image ramdisk.image.gz to the /tftpboot directory:
# cp ramdisk.image.gz /tftpboot
- If your architecture combines the initrd with the kernel using a Makefile target, then
issue the make zImage.initrd command to produce a bootable image containing
both the kernel and the initial RAM disk. Remember that the x86 architecture and some
XScale targets do not support initrds that are part of the kernel image.