Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

share|improve this question

6 Answers 6

up vote 9 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/blockdev/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
share|improve this answer

On lighthouse 64 (puupy linux based on slackware) I did this;

mke2fs /dev/ram1 4096000 # nearly 4G ramdisk, choose the size of ramdisk less than actual ram!
mount /dev/ram1 /mnt/dvd # dvd on my laptop is unused choose your device from /mnt/

There you have a ramdisk mounted as a directory /mnt/dvd where you can copy paste save do everything as you would in a hd directory except in ram. remember to save your files to hd before shutdown.

share|improve this answer

To make a large ram disk after boot without messing around with kernel parameters. Use tmpfs, make a file, mount it via loop, and mount that via a filesystem:

mount -t tmpfs -o size=200M tmpfs temp/
cd temp/
dd if=/dev/zero of=disk.img bs=1M count=199
losetup /dev/loop0 disk.img
mkfs.ext4 /dev/loop0
cd ..
mount /dev/loop0 temp2/

Probably a bit of performance penalty going through multiple different layers... but at least it works.

share|improve this answer

Another option is to use the loop devices (as opposed to the loobpack feature of mount as previously mentioned):

dd if=dev/zero of=myfs.img bs=1M count=1024
losetup /dev/loop0 myfs.img
mkfs.xfs /dev/loop0

Now /dev/loop is a legitimate block device which your app would act upon like a physical device or ramdisk, except that it is file backed. You can mount is somewhere or have you app act upon the device node, which implements the standard block ioctls. Saves your system ram and useful to keep around for testcases, etc.

(You can even fdisk myfs.img, create partitions on it and use --offset and --sizelimit with losetup to point each /dev/loopX to specific partitions in the image, so loop0, loop1 become just like sdc1, sdc2, etc)

share|improve this answer
    
+1 as this does not need recompiling the kernel –  m-ric Jun 18 at 15:30

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
share|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
2  
Loopback devices are block devices, so I'm not sure how that is possible? –  pjc50 Jul 10 '12 at 14:11

You should use tmpfs for that instead.

mount -t tmpfs -o size=10g none /mnt/point
share|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
1  
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
    
The problem with tmpfs is that it is backed by swap. If you start using swap, then you are losing the benefits of being in pure RAM. Also, some people prefer to have an area that isn't backed for crypto applications. –  drudru Aug 11 '13 at 22:27

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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