Overview
First, when we talk about a ramdisk, we're usually talking
about an image of an ext2 filesystem and not necessarily the
ramdisk device driver. We often use the ramdisk device
driver, copying in the ramdisk image, mounting the filesystem,
etc., but we could also use the flash block device driver or
the loopback driver. These instructions tell how to use the
loopback device to access an ext2 image, in which case ramdisk
is not really involved at all.
The filesystem image files found on ftp.handheld.org are
compressed. Before you can modify them, you must uncompress
them using gunzip.
Given an uncompressed filesystem image, you can mount it
either through a ramdisk device or through the loopback
filesystem type. Via ramdisk:
mkdir mnt
cat init-ramdisk-2-35 > /dev/ram1
mount /dev/ram1 mnt
Or via loopback:
mount -o loop init-ramdisk-2-35 mnt
In both of these cases, we omitted the '-t fstype' option
from mount because it will read the superblock to determine
the filesystem type. I've found that I often need to supply
the type when mounting fat filesystems, but maybe that's just
me.
Finally, we almost always compress the image before making
copies of it, and we install the compressed filesystem image
for the initial ramdisk, because the initrd driver knows how
to recognize and unzip compressed filesystem images. We use
the highest level of compression to minimize xmodem download
times.
A small note: if you did some work (copied, moved, deleted
files), the ramdisk will have some dirty blocks. Those blocks
are not in use by the ext2 filesystem, but they still have
the original file contents, and hence aren't that easy
compressable as empty blocks (i.e. blocks only containing
zeros). To get a smaller compressed image, you can copy the
contents of the ramdisk to a clean ramdisk. Create a second
ramdisk (or loopback device) and mount it. Suppose we have the
original ramdisk mounted on /tmp/orig and the new one on
/tmp/new, we just copy the contents:
cd /tmp/orig
tar cf - . | ( cd /tmp/new ; tar xpf - )
Unmount the ramdisks, extract the new ramdisk, compress it,
and you'll have a smaller compressed image with exactly the
same contents.
Modifying an existing ext2 filesystem image
- gunzip ramdisk-file.gz
- mkdir temp
- mount -o loop ramdisk-file temp
- cd temp
- (Do what you need to do.)
- cd ..
- umount temp
- gzip -9 ramdisk-file
Creating a new ext2 filesystem image
- dd if=/dev/zero of=init-ramdisk.img bs=1k
count=8k
- mke2fs -i 1024 -b 1024 -m 3 -F -v
init-ramdisk.img
- mkdir temp
- mount -o loop init-ramdisk.img temp
- cd temp
- (Do what you need to do.)
- cd ..
- umount temp
- gzip -9 init-ramdisk.img
Creating an ext2 filesystem on a device
mkfs -t ext2 /specialfile
where specialfile is something like /dev/ram1 (for a
ramdisk), /dev/flash3 (for a flash device), /dev/fd0 (for
a floppy), or init-ramdisk.img (for an image of a
filesystem stored in a pre-existing file). The example
above makes a filesystem onto an 8MByte file. This is the
equivalent of formatting the drive. Instead of ext2, we
could use another filesystem type, such as reiserfs, fat,
etc.
Going from a device to a file
dd if=specialfile of=imagefile
will read the entire special file into a plain file, e.g.:
dd if=/dev/ram1 of=init-ramdisk-2-35
But remember to unmount it before you extract it, or it
can be out-of-sync (i.e.: the kernel hasn't flushed all
data to disk yet). And of course the "mounted" bit is set
if it is still mounted, so the next time you mount it
you'll get a warning about dirty filesystems.
Accessing cramfs is similar to ext2 ramdisk, except that
cramfs is a readonly filesystem. It's new to 2.4.x so most
2.2.x-based development machines do not support it. Since
cramfs is readonly, you cannot 'mkfs -t cramfs' and then
populate. The mkcramfs utility creates an image of a
cramfs filesystem from a directory tree.
Linux 2.4.x Desktop Computer
- mkdir mntpoint
- mkdir temp
- mount -t cramfs init-2-40.cramfs mntpoint -o
loop
- cp -a mntpoint temp
- (do what you need to do)
- cd ..
- mkcramfs temp init-2-41.cramfs
- Get into the boot loader and load the file where it
belongs.
Linux 2.2.x Desktop Computer
Since 2.2 does not support cramfs filesystems, you cannot mount
the cramfs filesystem. You will need the 'src' tar ball,
e.g. root-src-2-40.tar.gz
- tar xfz root-src-2-40.tar.gz
- cd root
- (do what you need to do)
- cd ..
- mkcramfs root root-src-2-41.cramfs
- Get into the boot loader and load the file where it
belongs
Ramfs is new to 2.4.x. It is a filesystem which keeps all
files in RAM. It allows read and write access. Ramfs grows and
shrinks to accomodate the files it contains, in contrast to a
'ext2 ramdisk', which gets allocated a fixed amount of RAM. To
use ramfs, type:
- mkdir /mnt/mntpoint
- mount -t ramfs ramfs /mnt/mntpoint
Questions?
Please post any questions to handhelds@handhelds.org.
Thank you.
|