Tuesday, March 07, 2006

RAM disk

What is RAM disk?
RAM disk is a portion of RAM which is being used as a disk drive. Any data stored in RAM disk is lost when system is switched off. very useful for embedded system where there is not disk drive. Linux kernel 2.4 has built-in support for ramdisks

How to create a RAM disk in linux?
  • RAM disk size : default RAM disk size supported by linux is 4 MB so, if you need more ram space then include ramdisk_size=XXXX in kernel command line for kernel to reserve memory for ramdisk. here XXXX is ram size expressed in 1k block. for 16 MB, ramdisk_size=16000
  • Format your RAM disk : command :- mke2fs – m 0 /dev/ram0 16384. Linux supports 16 RAM disks by default (ram0 to ram15).
  • Mount your RAM disk : command :- mkdir /mnt/rd; mount /dev/ram0 /mnt/rd
  • Verify your RAM disk : command :- df -h

How to create RAM disk for embedded linux?

  • create a empty file of your file system size. here it is 16MB command :- dd if=/dev/zero of=ramdisk bs=1k count=16384
  • format the empty file as ext2 file system command :- mke2fs -F -m 0 -i 1024 ramdisk
  • create a mount point and mount the empty file system command :- mkdir ramdiskmountpoint;mount -t ext2 -o loop ramdisk ramdiskmountpoint
  • copy the tinytarget(uclibc and busybox) to mounted file system command :- cp -a tinytarget/* ramdiskmountpoint/
  • unmount the mount point and delete it command :- umount ramdiskmountpoint;rm -rf ramdiskmountpoint
  • compress the new file system present in raddiskfile command :- gzip -v9 ramdisk
  • Copy ramdisk.gz to arch/XXXX/ramdisk/ramdisk.gz where XXXX is target name. ex. ppc,mips,arm,etc.,
  • Enable the following options in kernel config : ramdisk and initial ramdisk

0 Comments:

Post a Comment

<< Home