Managing Logical Volumes in Proxmox VE
These days I’m trying to using Proxmox VE as my home server. As I hope to runiing mulitple VMs in order to do some experiments, I need to manage the storage of the VMs.
In Proxmox VE, there are two types of storage: local storage and shared storage. Local storage is the storage that is attached to the host, and shared storage is the storage that is attached to the cluster. Here we will mainly focus on the local storage.
After installing Proxmox VE, we can see the storage management page in the “Datacenter” tab. In this page, we can see the storage that is attached to the host. In my case, I have a 1TB SSD. Proxmox VE will automatically create a storage named “local” with about 10% of the total size of the disk. The rest of the disk is created as a storage named “local-lvm”.
In my case, 100GB is allocated to “local”. “local” is used to store the VMs’ configuration files and other Proxmox VE settings. I think we can make it smaller, maybe down to 20GB so the rest of the disk can be used as a storage for VMs.
Since when you are running PVE, you can extend the /root but not shrink it. So we need to shut it down and login to another Linux system and use the command line to shrink the /root.
sudo lvdisplay
lvreduce --resizefs -L {Target Size}G /dev/pve/root
root@fedora /h/amia# lvreduce --resizefs -L 20G /dev/pve/root
fsck from util-linux 2.38.1
/dev/mapper/pve-root: clean, 49888/59154432 files, 4507888/236588032 blocks
resize2fs 1.46.5 (30-Dec-2021)
Resizing the filesystem on /dev/mapper/pve-root to 5242880 (4k) blocks.
The filesystem on /dev/mapper/pve-root is now 5242880 (4k) blocks long.
Size of logical volume pve/root changed from 902.51 GiB (231043 extents) to 20.00 GiB (5120 extents).
Logical volume pve/root successfully resized.
After that, reboot the machine into PVE, we can see the “local” storage is now 20GB.
Now we hope to remove the “local-lvm” storage and create a new “directory” storage with the rest of the space.
For removing the “local-lvm” storage, we need to unmount it first.
umount /dev/pve/data
lvremove /dev/pve/data
Then, we can check the free storage available in the host.
vgdisplay pve | grep Free
We can see there are 902G free space. We can create a new storage with this space.
lvcreate -l 92482 -n data pve
mkfs.ext4 /dev/pve/data
mkdir /mnt/data
mount /dev/pve/data /mnt/data
And finally we need to modified fstab to mount the storage automatically.
echo "/dev/pve/data /mnt/data ext4 defaults 0 0" >> /etc/fstab
Finally, add the storage in the PVE web interface.
All done!