Memory disk "a la mfsroot"?
Pierre-Luc Drouin
pldrouin at pldrouin.net
Thu Feb 11 20:15:52 UTC 2010
Matthew Seaman wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> On 11/02/2010 17:10, Pierre-Luc Drouin wrote:
>
>>> Actually, I was thinking more along the lines of mounting a .iso as a
>>> cd9660 filesystem. Which won't muck up the underlying .iso, but only
>>> because it's read-only. You could mount a FFS image read-only in
>>> exactly the same way -- I think there's a 'last mounted on' field in the
>>> backing file image that will be updated if the it is writable (even if
>>> the fs itself is mounted ro) but that's not the right answer either.
>>>
>>> Basically, you're going to have to mount and initialise as two separate
>>> operations as far as I can see.
>>>
>>>
>> By this do you mean that I would need to copy the whole content of the
>> read-only filesystem to the memory disk?
>>
>
> Yes.
>
>
>> I looked at the man page for mount_unionfs and there is a big warning
>> saying that it is a bad idea to use it, so I guess I will pass on this
>> solution...
>>
>
> Ah -- that warning is probably a bit more alarming than it really
> needs to be nowadays. unionfs can be used pretty effectively for many
> purposes. Try it and see what happens is the best policy.
>
>
>> What I am trying to do basically is to mount a filesystem from a CD but
>> I want to use a memory disk to allow write operations. I would basically
>> want the filesystem to behave like a regular read-write filesystem, but
>> not have to copy everything into a memory disk. What does "mfs_root" do
>> exactly in the official FreeBSD boot CDs? Does it copy the content of
>> mfsroot.gz into a memory disk? That filesystem is so small that I guess
>> it can be copied without any problem...
>>
>
> mfs_root does exactly that: it creates a memory based filesystem and
> then expands a tarball of the system into it.
>
> One approach you might consider is mounting your CD image read-only as
> per usual, but creating memory-based /tmp and /var partitions[*]. Most
> of the usual root and /usr filesystems don't need to be read-write at
> all. There are only a few special locations that do and those will need
> special handling. You will need to initialise your memory-backed /var
> partiton by expanding a skeleton structure into it, but that's going to
> be pretty small really. You will also need to make provision for editing
> various files under /etc -- you might be able to create a /var/etc and
> replace the real files in /etc with symlinks to copies in /var/etc.
> Possibly. Or you could just have /var/etc nullfs mounted on top of /etc.
>
> I've read reports from people setting up such things -- a while back
> now, but as far as I recall they were on the whole successful.
>
> Cheers,
>
> Matthew
>
> [*] There are already scripts to do this sort of thing within the base
> system, although primarily aimed at diskless systems.
>
> - --
> Dr Matthew J Seaman MA, D.Phil. 7 Priory Courtyard
> Flat 3
> PGP: http://www.infracaninophile.co.uk/pgpkey Ramsgate
> Kent, CT11 9PW
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG/MacGPG2 v2.0.14 (Darwin)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
>
> iEYEARECAAYFAkt0WDQACgkQ8Mjk52CukIyWgwCeMHjE7VsdHx5HLGQw75SplJ9v
> 6zUAni7BZsLYsp2qGSFUUMmkjpVMYomt
> =4SwV
> -----END PGP SIGNATURE-----
>
Thanks,
so I think I will do the following:
1-Create a mfsroot.gz with empty /usr, /var, /boot/kernel and
/boot/modules directories and have it mounted through loader.conf
2-Create a rc.d script that is called immediately after rc.d/conf and
that does the following:
-Mount /usr using mdmfs and an independent backing file on the CD (so
this way the whole content of /usr would not be loaded into RAM)
-Create a 500MB memory disk and mount it in /memdisk
-Create /memdisk/{var,tmp,root,home,usr}
-mount_nullfs /memdisk/var and /memdisk/tmp on /var and /tmp respectively
-copy the content of /root and /home (i.e. just a few config files) to
their respective directories in /memdisk
-mount_nulls /memdisk/root and /memdisk/home on /root and /home
respectively
-mount_unionfs /memdisk/usr over /usr
3-use populate_var="YES" in rc.conf to automatically populate the /var
directory
So using this I would have a read-write file system without loading the
whole content of /usr into RAM, I would minimize memory usage by
regrouping all the writable directories into a single memory disk and I
would also minimize the amount of data that is copied from the CD to the
memory. Does it sound like a good plan?
I read something about a limit of 45MB for mfsroot.gz to prevent kernel
crashing. Have you ever heard about this?
Thanks!
More information about the freebsd-questions
mailing list