Solved Mount memory disk on boot

I've searched google and this forum but still no sucess. I've created a file-backed filesystem (memory disk). what I want is to automatically mount the md(4) device at boot. What would be the correct entries in the rc.conf and fstab. Thank you for your inputs.
 
Last edited by a moderator:
Indeed there is a nice example but how do you handle this?

Code:
# md /tmp mfs rw,-s32m 2 0
md: Command not found.

Tried on FreeBSD 9, 11, 12.

Maybe there is an example of what I can add to fstab manually?
 
I have read this also, but device md is already present in generic kernel. If I create a ram disk with mdmfs, I don't see md with kldstat, so it is built in for sure. And another proof:

Code:
# kldload geom_md
kldload: can't load geom_md: module already loaded or in kernel

The missing part is the command.
 
md is the driver name, not the command line tool.
See mdmfs(8) and also mdconfig(8).

Oh, I understand your question...
You have to set something like mdconfig_md0=".." (arguments of mdconfig) in rc.conf.
Then, write something like "/dev/md0 /mnt ... " (normal fstab syntax) in fstab.
 
I realize this is marked as SOLVED , yet no working solution is provided.

And just now I was creating a USB flash based small system for a router/gateway/wifi. With USB being very slow at writes, I'm using memory file system wherever possible -- specifically in /var that has to be written to. And I was also searching forums as to how exactly my /etc/fstab entry should look.

So, just for future reference and to save your time as it would have saved mine )))
In fact, while rc.conf or loader.conf settings WILL create such image at boot time, you can very well do without them.
Note, the simple answer of how it works is found in mdmfs(8):
Code:
 Create and    mount a    32 megabyte swap-backed    file system on /tmp:
       mdmfs -s 32m    md /tmp
     The same file system created as an    entry in /etc/fstab:
       md /tmp mfs rw,-s32m    2 0
Generally, then, the 4th block is your specific mount options -- first, mount(8) related options, then your file system-specific ones. Accordingly, in order to boot-time mount /var as vnode-backed mfs (with image found at /var.img) the following string in /etc/fstab is enough:
Code:
md    /var    mfs    rw,sync,noatime,-P,-F=/var.img    0    0
For mount(8) related options sync and noatime are good enough AFAIK. Other OS manuals also use nodev in similar scenarious, but it is not used in FreeBSD (see mount(8)) and will only make mount fail. Then -P -F $file.img are needed to mount vnode-backed mfs.

With this single entry in /etc/fstab and nothing else mdconfig will create md image from my /var.img file and mfs mount it on /var. Note, too, that md device numbering will be handled automatically, as explained in the man.
 
Back
Top