simple way to mount a ramdisk?

Malcolm Kay malcolm.kay at
Sat May 24 20:59:50 PDT 2003

On Sat, 24 May 2003 13:32, Neo wrote:
> Hi,
> can anyone tell me please, how to "mount a mfs-filesystem for dummies"?
> My hdd is /dev/ad0 with two slices /dev/ad0s1a as / and /dev/ad0s1b as

Does this mean you have the trees /usr, /var and /tmp all resident on 
/dev/ad0s1a ?

> swap, the ramdisk (for example 8 megs in size) should become /ram.

Assuming you're running FBSD 4.x then:

If /dev/md0c does not exist then
	# cd /dev
        # MAKEDEV md0

        # mkdir /ram

Now follow the man page md(4):
        # disklabel -r -w md0 auto
        # newfs /dev/md0c
        # mount /dev/md0c /ram
        # chmod 1777 /ram

        # df
should show md0c mounted on /ram

The capacity is set up when the kernel is compiled
and is 20000 sectors of 512 bytes or about 10Mb.
But empty sectors and sectors of uniform data 
don't consume real memory space.

For automated installation on boot:
The devices /dev/md0 and/dev/md0c should be permanent
once created and so should /ram directory.

You need to add somewhere in the start sequence:

     if [ -e /dev/md0 -a -e /dev/md0c ]; then
             disklabel -r -w md0 auto && \
             newfs /dev/md0c && \
             mount /dev/md0c /ram && \
             chmod 1777 /ram

This might be for example added to /etc/rc.local  or
created as such if it does not exist.

Or better create a file /usr/local/etc/rc.d/
with the lines:
     if [ -e /dev/md0 -a -e /dev/md0c ]; then
             disklabel -r -w md0 auto && \
             newfs /dev/md0c && \
             mount /dev/md0c /ram && \
             chmod 1777 /ram

Make sure the file is set to executable:
     # chmod +x /usr/local/etc/rc.d/
(The file name must terminate in .sh)


More information about the freebsd-questions mailing list