Saturday, 8 October 2011

Extend Volume Group, Logical Volume and File System


If extension of file system is needed then you need to check for space in LV, if sufficient free space is not there in that LV then you need to check for the space in VG, if it also not have  sufficient free space then you need to add new physical Volume(PV). If you system have space at any step you can proceed from that point onwards. Here in below scenario we imagine there in no sufficient free space in LV and VG.

 Plan of action
Ø  Identify new disk and create PV
Ø  Extend Volume group.
Ø  Extend Logical Volume.
Ø  Extend File System.

Identify new disk and create PV

(for details click here)
Detect new LUN on the server
#ioscan -nfNC disk
 
To find which disks are not used in the LVM
#pvdisplay -l /dev/disk/*

Verify size of disk
#diskinfo  /dev/rdisk/disk42

 Initializing PV before using in LVM
# pvcreate /dev/rdisk/disk42


Extend Volume group

Add the physical volume in the volume group using the vgextend command.
# vgextend /dev/vg03 /dev/disk/disk42



Volume group "/dev/vg03" has been successfully extended.

Volume Group configuration for /dev/vg03 has been saved in /etc/lvmconf/vg03.conf

Verify that the volume group is successfully extended using the vgdisplay command.
It gives complete information about VG, LV, and PV
#vgdisplay -v /dev/vg03

You can also use grep to get useful information only like below:
# vgdisplay -v /dev/vg03 |grep "PV Name"



PV Name /dev/disk/disk41

PV Name /dev/disk/disk42

 Now VG have to free space so now we can extend LV

Extend Logical Volume

A logical volume can span multiple physical volumes, but it cannot span multiple volume groups. If you don't specify where LVM should allocate the new extents, LVM simply uses the first available extents in the volume group.

Extend lvol1 up to 900GB without specifying PV
# lvextend -L 1924  /dev/vg03/lvol1



Logical volume "/dev/vg03/lvol1" has been successfully extended.

Volume Group configuration for /dev/vg01 has been saved in /etc/lvmconf/vg03.conf

 Extending lvol1to 900GB with specifying PV
#lvextend -L 1924 /dev/vg03/lovl1 /dev/disk/disk42

If you not have enough space on VG then you may get the following error:


lvextend: Not enough free physical extents available.

Logical volume "/dev/vg03/lvol1" could not be extended.

Failure possibly caused by contiguous allocation policy.

Failure possibly caused by strict allocation policy
Verify the volume size by using the lvdisplay command.
# lvdisplay -v /dev/vg03/lvol1

It gives us complete information about LV, Distribution of logical volume (in PV) and LE.
We can use grep command to get the use full information only:
#lvdisplay -v /dev/vg03/lovl1 | grep “LV Size (Mbytes)”



LV Size (Mbytes)            1924

 Now it is verified that LV have sufficient space so now you can extend file system

Extend File System

Simply extending a logical volume does not make the new space available for use by the file system in that volume. The new space in the volume cannot be used until the file system’s superblock and other metadata structures have been notified that new space is available.

Extending file system without online JFS:
We would need to unmount the /data file system
#umount /data

Extend the file system using the extendfs file command.
#extendfs -F vxfs -s 115200 /dev/vg03/rlvol1

Here F: - File system type
         s :- Specifies the number of DEV_BSIZE blocks to be added to the file system. 

If size is not specified, the maximum possible size is used.
# extendfs /dev/vg03/rlvol1

You can check system block size by below command:
#fstyp -v /dev/vg03/lvol1 | grep f_bsize



f_bsize: 8192

 OR
#df -g /dev/vg03/lvol1 |grep "file system block size"



8192 file system block size            1024 fragment size

From here we get 1block size = 8192KB = 8MB
Re-mount the /data file system.
# mount /data

With OnlineJFS you do not need to umount. Use fsadm instead:
# fsadm -b <new size in KB> <mountpoint>

#fsadm -b 943718400 /data
Verify you have the OnlineJFS software by using the command
# swlist | grep JFS

 Check the file system extension using the bdf command.
# bdf | grep /dev/vg03/lvol1



Filesystem                 kbytes           used                avail             %used Mounted on

/dev/vg01/oracle   943718400   283115520     660612880   30%        /data

4 comments:

  1. thanks a lot for the information, its very useful

    ReplyDelete
  2. Can you extend the Volume Group without adding a new PV? I have increased the sixe of the virtual disk so do not need to add a new one.

    ReplyDelete
  3. you can increase as many virtual disk as you want till space available in Volume Group. If there is no space in VG then you have to extend it with new PV.

    ReplyDelete
  4. (root) @/var/adm/syslog> extendfs -F vxfs /dev/vgtest/lvtest
    UX:vxfs extendfs: ERROR: V-3-20144: /dev/vgtest/lvtest is mounted, cannot extend.
    (root) @/var/adm/syslog>

    Any help?

    ReplyDelete