giovedì 5 luglio 2012

How To Expand LVM Volume

One of the great features of Oracle Linux is that it uses by default Logical Volume to group physical volumes.
This means that if we ran out of disk space we can add another disk, physical hard drive or virtual disk if we are on a guest VM, and expand the original volume increasing available space.

Log in to your machine and run "df -h" and write somewhere the output it produces:

[root@orcl ~]# df -h
Filesystem                    Size  Used Avail Use% Mounted on
/dev/mapper/vg_orcl-lv_root    118G  21G   92G   19% /
/dev/mapper/vg_orcl-lv_home    5.0G  1.7G  3.0G  36% /home
tmpfs                         1.5G  0     1.5G   0% /dev/shm
/dev/xvda1                    485M  51M   409M  12% /boot

as you can see we have:

Volume Group= vg_orcl
Logical Volume= lv_root and lv_home

Based on what we would like to expand we will use either lv_root or lv_home.

In this post I need to increase disk space for expanding a database tablespace. Since Database is installed on "/u01" directory I need to expand the Logical Volume lv_root which has a mount point of "/".

Power off machine (or VM guest in my case) and attach to it new physical hard drive or virtual disk.

Now we need to boot the machine using a Live CD since we have to do some stuff on partitions and we can't do it if partitions are mounted.

I use RescueLinux  which is a pretty small Live CD.

When booted from LiveCD:

[root@orcl ~]# fdisk /dev/sdb  (OR /dev/sdc OR /dev/sdd if you add your second or third hard disk)
Press n for creating new partition
Press p for primary
Press 1
Press enter
Press enter
Press t for partition type and choose 8e for LVM
Press w to write changes

[root@orcl ~]# lvm

lvm> pvcreate /dev/sdb1 (OR /dev/sdc1 OR /dev/sdd1 if you add your second or third volume)
Physical volume "/dev/sda1" successfully created

lvm> vgextend vg_orcl /dev/sdb1
Volume group "vg_orcl" successfully extended

lvm> lvextend -l +100%FREE /dev/vg_orcl/lv_root
Extending logical volume lv_root to 250.47 GB
Logical volume lv_root successfully resized

[root@orcl ~]# e2fsck –f  /dev/vg_orcl/lv_root

[root@orcl ~]# resize2fs /dev/vg_orcl/lv_root

Reboot and remove LiveCD.

Run "df -h" and if everything went fine you will have increased available disk space on VolumeGroup.

Nessun commento:

Posta un commento