Decrease the size of the local-lvm partition in Proxmox

From Levy

Introduction

When installing Proxmox on a server the size of the LVM's for your root filesystem and local-lvm are determined automatically by the installer. There's nothing you can do about that. In this case I had a server with only a very small disk (15GB) which is fine, since the VM's are on remote storage anyway. But the automatic size left me with a root partition for the OS of only 5GB. And after some kernel updates this was getting too small.

Since I don't really use the local-lvm on this server I decided to decrease that in size and add it to the root filesystem.

Warnings

Decreasing the size of the local-lvm filesystem comes actually down to removing it and recreating it in a smaller size. So before attemting this procedure make sure it's empty or you will loose all data on it.

Decreasing the size of local-lvm

As mentioned in the warmings section, the only way to decrease the size of the local-lvm filesystem can only be accomplished by removing and then recreating it. This is because the logical volume used for this pve/data is a thin pool volume. It's impossible to shrink these.

Log in as root to your Proxmox server and use the lvs command to check your current LVMs:

root@nilou:~# lvs
  LV   VG  Attr       LSize Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  data pve twi-a-tz-- 5.41g             0.00   1.57
  root pve -wi-ao---- 5.25g
  swap pve -wi-ao---- 1.75g

As you can see the root filesystem is only 5.25 GB which is way too small. First we remove the data volume:

root@nilou:~# lvremove /dev/pve/data
Do you really want to remove active logical volume pve/data? [y/n]: y
 Logical volume "data" successfully removed

Then we create a new, smaller volume for data and convert it to a thin pool:

root@nilou:~# lvcreate -L 2G -n data pve
  Logical volume "data" created.
root@nilou:~# lvconvert --type thin-pool pve/data
  Thin pool volume with chunk size 64.00 KiB can address at most 15.81 TiB of data.
  WARNING: Converting pve/data to thin pool's data volume with metadata wiping.
  THIS WILL DESTROY CONTENT OF LOGICAL VOLUME (filesystem etc.)
Do you really want to convert pve/data? [y/n]: y
  Converted pve/data to thin pool.

Then we tell Proxmox to forget about the current local-lvm storage and add it again:

root@nilou:~# pvesm remove local-lvm
root@nilou:~# pvesm add lvmthin local-lvm -thinpool data -vgname pve -content rootdir,images

As we can see, there's now room free in the volume group to expand the root filesystem:

root@nilou:~# vgs
  VG  #PV #LV #SN Attr   VSize  VFree
  pve   1   3   0 wz--n- 14.41g 5.40g

Finally it's time to expand the root filesystem:

root@nilou:~# lvextend -L +2g /dev/pve/root
  Size of logical volume pve/root changed from 5.25 GiB (1344 extents) to 7.25 GiB (1856 extents).
  Logical volume pve/root successfully resized.
root@nilou:~# xfs_growfs /
meta-data=/dev/mapper/pve-root   isize=512    agcount=6, agsize=229376 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=1, sparse=1, rmapbt=0
         =                       reflink=1    bigtime=0
data     =                       bsize=4096   blocks=1376256, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0, ftype=1
log      =internal log           bsize=4096   blocks=2560, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 1376256 to 1900544
root@nilou:~# lvs
  LV   VG  Attr       LSize Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  data pve twi-a-tz-- 2.00g             0.00   11.04
  root pve -wi-ao---- 7.25g
  swap pve -wi-ao---- 1.75g