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

I've been playing with Linux RAMDISKs, as in the block device /dev/ram0. I understand that when I first start writing to one of these devices some RAM is allocated to it.

How do I free the memory used by, say, /dev/ram0? Put another way: how do I indicate to the Linux kernel that I'm done and it can reclaim whatever resources are held by /dev/ram0?

share|improve this question
Did you mount the ram disk to something like /mnt/ramdisk? – Mike Keller Aug 5 '11 at 14:57
I used mkfs /dev/ram0 and then mounted it, did some experiments (testing how my app copes with out of disk-space conditions) and unmounted it. But that doesn't free the memory that backs /dev/ram0. – RobM Aug 5 '11 at 19:42
up vote 2 down vote accepted

Unless you format the ramdisk something along the lines of

mke2fs -m 0 /dev/ram0

The ramdisks themselves don't actually occupy any memory space.

If you do format and mount a ramdisk however, the only way that I remember doing is by using freeramdisk but that was a long long time ago.

Some other resources you might want to check out:

share|improve this answer
Thanks freeramdisk does the trick. Verified by experiment while watching the output from free. – RobM Aug 5 '11 at 18:04

Step 1: Consider what exactly was already developed by your whole body

Red-colored Cap produces of sixteen ramdisks automatically, although there're not necessarily "active" or making use of almost any RAM. It listings products ram0 : ram 19, however solely ram0 : ram15 are usually usable automatically. To check on these block products out there, utilize the using get:

[root]# ls -l /dev/ram*
lrwxrwxrwx 1 root root four Jun 12 00: thirty-one /dev/ram -> ram1

Step 2: Improve ramdisk size

Ramdisk size can be controlled by way of command-line solution which is passed on the kernel in the course of trunk. Since GRUB could be the default bootloader intended for Red-colored Cap 9, I'll transform /etc/grub.conf while using brand new kernel solution. The actual kernel solution intended for ramdisk size can be: ramdisk_size=xxxxx, where xxxxx could be the size indicated with 1024-byte hindrances. Can do for you I'll complement /etc/grub.conf for you to configure of sixteen MB ramdisks

Step 3: Data format the particular ramdisk

There' no requirement for you to file format the particular ramdisk as a journaling file process, therefore most of us only will utilize the common ext2 file process. When i solely desire to use one particular ramdisk, so i is only going to file format /dev/ram0:

Step: Make a attach place along with attach the particular ramdisk

Today you have formatted the particular ramdisk, you need to make a attach place for doing this. Then you can definitely attach your current ramdisk along with work with it. Many of us will use the particular service /mnt/rd because of this operations.

Activity 5: Make use of the ramdisk

Since it has been designed, you can easlily replicate, shift, get rid of, revise, along with quantity data files round the ramdisk as provided that these people wound up with the actual physical hard drive partiton. This is actually the fantastic position intended for a peek at decrypted GPG or possibly OpenSSL data files, in addition to a fantastic position for just a crank out data files which is to be encrypted. Right after your own host is definitely run lower, a lot of record linked with data files designed round the ramdisk have left.

In order to unmount this ramdisk, merely enter your next:

[root]# umount -v /mnt/rd
/dev/ram0 umounted.
share|improve this answer
This doesn't address the question though - unmounting a ramdisk does not deallocate the memory: if you remount it the data is still where you left it. As per the accepted answer, freeramdisk does the trick. – RobM May 12 '13 at 16:25

You must log in to answer this question.

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