Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
up vote 14 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:


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- 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

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
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

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 '14 at 15:30

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

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

The object of a ramdrive is speed. Tmpfs is not a drive. Loop devices are not drives, but you can put a drive image on a loop device. Ram disks "are" drives, and very fast drives. Try running:

hdparm -t /dev/sda 

and then:

hdparm -t /dev/ram0

You'll see what I mean! But hdparm sometimes destroys the ram drive. So, you have to make it again.

Sometimes there are no /dev/ram devices. To make one:

mknod -m 0777 /dev/ram0 b 1 0 

but it won't have any size. To give it size:

dd if=/dev/zero of=/dev/ram0

and it will stop when the drive is full. The maximum size is determined by the kernel config parm: CONFIG_BLK_DEV_RAM_SIZE.

Then, just format it, i.e.

mke2fs /dev/ram0

And mount it:

mount /dev/ram0 /mnt/ramdrive

A favorite of mine is debugging code stored on a ramdrive. The compiles are at least 10x speed of code stored on a hard drive. Database tables stored on ramdrive also fly, but you must have a script that writes to hard disk periodically. Most admins don't have the guts to put data on ram disks. And some tables are too large.

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .