Skip to content

LVM

Install lvm2

apt install lvm2

Create lv

pvcreate /dev/sda99
vgcreate vg1 /dev/sda99
lvcreate -L 8gb -n NEWLV vg1
lvs

mkfs.ext4 -m 0 -L backupspace /dev/vg1/NEWLV

Remove lv

lvremove seagate2tb_crypt_vg/oas-local-storage

Sizes

Create new lv with 100% of free remaining vg disk space

lvcreate -l 100%FREE -n <lv-name> vg1

Remove volume group mapping after removing physical disk

https://serverfault.com/questions/421776/removing-vg-and-lv-after-physical-drive-has-been-removed

umount /mnt
dmsetup status
dmsetup remove vg1-media
vgs

Snapshots

Create Snapshot

Size: "The snapshot does not need the same amount of storage the origin has. In a typical scenario, 15-20% might be enough."

lvcreate -L4G -s -n dbbackup /dev/ops/databases
# create read-only snapshot (-pr)
VM=NAME; lvcreate -pr -L2400M -s -n $VM-root-dist-upgrade /dev/viper_vg0/$VM-root

Revert to snapshot

`--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. lvconvert --merge viper_vg0/mole-root-dist-upgrade Can't merge over open origin volume Merging of snapshot mole-root-dist-upgrade will start next activation. http://www.thegoldfish.org/2011/09/reverting-to-a-previous-snapshot-using-linux-lvm/

dmsetup remove viper_vg0-mole--rootp1
dmsetup remove viper_vg0-mole--rootp2
lvchange -an viper_vg0/mole-root
lvchange -ay viper_vg0/mole-root
virsh start mole

Delete snapshot

$ lvremove viper_vg0/mole-root
Logical volume "mole-root-dist-upgrade" successfully removed
Do you really want to remove active logical volume mole-root? [y/n]: n
Logical volume mole-root not removed