I’m playing with proxmox right now, and had a need to setup LVM locally on each node. I figure why not script it.. I’ve ended up with this abomination of a script. You probably want to do better, but it’s a start:
set -x;
lvmid=`hostname`_localLVM;
pvcreate /dev/sda;
pvs;
vgcreate vg_$lvmid /dev/sda;
vgs; l
vcreate -n lv_$lvmid -l 100%FREE vg_$lvmid;
lvs;
mkdir -p /local/vg_$lvmid-lv_$lvmid;
mkfs.ext4 /dev/mapper/vg_$lvmid-lv_$lvmid;
echo /dev/mapper/vg_$lvmid-lv_$lvmid /local/vg_$lvmid-lv_$lvmid ext4 defaults 0 0 >> /etc/fstab;
mount /local/vg_$lvmid-lv_$lvmid;
df -h
Or on one line..
set -x;lvmid=`hostname`_localLVM; pvcreate /dev/sda; pvs; vgcreate vg_$lvmid /dev/sda; vgs; lvcreate -n lv_$lvmid -l 100%FREE vg_$lvmid;lvs; mkdir -p /local/vg_$lvmid-lv_$lvmid; mkfs.ext4 /dev/mapper/vg_$lvmid-lv_$lvmid;echo /dev/mapper/vg_$lvmid-lv_$lvmid /local/vg_$lvmid-lv_$lvmid ext4 defaults 0 0 >> /etc/fstab; mount /local/vg_$lvmid-lv_$lvmid; df -h
Hope this helps someone in the future.. maybe me!