All Forums
 Embedded Linux
 Linux FAQ
 What is a ramdisk?
 Forum Locked
 Send Topic to a Friend
 Printer Friendly
Author Topic  

jlackey

213 Posts

Posted - 20 May 2002 :  17:41:04  Show Profile  Email Poster
What is a ramdisk and why do I need one?

The linux kernel expects several important files to exist in a 'root file system' when it boots. In embedded systems like ours, these files may be stored in a ramdisk. A ramdisk uses RAM as a disk so that a hard drive or flash file system is not required. The ramdisk is compressed using gzip and decompressed when the kernel boots.

How big can a ramdisk be?

There are two limitations on the size of a ramdisk.
    1. If the compressed ramdisk image is stored in a partition in On-Board Flash memory and the compressed ramdisk.gz file is bigger than this partition, the bootloader will not program it to On-Board Flash. The bootloader can load ramdisk images that are bigger than the On-Board Flash partition into RAM from an ATA CF or PCMCIA card, though.

    To change the size of a partition, you must have Ver 4.0 or later of the ADS Linux Bootloader. Consult your manual for instructions on how to do this.

    2. The compressed ramdisk image is decompressed into RAM. The bigger your uncompressed ramdisk is, the less RAM you have remaining for the kernel and user programs. This limitation depends on the amount of RAM installed and the amount needed by the kernel and your software to run. If your ramdisk has a lot of free space, you may want to consider making it smaller. Enter the command:
      df
    to see how much free space you have in your ramdisk.

The kerenl also has maximum compressesed and uncompressed ramdisk size variables. To use a ramdisk image that is bigger than the default maximums, you must specify the new values in the kernel command line or modify the default values in the source code and recompile the kernel.

To change the kernel command line, you must have Ver 4.0 or later of the ADS Linux Bootloader and a recent kernel. Consult your manual for instructions on how to specify the command line.

For older kernels you must modify the source code and recompile the kernel. Edit the source file for your platform in the linux/arch/arm/mach-sa1100/ directory and change it as follows:

To increase the uncompressed maximum, change:
    setup_ramdisk();
The size is specified in blocks (1024 bytes).

To increase the maximum compressed size (which still can't be bigger than the partition if you want to load from on board flash), change:
    setup_initrd();
The size is specified in bytes.

How can I use files or programs that require more disk space?
  • You can use NFS to share disk space on a host machine and access it through Ethernet.

  • You can set up a flash file system (i.e. JFFS2, CRAMFS) in flash memory.

  • You can use a PCMCIA Flash card. The kernel can mount an ATA flash card formatted as FAT12 or FAT16.


Do I need to maintain my ramdisk?

Usually, no. Each time your board boots, the ramdisk is recreated from the compressed image. During development, though, you may want to check the file system, especially after you've made a lot of changes.

To check and repair the file system on your ramdisk, decompress it and use fsck:
    gunzip ramdisk.gz
    fsck.ext2 ramdisk

You should see output like this:
    e2fsck 1.23, 15-Aug-2001 for EXT2 FS 0.5b, 95/08/09
    ramdisk has been mounted 25 times without being checked, check forced.
    Pass 1: Checking inodes, blocks, and sizes
    Pass 2: Checking directory structure
    Pass 3: Checking directory connectivity
    Pass 4: Checking reference counts
    Pass 5: Checking group summary information
    ramdisk: 498/1792 files (2.4% non-contiguous), 6268/7168 blocks

Use fsck again:
    fsck.ext2 ramdisk

This time, your ramdisk should be clean:
    e2fsck 1.23, 15-Aug-2001 for EXT2 FS 0.5b, 95/08/09
    ramdisk: clean, 498/1792 files, 6268/7168 blocks

Don't forget to recompress your ramdisk when you're done:
    gzip ramdisk

Can I create a second ramdisk?

To create an additional ramdisk, do this:
    mke2fs -vm0 /dev/ram1 1024
    mkdir /my_ram_disk
    mount /dev/ram1 /my_ram_disk

This will create a 1 MB ramdisk using /dev/ram1.

The root file system uses /dev/ram0. Additional ramdisks can be created on /dev/ram1, /dev/ram2 and /dev/ram3.

30-Dec-2003: jlackey - update information related to the root file system
19 NOV 2002: jlackey - add information on partition resizing and changing the kernel command line.
  Topic  
 Forum Locked
 Send Topic to a Friend
 Printer Friendly
Jump To:
Eurotech Support Forums © Eurotech Inc. Go To Top Of Page
This page was generated in 0.03 seconds. Snitz Forums 2000