[SOLVED] Automated creation of LVM Thin Storage

sygibson

Member
Mar 25, 2020
6
1
23
51
I am building automation to spin up Proxmox VE servers. This means I need to do everything via a CLI / Script methodology.

I have been fighting this one for about 4 or 5 hours today. My goal is to take a single full disk, and convert it to an LVM Thin storage target for VMs. I can do this with ease via the web GUI, but am stumped on how to replicate it at the command line. I've read at least a dozen different postings that have various recipes on how to try to tackle this unsuccessfully ... but nothing I've been able to find that does it successfully. Most of the folks end up with "just use the GUI"...

My attempt:

sgdisk -N 1 /dev/sdc pvcreate --metadatasize 250k -y -ff /dev/sdc1 vgcreate vmdata /dev/sdc1 pvesm add lvmthin vmdata -vgname vmdata -thinpool vmdata

This results in a "vmdata" LVM target in the GUI - but it ends up with "0" size available. It does not end up giving me an "LVM Thin" pool target.

Pointers/thoughts/or references that I've missed to successful recipes greatly appreciated.

Thanks,
~~shane
 
Ok ... realized I was missing my LV steps in this - and sorted it out ... here's a shell snippet that seems to work, and tested smoothly with creating 200 VMs on the new "vmdata" thinpool volume:


Bash:
# create a single partition with GPT table on disk /dev/sdc
sgdisk -N 1 /dev/sdc

# Create a Physical Volume (PV) without confirmation and 250K metadatasize
pvcreate --metadatasize 250k -y -ff /dev/sdc1

# Create a volume group named “vmdata” on /dev/sdc1
vgcreate vmdata /dev/sdc1

# create a thin-pool Logical Volume (LV) named "vmdata" on VG "vmdata"
lvcreate -L 38G -n vmdata vmdata
lvconvert -y --type thin-pool vmdata/vmdata

# add the storage in to Proxmox CV as an LVM Thin type named "vmdata"
pvesm add lvmthin vmdata -vgname vmdata -thinpool vmdata
 

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!