kb

Centos | Resize an LVM physical volume without a reboot

First unmound everything that uses the given volume group

List all the logical volumes that are in vol1

lvdisplay /dev/vol01

  — Logical volume —
  LV Name                /dev/vol01/lv01
  VG Name                vol01
  LV UUID                q3eQP3-4V9E-7yvo-LUZR-zbXz-F2Mh-Pn5fDt
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                139.70 GB
  Current LE             35762
  Segments               2
  Allocation             inherit
  Read ahead sectors     auto
  – currently set to     256
  Block device           254:0
   
  — Logical volume —
  LV Name                /dev/vol01/lv02
  VG Name                vol01
  LV UUID                b53h7W-VO2U-3Ok5-WvW3-GbDp-Tbvb-6bbdkw
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                29.31 GB
  Current LE             7504
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  – currently set to     256
  Block device           254:1

Now unmount all these volumes (if they are mounted)

umount /dev/vol01/lv01
umount /dev/vol01/lv02

In case you get a “device is busy” error, check out what processes use them (lsof /dev/vol01/lv01) and stop/kill them.
Now deactive the volume group.

vgchange -a n vol01

Increase the size of the sda2 partition to the desired value.
You do this by deleting the partition and recreating it with a higher end cylinder.
I assume that pvresize can handle partition expansions only if the partition start remains the same and the partition end cylinder is moved to a higher value.

fdisk /dev/sda

The number of cylinders for this disk is set to 60801.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
   (e.g., DOS FDISK, OS/2 FDISK)

Command (m for help): p

Disk /dev/sda: 500.1 GB, 500107862016 bytes
255 heads, 63 sectors/track, 60801 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x000e4bad

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1               1         486     3903763+  83  Linux
/dev/sda2             487       18722   146480670   8e  Linux LVM

Command (m for help): d
Partition number (1-4): 2

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (487-60801, default 487): 
Using default value 487
Last cylinder or +size or +sizeM or +sizeK (487-60801, default 60801): 
Using default value 60801

Command (m for help): t
Partition number (1-4): 2
Hex code (type L to list codes): 8e
Changed system type of partition 2 to 8e (Linux LVM)

Command (m for help): p

Disk /dev/sda: 500.1 GB, 500107862016 bytes
255 heads, 63 sectors/track, 60801 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x000e4bad

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1               1         486     3903763+  83  Linux
/dev/sda2             487       60801   484480237+  8e  Linux LVM

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table.
The new table will be used at the next reboot.
Syncing disks.

Now comes the interesting part: we force the system with partprobe to re-read the partition table.

pvdisplay /dev/sda2


  — Physical volume —
  PV Name               /dev/sda2
  VG Name               vol01
  PV Size               139.69 GB / not usable 3.53 MB
  Allocatable           yes (but full)
  PE Size (KByte)       4096
  Total PE              35761
  Free PE               0
  Allocated PE          35761
  PV UUID               S0cDcl-7mr8-2AAb-172u-HClq-J2aQ-DfC2V5

partprobe
pvresize /dev/sda2
pvdisplay /dev/sda2

  — Physical volume —

  PV Name               /dev/sda2
  VG Name               vol01
  PV Size               462.04 GB / not usable 1.04 MB
  Allocatable           yes 
  PE Size (KByte)       4096
  Total PE              118281
  Free PE               82520
  Allocated PE          35761
  PV UUID               S0cDcl-7mr8-2AAb-172u-HClq-J2aQ-DfC2V5


# Voala! 🙂 The physical volume got increased.
# Time to reactivate the volume group.

vgchange -a y vol01

# Now check the volume group details.

vgdisplay vol01

  — Volume group —
  VG Name               vol01
  System ID             
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  18
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                3
  Open LV               3
  Max PV                0
  Cur PV                2
  Act PV                2
  VG Size               927.79 GB
  PE Size               4.00 MB
  Total PE              237515
  Alloc PE / Size       68866 / 269.01 GB
  Free  PE / Size       168649 / 658.79 GB
  VG UUID               0eY2tg-AOny-XsDL-wfLR-d290-2jxO-TDTNnQ

You can now use lvextend to increase logical volumes in the volume group.

lvextend -L +10G --name lv01 /dev/vol01

And resize2fs to extend the Ext2/3 filesystem on the logical volume.

And xfs_growfs /mountpoint to extend the xfs filesystem on the logical volume.

resize2fs /dev/vol01/lv01

And finally mount the filesystems.

mount /dev/vol01/lv01
mount /dev/vol01/lv02

You’re now ready.

source: http://muzso.hu/2009/07/28/how-to-resize-an-lvm-physical-volume-without-a-reboot