pavement

RAMdisks, creating under FreeBSD 5.x

From FreeBSDwiki
Jump to: navigation, search

I invariably get irritated and confused by mdconfig's syntax, since I need it just often enough to never remember how to use it, and no more. And most of the readily google-able documentation on the web covers FreeBSD 4.x's vnconfig instead, which is useless if you're running a 5.x system. So I just wrote myself a handy little shell script named makeramdisk.sh that I keep in my home directory for reference's sake:

#!/bin/sh

case "$1" in
start)
        /sbin/mdconfig -a -t malloc -s 256M -u 10
        /sbin/newfs -U /dev/md10
        /sbin/mount /dev/md10 /mnt/ramdisk
        echo "256MB ramdisk created on /dev/md10 and mounted on /mnt/ramdisk"
        exit 0
        ;;
stop)
        /sbin/umount /mnt/ramdisk
        /sbin/mdconfig -d -u 10
        echo "ramdisk unmounted from /mnt/ramdisk and deleted from /dev/md10"
        ;;
*)
        echo "Usage: `basename $0` {start|stop}" >&2
        exit 64
        ;;
esac

Under FreeBSD 6.x (and possibly under 5.x as well), the first three lines of the start section can be combined into a single line, as per the below.

#!/bin/sh

case "$1" in
start)
        /sbin/mdmfs -s 256M md10 /mnt/ramdisk
        echo "256MB ramdisk created on /dev/md10 and mounted on /mnt/ramdisk"
        exit 0
        ;;
stop)
        /sbin/umount /mnt/ramdisk
        /sbin/mdconfig -d -u 10
        echo "ramdisk unmounted from /mnt/ramdisk and deleted from /dev/md10"
        ;;
*)
        echo "Usage: `basename $0` {start|stop}" >&2
        exit 64
        ;;
esac

To use this script, you would type makeramdisk.sh start or makeramdisk.sh stop to create and mount, or dismount and delete, respectively, a 256MB RAMdisk on /dev/md10. (Note: the script as written depends on the prior existence of a directory at /mnt/ramdisk. If that directory does not exist, you're going to have problems.)

You should be able to figure out from the examples what you'd need to do different to change the size of the drive, where you mount it, etc.

Personal tools