I've installed Ubuntu using these options:
- Erase the disk and install Ubuntu
- Encrypt the new Ubuntu installation
- Use LVM
How can I create LVM snapshots, so that I'm able to revert system changes when it's necessary?
lvm
I've installed Ubuntu using these options:
How can I create LVM snapshots, so that I'm able to revert system changes when it's necessary?
Best Answer
Note: all commands should be done from
sudo
First, reduce size of your root volume to make some room for a snapshot volume
fdisk -l
to see name of your device./dev/sda3
in my casecryptsetup luksOpen /dev/sda3 crypt1
to decrypt your volumevgscan --mknodes
to find all volume groupsvgchange -ay
to activate all your volume groupslvreduce -r -L -20G /dev/ubuntu-vg/root
to reduce size of your root volume by 20 Gb. This may take a while (it took ~4 min for me).That space will later be used to create LVM snapshots.
vgs
to see that you actually got 20G of free spacereboot
and remove Live CDCreate a snapshot (i.e., activate "experimentation" mode)
Now whenever you want to do something risky with your system, run the following command
lvcreate -s -n snap -L 20G /dev/ubuntu-vg/root
Note:
/dev/ubuntu-vg/root
is a logical volume that you want to have a snapshot oflvs
to see that the volume has been created The snapshot is active from the moment you runlvcreate
. You can now start experimenting with new things.Scenario #1: You want to revert changes
lvconvert --merge /dev/mapper/ubuntu--vg-snap
reboot
Scenario #2: You want to persist changes
lvremove /dev/mapper/ubuntu--vg-snap
In Conclusion
You basically have to run
lvcreate
to start the process and then either runlvconvert --merge
orlvremove
to end it.Keep in mind that when the snapshot is active, due to Copy-On-Write strategy all the changes are saved to those 20Gb of space (or whatever value you set). One way of checking the remaining capacity is to look at Data% column of
lvs
command.