Resize LVM Partition

I partitioned the server hard drive with previous sizing when I reinstalled the Red Hat. At that time I still don’t quite familiar with Linux yet and now, with better understanding on the application and Linux I found that the partition size is not good enough so I tried to resize it. I used the Red Hat Linux installation disc in rescue mode to resize the partition in LVM. Before the resize:

[root@server ~]# fdisk -l

Disk /dev/sda: 299.4 GB, 299439751168 bytes
255 heads, 63 sectors/track, 36404 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       36404   292310707+  8e  Linux LVM
[root@server ~]# lvm lvs
  /dev/hda: open failed: No medium found
  LV       VG         Attr   LSize  Origin Snap%  Move Log Copy%  Convert
  LogVol00 VolGroup00 -wi-ao 72.84G
  LogVol01 VolGroup00 -wi-ao 79.97G
  LogVol02 VolGroup00 -wi-ao 79.97G
  LogVol03 VolGroup00 -wi-ao 40.00G
  LogVol04 VolGroup00 -wi-ao  5.97G
[root@server ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
                       71G  724M   67G   2% /
/dev/mapper/VolGroup00-LogVol01
                       78G  242M   74G   1% /home
/dev/mapper/VolGroup00-LogVol02
                       78G  2.2G   72G   3% /usr
/dev/mapper/VolGroup00-LogVol03
                       39G   20G   18G  53% /var
/dev/sda1              99M   20M   75M  21% /boot
tmpfs                 2.0G     0  2.0G   0% /dev/shm
[root@server ~]#

Below is the command I used:

# Check partition status
fdisk -l
df -h
lvm lvs --units m
lvm vgdisplay /dev/VolGroup00

# Unmount all partition
swapoff /dev/VolGroup00/LogVol04
umount /mnt/sysimage/home
umount /mnt/sysimage/usr
umount /mnt/sysimage/var
umount /mnt/sysimage/boot
umount -l /mnt/sysimage/dev
umount -l /mnt/sysimage

# Reduce / to 20GB
e2fsck -f /dev/VolGroup00/LogVol00
resize2fs -p /dev/VolGroup00/LogVol00 20G
lvm lvreduce -L 20G /dev/VolGroup00/LogVol00

# Reduce /usr to 40GB
e2fsck -f /dev/VolGroup00/LogVol02
resize2fs -p /dev/VolGroup00/LogVol02 40G
lvm lvreduce -L 40G /dev/VolGroup00/LogVol02

#Extend /home to 90GB
lvm lvextend -L 90G /dev/VolGroup00/LogVol01
e2fsck -f /dev/VolGroup00/LogVol01
resize2fs -p /dev/VolGroup00/LogVol01

#Extend /var to 110GB
lvm lvextend -L 110G /dev/VolGroup00/LogVol03
e2fsck -f /dev/VolGroup00/LogVol03
resize2fs -p /dev/VolGroup00/LogVol03

#Extend swap to (Size of RAM x 2) + 1MB
lvm lvextend -L 8193M /dev/VolGroup00/LogVol04

#Fill up the disk to /
lvm lvextend -l +100%FREE /dev/VolGroup00/LogVol00
e2fsck -f /dev/VolGroup00/LogVol00
resize2fs -p /dev/VolGroup00/LogVol00

# After reboot, recreate swap space
swapoff -v /dev/VolGroup00/LogVol04
mkswap /dev/VolGroup00/LogVol04
swapon -v /dev/VolGroup00/LogVol04
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s