Pages

Friday, March 13, 2015

LVM Snapshot example

If your Linux is using LVM (Logical Volume Management) testing out or setting up can be much safer if you take a snapshot of your root partition. Here's a small but helpful example to help you do this quickly.



This quick approach is what I do when testing stuff on my servers. The commands are typed into a terminal (of course).

The steps needed are:

  1. Create a snapshot of root partition
  2. Install - Configure - Test - Evaluate
  3. Revert to snapshot (or not)

Here's how:

Create a snapshot of root partition

  • sudo lvcreate -s -n snap-root -L 10G lvm-vg/root
The above command should give you:
Logical volume "snap-root" created
The snapshot is named: snap-root and is added to the list of Logical Volumes. You can check this by running: sudo lvs (It will also show how much of the 10GB snapshot have been used.)


Install - Configure - Test - Evaluate

Here's where you install and test new software.
You know best what you want to test.
Run: sudo lvs to check how much of the snapshot have been used. If you exceed 100% you will not be able to revert to your initial snapshot.


Revert to snapshot (or not)

After having tested you are left with two possibilities; to keep your changes, or to revert to the state when creating the snapshot.

Make sure your snapshot (snap-root) is not mounted; unmount it if it is.


To revert to snapshot:
  • sudo lvconvert --merge lvm-vg/snap-root
You will be told that the merge will be completed at the next activation. You can do that with partitions you can de-/re-activate, but for the root partition I feel it is safer to reboot:
  • sudo reboot

To keep the changes:
  •  sudo lvremove lvm-vg/snap-root


Now wasn't that simple and easy?


No comments:

Post a Comment