A few technical items on UFS2 and snapshots...

Oliver Fromme olli at lurza.secnetix.de
Mon Jun 28 10:58:35 PDT 2004


Joe Schmoe <non_secure at yahoo.com> wrote:
 > Oliver Fromme <olli at lurza.secnetix.de> wrote:
 > > Joe Schmoe <non_secure at yahoo.com> wrote:
 > > > 1. Is it dangerous to mount all 20 possible
 > > > filesystem snapshots and
 > > > _leave them mounted_ to use at any time ?
 > > 
 > > I don't think there is any danger, except that you
 > > will run
 > > out of disk space sooner or later.
 > 
 > Every snapshot I have taken so far takes up zero space
 > on the drive, or at least that is what `df` is telling
 > me ...

Well, right after you have taken the snapshot, it doesn't
require any additional space, because it contains just the
same data as the original filesystem.  Similar to a hard-
link which doesn't take any addition disk space either.

But as soon as you start modifying the filesystem _after_
you have taken the snapshot, the snapshot will begin to
take up space on its own.  For example, when you delete
a file, then its space will not actually be freed, but
taken over by the snapshot, because it still has to exist
in the snapshot -- you will not actually free any physical
space.  Remember that the snapshot is supposed to contain
the data from the time when it was created.

Similar things happen when you modify a file:  When you,
say, change a few bytes in a file, then the disk block
with the _old_ contents is copied and given to the snap-
shot -- then the modification is written to the original
disk block.

That mechanism is called copy-on-write.  It means that your
snapshot's space requirement is growing all the time.
Removing files does not free any space, and modifying files
in fact reduces the free space, even if your modification
don't actually increase the size of the file.

 > > > What about
 > > > automatically mounting all 20 snapshots at boot
 > > > time ?
 > > 
 > > Sorry, I fail to see what exactly you're trying to
 > > achieve.
 > > Why would you want to do that?
 > 
 > I dunno - just to have all the snapshots mounted so
 > that if I want to access one, I don't have to take the
 > time to mount it up.  I'm just lazy, I guess ... so
 > there would be no ill effects of doing this ?

No -- except, as I said, you'll run out of disk space,
sooner or later.

Under normal circumstances snapshots don't live for an
extended period of time.  Typical uses include:

 - Background fsck.  This is done automatically during boot
   without you having to do anything.

 - Secure dump.  You can take a snapshot and them dump it,
   which is better than dumping a live filesystem.

 - Short term backup.  You can set up a cron which creates
   and removes (i.e. "rotates") snapshots in certain inter-
   vals, e.g. once per hour.  This can protect against
   accidental "rm" commands -- just copy the lost file back
   from the most recent snapshot.

However, I fail to see why you would want to make 20 fixed
snapshots, automatically mount them during boot and keep
those same snapshots mounted forever.

 > > > 2. Related to the first question, it seems like I
 > > > am getting space
 > > > out of nowher e ... that is, if I fill up a
 > > > drive, then make a
 > > > snapshot, then erase the drive and fill it again,
 > > 
 > > You cannot fill it up again, because the snapshot
 > > still
 > > takes up all the space.  When you fill the drive and
 > > make
 > > a snapshot, erasing the drive will not free any
 > > space.
 > 
 > Is this really true ?

Yes.  See above.

 > Where did you read this ?

Uhm, I think I read it 10 years ago in the manual of a
NetApp Filer.  :-)   FreeBSD's snapshots work very similar
to those of the NetApps.

 > if the snapshot files all take
 > up the same amount of space as the filesystem itself,

It does't.  First it takes zero space.  When modifying the
original filesystem, the space of the snapshot grows.

 > but `df` does not show an increase in space when I
 > make a snapshot, how do I tell what is _really_ going
 > on ?

"df" displays the current size of the snapshot (which is
zero in the beginning) and the total size of the original
filesystem, which includes any snapshots.

 > > > 3. When I mount a snapshot, as described in the
 > > > man page, but then
 > > > later mount - uw the snapshot ( to make that a
 > > > writeable mount) and,
 > > > say, touch a file or create a file in the mounted
 > > > snapshot ... what
 > > > exactly am I doing ?
 > > 
 > > You're getting EPERM ("operation not permitted"),
 > > because
 > > snapshots are always read-only.
 > 
 > No, I'm not.  Re-read the question - I am saying that
 > after I mount the snapshot, I then remount it with
 > -uw, making it writeable (with `mount -uw`), and then
 > I can _successfully_ touch files inside that snapshot.

Have you actually tried that?  And did the touched file
appear within the snapshot?  I don't think so.

Note that you might be able to remount the snapshot with
-uw, but it doesn't actually change anything.  You still
cannot write to it.

You can also mount a CD-ROM (cd9660) read/write -- and
yes, I have tried this.  ;-)  You don't get an error,
and "mount" displays it to be mounted read/write.  But
you still cannot write to it:  First, for the obvious
reason that a CD-ROM is physically non-writable.  Second,
because FreeBSD's cd9660 filesystem does not support
write operations.

I guess it it very similar with snapshots:  You might be
able to mount them read/write, but that doesn't mean that
you can really successfully write to them.

 > SO what exactly am I doing then ?  Have I ruined the
 > snapshot ?  Can it still be used ?

It seem you have not actually tried it, otherwise you would
not ask those questions.  :-)

Best regards
   Oliver

PS:  Also see Robert Watson's detailed reply (which I've
only noticed after I had written mine ...)

-- 
Oliver Fromme, secnetix GmbH & Co KG, Oettingenstr. 2, 80538 München
Any opinions expressed in this message may be personal to the author
and may not necessarily reflect the opinions of secnetix in any way.

"A language that doesn't have everything is actually easier
to program in than some that do."
        -- Dennis M. Ritchie


More information about the freebsd-hackers mailing list