Wednesday, February 26, 2020

Converting LVM to LVM Thin so Proxmox PVE will support Snapshot Backup and Thin Provisioning

I have been using Proxmox PVE since version 2.x.  Back in Proxmox version 2 and 3, a regular LVM partition with enough free space in its LVM Volume Group would be enough for Proxmox Backup Snapshot function to work.  However starting Proxmox version 5 you have to use LVM Thin (thin provisioning) in order to make backup with snapshot to work and support over provisioning.

Backup with snapshot is important because it allows the VM or CT to continue working during the backup process (uninterrupted).  This is crucial and makes backup seamless and effortless without downtime.

Over provisioning allow you to create VM and CT without actually taking up the storage size specified in the VM or CT.  For example, lets say you create a CT with 100GB storage, however the CT actually only use 20GB, with thin provisioning the LVM Thin will only take up 20GB instead of 100GB therefore allowing you to assign / provision more storage and you actually physically have capacity of.  Of course if all your CT / VM actually takes up 100% of their capacity and you over provision all your CT / VM you will run out of space!

Here are the steps I have done to convert my existing partition (/dev/md0) from typical ext4 mounted as a directory to my Proxmox (which currently does not work for backup with snapshot) and converting it to LVM Thin:


STEP 1 - Move all your VM and CT

First you need to empty and remove all your VM and CT if the partition you are working on is being used by some VM / CT.  I simply just STOP them and back them up one at a time and restore at a different proxmox server.   If you backup and restore, you will then still have to remove all the VM and CT in the hardware node you are working on.  The point here is, you have to empty the partition we will be converting to LVM Thin (because the data will be erased during the process).


STEP 2 - UNMOUNT THE PARTITION

Unmount the partition using the command:

umount /mnt/md0

in case the above fails you can try using 'force':

umount -f /mnt/md0


STEP 3 - CHANGE PARTITION TYPE TO LVM

See the list of devices recognize by fdisk and find the device ID you are working on:

fdisk -l

My device ID is /dev/md127

Next, I will use fdisk to create a new single partition (100% size) and change its type to LVM

fdisk /dev/md127

Type command 'n' to create new partition, select default options (press enter a few times to select default) until the partition has been created.

Type command 't' to change its type, type '8e' to select Linux LVM

Type command 'w' to commit changes.


STEP 4 - CREATE PHYSICAL VOLUME AND VOLUME GROUP

Use fdisk again to find the newly created LVM partition:

fdisk -l

My new device ID for the partition is /dev/md127p1

Create physical volume first:

pvcreate /dev/md127p1

Check to make sure physical volume has been created:

pvdisplay



Then create volume group, I would like to call my volume group local_md0

vgcreate local_md0 /dev/md127p1

Check to make sure volume group has been created:



STEP 5 - CREATE LOGICAL VOLUME WITH THIN OPTION

The lvcreate command below will create a THIN logical volume because of the -T option and will leave 5% of the volume group free.  The 5% is enough in my case because this is a 2TB partition.  You only need to reserve enough space for snapshot changes during backup operation.  Meaning lets say your backup takes 30 min, during that 30 min time, is your 5% free space enough to record all the changes that may happen within that 30 min window?

lvcreate -T -n local_md0 -l 95%FREE local_md0


STEP 6 - ADD STORAGE IN PROMOX PVE AS LVM THIN


Click on Datacenter > Storage > Add




STEP 7 - CONFIRM IT HAS BEEN ADDED AS STORAGE






Congratulations!  You know have LVM Thin which means you can do Backup with Snapshot and your VM and CT can be over provisioned!


1 comment: