How to Shrink an LVM Volume on Linux

Argomenti vari di carattere sistemistico
Post Reply
daniele
Posts: 327
Joined: 04 Mar 2009, 13:59

How to Shrink an LVM Volume on Linux

Post by daniele »

Articolo originale: https://www.casesup.com/category/knowle ... y-on-linux

Which command we will use;
- resize2fs
- lvreduce
-vgchange
-vgdisplay
-lvdisplay

1) Fare uno snapshot della VM. Se è una macchina fisica fare un backup. Se non ti fidi del meccanismo degli snapshot fai prima un backup
Restringere un file system non si può fare online, a differenza dell'espansione.
Il rischio potenziale è che dati siano presenti laddove la partizione verrà ristretta: in tal caso i dati saranno persi e il sistema potrebbe non funzionare più correttamente

2) Se la partizione NON è la root puoi semplicemente fare l'unmount della partizione e procedere a partire dal punto 4)

3) Se la partizione è la ROOT:

Code: Select all

#vgchange -a  y vgname
4) Esegui un check forzato del filesystem

Code: Select all

#e2fsck -f /dev/vgroot/lvroot

5) Ridimensiona il filesystem prima di ridimensionare il Logical Volume

*This step is too critical. You should resize your filesystem then shrink the logical volume.

Set the new size of the filesystem. But be careful when you set new filesystem size. You should give new size bigger than file system usage. For example, if your filesystem size is 250 GB and usage is 170GB. So you should shrink new volume 180Gb. This value musn't be less than usage! And also if your logical volume will be set 200GB it's recommended to set filesystem size 180GB.

Code: Select all

#resize2fs /dev/vgroot/lvroot 180G
6) Riduci la dimensione LVM
After resizing filesystem now start the same operation for LVM. But set LVM size bigger than Filesystem size. In my case it'll be 200GB.

Code: Select all

#lvreduce -L 200G /dev/vgroot/lvroot
7) Infine esegui di nuovo il resize del filesystem

Code: Select all

#resize2fs /dev/vgroot/lvroot
Post Reply