18

I have made an LVM snapshop by

lvcreate --name snap --size 10G -s /dev/vg00/vm

What command should I write if I want to drop the snapshot, and not keep the changes that have happened since the snapshot?

And what command should I write to roll the changes from the snapshot into /dev/vg00/vm ?

5 Answers 5

17

to drop snapshot use:

lvremove group/snap-name

to merge snapshot use:

lvconvert --merge group/snap-name

Though merging will be deferred until the orgin and snapshot volumes are unmounted. You may need to update kernel (>=2.6.33) and lvm tools to have support for merging.

3
  • Does this mean that you can run lvconvert --merge ... then reboot in order to rewind the volume?
    – Hubro
    Mar 25, 2020 at 14:05
  • @Hubro Exactly. See wiki.archlinux.org/title/LVM#Snapshots for more information
    – mxmehl
    Jan 7, 2022 at 13:57
  • I've just lost data following this advice because LVM terminology is backwards IMO. Correct me if I'm wrong, by when LVM says "drop a snapshot", it means merging the changes from the COW volume into the origin volume, and "merge a snapshot" means reverting the origin volume to the state when the snapshot was made, effectively dropping the changes stored in the COW volume.
    – tgirod
    Jul 7, 2023 at 7:08
3

Looks like this has been asked before:

Linux LVM snapshot commit or revert?

As well as:

http://www.jonnor.com/2010/02/lvm-snapshot-merging-avaliable/

1
  • Ok, so lvremove accepts the changes in the snapshot. So far so good =)
    – Sandra
    Sep 27, 2010 at 23:18
3

OK, first of all: the grand old LVM1 supported only read-only snapshots. In that case the modifications were copied to original image after unmounting the snapshot. LVM2 provides support for read-write snapshots, allowing you to do funkier stuff with virtual machine images and stuff like that.

Novell has a very niece piece of documentation about the concept of using LVM for rolling back a failed OS update. Take a look at that article, it provides all the bits and pieces you need for your case.

1
  • So there isn't a command to drop the snapshot without accepting the changes?
    – Sandra
    Sep 27, 2010 at 23:20
2

you can use lvremove command to remove the old snapshot files:

lvremove /dev/vg_brcvhost1/snap this will ask you to remove a sanpshot persent in the your LV.

other commands are also there for managing a LVM based VM setup.

you can find the details commands in the link below: http://linux.math.tifr.res.in/HOWTO/LVM-HOWTO/snapshots_backup.html

and the below link may also be usefull: http://dentarg.it64.com/content/lvm-based-backup-virtual-machines

1

I've just lost data following the selected answer to this question, so I'm posting this to clarify. Please correct me if I'm wrong.

IMO, LVM terminology is backwards. For reference redhat's documentation to LVM snapshot

When LVM says "drop a snapshot", it means merging the changes from the COW volume into the origin volume.

When LVM says "merge a snapshot", it means reverting the origin volume to the state when the snapshot was made, effectively dropping the changes stored in the COW volume.

I find this VERY counterintuitive, lost 43h of data because of that. Don't do the same mistake I did !

EDIT: OK now I understand my mistake. From the documentation:

When you modify the original volume (the origin) after you take a snapshot, the snapshot feature makes a copy of the modified data area as it was prior to the change so that it can reconstruct the state of the volume. When you create a snapshot, full read and write access to the origin stays possible.

I wrongly assumed that LVM operated by freezing the origin partition and mounting the snapshot as an overlay to store the modifications, but this sentence makes it clear it does not work that way.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .