Linux – Shrinking Linux Partition and VM’s

centos6linuxpartitionvirtual-machines

I have a Centos 6.2 x86_64 Virtual machine running on an EXSi 5.1 Server.

It currently use 320GB of space which is way too much space and need to be shrunk to about 80GB.
What I need to do is reduce the size of the partitions and the reduce the size of the VMDK file.

Below is the partition layout

Filesystem                      Type    Size    Used    Avail   Use%    Mounted on
/dev/mapper/VolGroup00-LogVol00 ext4    9.9G    360M    9.0G    4%      /
tmpfs                           tmpfs   3.9G    0       3.9G    0%      /dev/shm
/dev/mapper/VolGroup00-LogVol05 ext4    30G     1.6G    27G     6%      /binlogs
/dev/sda1                       ext4    97M     32M     61M     34%     /boot
/dev/mapper/VolGroup00-LogVol02 ext4    9.9G    912M    8.5G    10%     /home
/dev/mapper/VolGroup00-LogVol06 ext4    30G     180M    28G     1%      /radius
/dev/mapper/VolGroup00-LogVol07 ext4    186G    272M    177G    1%      /u02
/dev/mapper/VolGroup00-LogVol04 ext4    30G     3.0G    26G     11%     /usr
/dev/mapper/VolGroup00-LogVol03 ext4    20G     414M    19G     3%      /var

If someone could tell me the the command required to reduce the partitions it would be greatly appreciated.

Best Answer

You don't need vgreduce. You only have one VG. Looks like you are mostly concerned about /u02 since that is the largest partition and is using less than 1G

For reducing LV, usually will need to unmount it first. That means if you ever want to reduce the / filesystem you will need to do it in rescue mode or single user mode. Process is otherwise the same

Anyway, this is what you do

First word of caution, you need to reduce the FS more than you reduce the LV. So if you want to free up 10G of LV space, reduce your FS by 11G. Make sense? Let's use that as an example

Second word of caution, when reducing a filesystem, it's always good to have a backup. Not as crucial (but still important) when extending a fs. But reducing FS, always good.

umount the filesystem  
use command: e2fsck -f /dev/[path to LV]  
use command: resize2pfs -p /dev/[path to LV] 175G  (11G smaller) 
use command: lvreduce -L -10G /dev/[path to LV]  (10G smaller) 
mount filesystem.

When you run vgdisplay you should see you have 10G freed up now

(TOTALLY FRESH IN MY MIND because I just blogged about it like one or two days ago right here: http://geekswing.com/geek/reducing-filesystem-fs-size-and-lvm-size-in-linux/ )