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.
 
Code:
md /osys mfs rw,sync,noatime,-P,-F=/mnt/osys.fs 0 0
This code works perfectely.
When booting the system then file /mnt.osys.fs is mapped on a /osys . but when rebooting, there is an entry on dmesg.boot indicating that /osys is not properly dismounted.

......
WARNING: /osys was not properly dismounted
....
This appears even if I added
umount /osys
in
Code:
/etc/rc.shutdown

Any idea how to tune this ?
 
Well, I only answered how this is technically accomplished.
But I stopped using this because the FreeBSD version of mfs, unlike the one used in OpenBSD, seems to write changes made to the memory disk down to the original image.
Which is not exactly what I wanted. In OpenBSD mfs only COPIES stuff from your original on-disk image into memory disk, but the writes to the memory disk aren't synced back to the image. So you have a faster system only writing to memory and keeping your disk as much read-only as possible.
But FreeBSD version of vnode-backed mfs writes back to the image. Funny idea... whatever.

You can read details in this thread.
 
Back
Top