Using Linux, when I boot I automatically have 16 16MB ramdisks, however, I would like to create one really large ramdisk to test some software.

I found that I can adjust the size of the ramdisks already on the system with the kernel boot parameter ramdisk_size however, this makes all 16 ramdisks (/dev/ram0 - /dev/ram15) the size that is specified. So if I want to create a 1GB ramdisk, I would need 16GB of memory.

Basically, I want to create one 10GB ramdisk which would be /dev/ram0. How would I go about doing that? I assume there is a kernel boot parameter, but I just haven't found it.

link|improve this question
feedback

3 Answers

You should use tmpfs for that instead.

mount -t tmpfs -o size=10g none /mnt/point
link|improve this answer
Can I make a filesystem on a tmpfs? I need a block device that resides in memory that I can make a filesystem on. Can I do this on a tmpfs? – Kevin S. Mar 9 '11 at 13:31
tmpfs is a filesystem. It just happens to reside in memory. – Ignacio Vazquez-Abrams Mar 9 '11 at 17:07
I appreciate the answer and normally a tmpfs would do the trick, but I need to create an xfs filesystem on the part of memory I am writing to. – Kevin S. Mar 10 '11 at 22:12
feedback
up vote 1 down vote accepted

Although the tmpfs answer would usually work (thanks Ignacio), however, in my unique case I was looking for something a little bit more specific.

I found information about how to configure ramdisks from this link Linux Ramdisk mini-HOWTO unfortunately, this link is broken, but if you google the url, you can view google's cached version of the page. Also I learned about kernel configuration options from this link Linux Kernel Documentation :: ramdisk.txt

There are two kernel configuration options that you can set in your .config file:

CONFIG_BLK_DEV_RAM_COUNT=1
CONFIG_BLK_DEV_RAM_SIZE=10485760

This configured my kernel to create one ramdisk that is 10G at boot time. Please note that the size is specified in KB and don't specify more memory than you actually have. (If you are editing your .config with make menuconfig look under Device Drivers->Block Devices)

Also, like I mentioned in the question you can specify the size of the ramdisks you create via the kernel boot parameter ramdisk_size. So I currently boot my machine with the line:

kernel /vmlinuz-2.6.32.24 ro root=LABEL=/ rhgb quiet ramdisk_size=10485760

Now I can boot my machine and I can make a filesystem on it, mount it and use it exactly like a block device.

# mkfs.xfs /dev/ram0
# mount /dev/ram0 /mnt/ramdisk
link|improve this answer
feedback

You could use a loop file instead. Just create a loop file the size you want it (if you wish to put it into a tmpfs ramdisk, fine), and then format the loop file and mount it.

dd if=/dev/zero of=myfile bs=1G count=10
mkfs.xfs -d file myfile
mount -t xfs -o loop myfile mymntpoint
link|improve this answer
I actually tried this before I posted my question. It is a great solution, but the software I am testing acts differently when it is dealing with a file and not a block device, that is why I was looking at the ramdisk option. Thanks. – Kevin S. Mar 11 '11 at 13:55
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.