Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

What are the commands to use in LVM in case I want to:

  1. create a read-only snapshot of a volume;
  2. (do some experiments in the volume);
  3. and then rollback the volume to the snapshot?
share|improve this question
add comment

1 Answer

up vote 10 down vote accepted

I think you are looking for lvconvert --merge. From the man page:

--merge

Merges a snapshot into its origin volume. To check if your kernel supports this feature, look for snapshot-merge in the output of dmsetup targets. If both the origin and snapshot volume are not open the merge will start immediately. Otherwise, the merge will start the first time either the origin or snapshot are activated and both are closed. Merging a snapshot into an origin that cannot be closed, for example a root filesystem, is deferred until the next time the origin volume is activated. When merging starts, the resulting logical volume will have the origin's name, minor number and UUID.
While the merge is in progress, reads or writes to the origin appear as they were directed to the snapshot being merged. When the merge finishes, the merged snapshot is removed. Multiple snapshots may be specified on the commandline or a @tag may be used to specify multiple snapshots be merged to their respective origin.

Assume you have a logical volume vg0/system which contains your / filesystem.

# create a read-only snapshot
lvcreate -pr --snapshot --name system_snapshot vg0/system
# upgrade or something
# if it fails, reboot and do this from a livecd
lvconvert --merge vg0/system_snapshot
# reboot again and you have your old system back

The reboots are only needed because in this scenario you can't unmount the filesystem. If it's not the / fs, unmount is enough.

Keep in mind that the snapshot will deleted after the merge.

share|improve this answer
    
Thanks for the answer! And if one doesn't give the -pr (--permission r) option to lvcreate, will the snapshot be read-only by default? (Does LVM allow writable snapshots at all? If yes, an alternative scenario could be possible, where the temporary experiments wouldn't be visible in the main volume, but would be performed in the temporary writable snapshot.) –  imz -- Ivan Zakharyaschev Aug 22 '11 at 23:29
    
The default is RW. –  stribika Aug 23 '11 at 18:38
2  
You shouldn't do the merge from a live CD , you can issue the command and after reboot it would merge automatically. –  Hanan N. Dec 4 '11 at 10:40
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.