* [linux-lvm] Snapshots
@ 2009-09-10 23:25 jonr
2009-09-11 9:14 ` Peter Keller
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: jonr @ 2009-09-10 23:25 UTC (permalink / raw)
To: LVM general discussion and development
Hello List,
I don't get it!
I have a xen system that has a DomU of FC11 with a 20GB LV for the
disk. I created a snapshot using this command:
lvcreate -L +10G -s -n s_cgate-be1 /dev/xenvg/cgate-be1
This is the output of an 'lvdisplay' of the snapshot LV:
lvdisplay /dev/xenvg/s_cgate-be1
--- Logical volume ---
LV Name /dev/xenvg/s_cgate-be1
VG Name xenvg
LV UUID 7c1kEs-xYoO-Qxem-2E2M-hlee-pc4Q-zm6TZ5
LV Write Access read/write
LV snapshot status active destination for /dev/xenvg/cgate-be1
LV Status available
# open 2
LV Size 20.00 GB
Current LE 5120
COW-table size 10.00 GB
COW-table LE 2560
Allocated to snapshot 0.11%
Snapshot chunk size 4.00 KB
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:15
I then shutdown the DomU and pointed the 'Disk...' line in the config
file for the DomU to the snapshot. It boots.
OK, I must be missing the simple answer because I cannot seem to grasp
the concept of snapshots.
1. How can I have a 20GB LV as a disk and the snapshot be 10GB and
boot the entire OS?
2. Can I create a DomU and then snapshot the LV and use the snapshot
to create other DomU's?
3. If 2 is yes, would I want to continue using the snapshot as the
disk or is there something else that should be done, i.e. dd the drive
to a new LV?
In the 'lvdisplay' of the snapshot I have these extra lines:
LV snapshot status active destination for /dev/xenvg/cgate-be1
# open 2
COW-table size 10.00 GB
COW-table LE 2560
Allocated to snapshot 0.11%
Snapshot chunk size 4.00 KB
4. Does the 0.11% mean that the 10GB snapshot file is only using .11%
of the 10GB LV?
If there is a good doc out there explaining all of this could someone
just post a link. I don't mind reading but am not getting the answers
to the above. I have found lots of docs explaining how to do it but
nothing going much further than that.
Thanks for any help,
Jon
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [linux-lvm] Snapshots
2009-09-10 23:25 [linux-lvm] Snapshots jonr
@ 2009-09-11 9:14 ` Peter Keller
2009-09-11 13:39 ` André Gillibert
2009-09-11 13:44 ` [linux-lvm] Snapshots Mike Snitzer
2 siblings, 0 replies; 5+ messages in thread
From: Peter Keller @ 2009-09-11 9:14 UTC (permalink / raw)
To: LVM general discussion and development
Hi Jon,
You seem to be right that there isn't much written down about how snapshots
work under the bonnet in the LVM context, but the same ideas have been used
for other snapshot implementations for years. You could try searching for
filesystem snapshot technology in general, rather than anything
LVM-specific. For example, this article explains some of the basic concepts:
http://www.ibm.com/developerworks/tivoli/library/t-snaptsm1/index.html
LVM uses the copy-on-write method (this is what "COW" stands for).
On Thu, 10 Sep 2009, jonr@destar.net wrote:
> Hello List,
>
> I don't get it!
>
> I have a xen system that has a DomU of FC11 with a 20GB LV for the disk. I
> created a snapshot using this command:
>
> lvcreate -L +10G -s -n s_cgate-be1 /dev/xenvg/cgate-be1
>
> This is the output of an 'lvdisplay' of the snapshot LV:
>
> lvdisplay /dev/xenvg/s_cgate-be1
> --- Logical volume ---
> LV Name /dev/xenvg/s_cgate-be1
> VG Name xenvg
> LV UUID 7c1kEs-xYoO-Qxem-2E2M-hlee-pc4Q-zm6TZ5
> LV Write Access read/write
> LV snapshot status active destination for /dev/xenvg/cgate-be1
> LV Status available
> # open 2
> LV Size 20.00 GB
> Current LE 5120
> COW-table size 10.00 GB
> COW-table LE 2560
> Allocated to snapshot 0.11%
> Snapshot chunk size 4.00 KB
> Segments 1
> Allocation inherit
> Read ahead sectors auto
> - currently set to 256
> Block device 253:15
>
> I then shutdown the DomU and pointed the 'Disk...' line in the config file
> for the DomU to the snapshot. It boots.
>
> OK, I must be missing the simple answer because I cannot seem to grasp the
> concept of snapshots.
>
>
> 1. How can I have a 20GB LV as a disk and the snapshot be 10GB and boot the
> entire OS?
Because the snapshot only stores copies of the disk blocks that have been
modified on the original volume since the snapshot was taken (the blocks
that would otherwise be overwritten if you hadn't created the snapshot).
When you read from the snapshot, LVM uses never-modified blocks from the
original volume and pre-modification copies of blocks from the snapshot as
needed.
If the original volume became corrupt, the snapshot would also be unusable.
> 2. Can I create a DomU and then snapshot the LV and use the snapshot to
> create other DomU's?
Yes - there are articles around about how to do this. If you intend to run
the DomU's on the same network, you should boot the copies into single-user
mode initially to modify their network identities so that they don't
conflict with each other. (Maybe you can find some other way of doing this
without booting the DomU's: I know that you can do this with VMWare, at
least for Linux guest OS's.)
> 3. If 2 is yes, would I want to continue using the snapshot as the disk or is
> there something else that should be done, i.e. dd the drive to a new LV?
>
> In the 'lvdisplay' of the snapshot I have these extra lines:
> LV snapshot status active destination for /dev/xenvg/cgate-be1
> # open 2
> COW-table size 10.00 GB
> COW-table LE 2560
> Allocated to snapshot 0.11%
> Snapshot chunk size 4.00 KB
You can continue use the snapshot in principle, although you might like to
make the snapshot the same size as the original volume in that case to make
sure that it never fills up. In your example, when the accumulated changes
on the original volume since the snapshot was taken reach 10Gb, the snapshot
will be full and go invalid and you won't be able to use it.
If your aim is to have a single starting point to create more than one DomU,
you should copy the data out and keep it safe somewhere. You can then use
that copy to create further copies as needed. Personally, I would only boot
up the first copy (or the snapshot) to keep the OS up to date (which will
save you having to update every copy that you make from it).
> 4. Does the 0.11% mean that the 10GB snapshot file is only using .11% of the
> 10GB LV?
Yes, that's right.
> If there is a good doc out there explaining all of this could someone just
> post a link. I don't mind reading but am not getting the answers to the
> above. I have found lots of docs explaining how to do it but nothing going
> much further than that.
>
> Thanks for any help,
Have fun,
Peter.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [linux-lvm] Snapshots
2009-09-10 23:25 [linux-lvm] Snapshots jonr
2009-09-11 9:14 ` Peter Keller
@ 2009-09-11 13:39 ` André Gillibert
2009-09-11 13:44 ` [linux-lvm] Snapshots Mike Snitzer
2 siblings, 0 replies; 5+ messages in thread
From: André Gillibert @ 2009-09-11 13:39 UTC (permalink / raw)
To: linux-lvm
jonr@destar.net wrote:
> Hello List,
>
> I don't get it!
>
> I have a xen system that has a DomU of FC11 with a 20GB LV for the
> disk. I created a snapshot using this command:
>
> lvcreate -L +10G -s -n s_cgate-be1 /dev/xenvg/cgate-be1
>
> This is the output of an 'lvdisplay' of the snapshot LV:
>
> lvdisplay /dev/xenvg/s_cgate-be1
> --- Logical volume ---
> LV Name /dev/xenvg/s_cgate-be1
> VG Name xenvg
> LV UUID 7c1kEs-xYoO-Qxem-2E2M-hlee-pc4Q-zm6TZ5
> LV Write Access read/write
> LV snapshot status active destination for /dev/xenvg/cgate-be1
> LV Status available
> # open 2
> LV Size 20.00 GB
> Current LE 5120
> COW-table size 10.00 GB
> COW-table LE 2560
> Allocated to snapshot 0.11%
> Snapshot chunk size 4.00 KB
> Segments 1
> Allocation inherit
> Read ahead sectors auto
> - currently set to 256
> Block device 253:15
>
> I then shutdown the DomU and pointed the 'Disk...' line in the config
> file for the DomU to the snapshot. It boots.
>
> OK, I must be missing the simple answer because I cannot seem to grasp
> the concept of snapshots.
>
>
> 1. How can I have a 20GB LV as a disk and the snapshot be 10GB and
> boot the entire OS?
>
That's because the snapshot uses these 10GB as a "COW-table". i.e. A "Copy On Write table".
When the snapshot is first created, no copy is performed. All the blocks of the snapshot are identical to the blocks of the original LV. Accessing the snapshot or original LV access the same block.
Then, if you modify some data in either the original LV or the snapshot LV, an "exception list" listing data chunks that are different in the snapshot LV than in the original LV, is created.
When reading a snapshot LV block, LVM first looks at the "exception list". If the chunk accessed is the in the "exception list", the chunk data in the exception list is returned. If the chunk isn't in the exception list, the chunk data is extracted from the original volume.
When writing a snapshot LV block, it's written in a chunk of the exception list, either existing, or created at this time.
When writing a chunk in the original volume, it's first copied in the "exception list", and then, modified in the original volume.
The chunk size is specified with the --chunksize parameter (4k to 512k) to lvcreate(8), when creating a snapshot.
If ever you've so many exceptions that the snapshot volume overflows, it's dropped.
Consequently, you must take care of allocating enough space in snapshots. This space is the size of the data that may be modified in the snapshot or original volume.
Snapshots are fine for short lived snapshots (e.g. when backing up) but aren't designed to cope with heavy modifications of the entire file system.
> 2. Can I create a DomU and then snapshot the LV and use the snapshot
> to create other DomU's?
I'm not a Xen user. Sorry, I don't know.
Here, Google may help:
<http://www.google.com/search?rls=en&hl=en&source=hp&q=xen+device+mapper>
>
> 3. If 2 is yes, would I want to continue using the snapshot as the
> disk or is there something else that should be done, i.e. dd the drive
> to a new LV?
>
> In the 'lvdisplay' of the snapshot I have these extra lines:
> LV snapshot status active destination for /dev/xenvg/cgate-be1
> # open 2
> COW-table size 10.00 GB
> COW-table LE 2560
> Allocated to snapshot 0.11%
> Snapshot chunk size 4.00 KB
>
> 4. Does the 0.11% mean that the 10GB snapshot file is only using .11%
> of the 10GB LV?
>
It means that the internal LVM data structure + the exception chunks are using 0.11% of the 10GB "COW-table partition".
Create snapshot, dd(1), delete snapshot is a way to create a "forked" copy of the original volume.
That may, or may not be what you want. If you intend to share much data with the original volume, a simple snapshot may be the way to go. If a small or near-zero amount of data is to be shared, in that case, snapshotting won't save data space, but may incur performance penalties (see <http://www.nikhef.nl/~dennisvd/lvmcrap.html>), and so, my advice is to create snapshot, dd(1), and delete snapshot.
I hope it helps.
--
André Gillibert
^ permalink raw reply [flat|nested] 5+ messages in thread
* [linux-lvm] Re: Snapshots
2009-09-10 23:25 [linux-lvm] Snapshots jonr
2009-09-11 9:14 ` Peter Keller
2009-09-11 13:39 ` André Gillibert
@ 2009-09-11 13:44 ` Mike Snitzer
2 siblings, 0 replies; 5+ messages in thread
From: Mike Snitzer @ 2009-09-11 13:44 UTC (permalink / raw)
To: LVM general discussion and development
On Thu, Sep 10 2009 at 7:25pm -0400,
jonr@destar.net <jonr@destar.net> wrote:
> Hello List,
>
> I don't get it!
The snapshot diagrams from Alasdair's old FOSDEM slides should help you
visualize the kernel layers involved beneath LVM (e.g. dm-snapshot):
http://people.redhat.com/agk/talks/FOSDEM_2005/
Starting with the "Snapshot" slide through "Two Snapshots". Without
having text associated with each slide it may be too terse for you
but I recommend having a look...
> 1. How can I have a 20GB LV as a disk and the snapshot be 10GB and boot
> the entire OS?
The snapshot LV is backed by the "COW" in the diagrams above. If you
wanted to accommodate _every_ block changing in the origin LV (copied out
to the snapshot LV) you'd have to size the snapshot LV to be a bit
larger than the origin LV (snapshot metadata has some small overhead).
Sizing your snapshot LV is all about how you intend to use the
snapshot. E.g. what is the expected rate of change to the origin LV
while you intend to have the snapshot active? If you'll be changing the
origin extensively then you want to use a larger snapshot LV.
> 2. Can I create a DomU and then snapshot the LV and use the snapshot to
> create other DomU's?
Sure, but I'd imagine you'd have to change some unique identifiers in
the DomU so that it can co-exist with the original. These changes would
get written through the "snapshot" layer in the kernel and directly out
to the COW (would never touch the origin LV; not to be confused with
"origin" layer :).
> 3. If 2 is yes, would I want to continue using the snapshot as the disk
> or is there something else that should be done, i.e. dd the drive to a
> new LV?
Depends how permanent you need the new DomU to be. And how much
simultaneous change you expect to the original DomU.
The emerging "multi-snapshot" implementation that Mikulas Patocka is
actively working on is really geared toward this Xen DomU snapshot
use-case. Mikulas has posted his patches to dm-devel but it'll be a bit
longer before they are all merged into an upstream Linux kernel.
Mike
^ permalink raw reply [flat|nested] 5+ messages in thread
* [linux-lvm] Re: Snapshots
2009-09-17 14:24 [linux-lvm] Snapshots Jon Hardcastle
@ 2009-09-17 14:32 ` Mike Snitzer
0 siblings, 0 replies; 5+ messages in thread
From: Mike Snitzer @ 2009-09-17 14:32 UTC (permalink / raw)
To: Jon, LVM general discussion and development
On Thu, Sep 17 2009 at 10:24am -0400,
Jon Hardcastle <jd_hardcastle@yahoo.com> wrote:
> Hi,
>
> Do I need some free extents to create a READ ONLY snapshot? I dont
> have free extents but require a read-only snapshot before doing an
> upgrade.
Yes, even though you intend to only read from the snapshot the upgrade
will cause data to be copied out from the origin to the snapshot. So
you definitely need some free extents.
Mike
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2009-09-17 14:32 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-09-10 23:25 [linux-lvm] Snapshots jonr
2009-09-11 9:14 ` Peter Keller
2009-09-11 13:39 ` André Gillibert
2009-09-11 13:44 ` [linux-lvm] Snapshots Mike Snitzer
-- strict thread matches above, loose matches on Subject: below --
2009-09-17 14:24 [linux-lvm] Snapshots Jon Hardcastle
2009-09-17 14:32 ` [linux-lvm] Snapshots Mike Snitzer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).