Monday, March 21, 2011

Shrinking VMware virtual disks with Linux OS and LVM partitioned

Here I present a method to shrink the virtual disk with Redhat Linux OS installed and the filesystems part of LVM.

Current disk information and partition layout is as follows :

[root@localhost ~]# fdisk -l

Disk /dev/sda: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sda1 1 13 104391 83 Linux
/dev/sda2 14 1305 10377990 8e Linux LVM

[root@localhost ~]# lvs
LV VG Attr LSize Origin Snap% Move Log Copy%
lvhome rootvg -wi-ao 1.56G
lvroot rootvg -wi-ao 2.00G
lvswap rootvg -wi-ao 1.00G
lvtmp rootvg -wi-ao 320.00M
lvusr rootvg -wi-ao 3.00G
lvvar rootvg -wi-ao 2.00G

[root@localhost ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/sda2 rootvg lvm2 a- 9.88G 0

[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
2.0G 217M 1.7G 12% /
/dev/sda1 99M 11M 83M 12% /boot
tmpfs 506M 0 506M 0% /dev/shm
1.6G 34M 1.5G 3% /home
289M 17M 260M 7% /tmp
3.0G 1.6G 1.3G 55% /usr
2.0G 68M 1.8G 4% /var

Now we see some free space left on /, /usr, /var, /home filesystems.

Next, shutdown the server and add a harddisk of smaller size.

(Note : the smaller hard disk should be able to fit the used space of the original disk)

In rescue mode, verify the filesystems mounted :

Run filesystem check on the filesystems :

#e2fsck -f /dev/rootvg/lvroot
#e2fsck -f /dev/rootvg/lvhome
#e2fsck -f /dev/rootvg/lvusr
#e2fsck -f /dev/rootvg/lvvar

Reboot the server after making the changes.

Reboot the server.

No comments:

Post a Comment