Howto shrink LVM partitions (Proxmox)
While installing Proxmox, in command line "boot", specify root partition size with 'linux maxroot=02 (for a 2go root).
When installation if finished, partitions look like this :
pve1.jpg
Let's start to shrink it :
First,
- Boot in rescue mode with a debian livecd for exemple.
Code:
vgchange -a y #activate existing lvm
e2fsk -f /dev/pve/data #verify the filesystem on the LV 'data'
- We can now shrink the data LV.
Code:
resize2fs -p /dev/pve/data 2G
lvresize -L 2G /dev/pve/data
pvs
- And now shrink the physical volume. We have to find it's new size :
Code:
pvs #We have PSize and free space PFree.
- Calculate PSIZE - PFREE to have the future pve size required. In my case it is around 11G so I set it a bit more.
Code:
pvresize /dev/sda2 --setphysicalvolumesize 11.5G
We have now a volume like this :
pve2.jpg
Now we can reboot on the proxmox server (and why not finish this using SSH).
On Proxmox console :
Code:
dpkg-reconfigure locales
aptitude update
aptitude install parted
- We will now make available that free space and use it
- First, we reduce sda2 to match the new PV size.
Code:
pvs --units s #write 'PSize': (for me 24 109 056 s)
parted /dev/sda unit s print #write the 'start' sector of the lvm partition : 1 048 640 s
- We will sda2 delete from the partition table and recreate it withthe same 'Start' sector but smaller.
To calculate the new 'End' sector, add the 'Start' sector with 'PSize' in sector and add a safety margin of 131072 sectors (64MB).
24 109 056 s + 1 048 640 s + 131 072 s = 25 288 768 s
!Do not forget the 's' for sector unit in the mkpart command!
Code:
parted /dev/sda rm 2
parted /dev/sda mkpart primary [startSecteur]s [newEndSecteur]s # [startSecteur]s [newEndSecteur]s : 1048640s 25288768 s
parted /dev/sda set 2 lvm on # set lvm on partition
parted /dev/sda print # to verify
We have now an available free space :
pve3.jpg
- Now we can easily create a new partition from the free space (with cfdisk for exemple)
Bookmarks