Friday, 10 February 2012

CENTOS extend LVM using existing space on the virtual disk

After creating virtual machine from template I have to provide it with more disk resources. I just reconfigure provided vitrual disk and made it size of 500Gb. After reboot I still see the same partitions sizee as before:

# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_vzldap1-lv_root
                       18G  2.7G   14G  16% /
tmpfs                 1.9G     0  1.9G   0% /dev/shm
/dev/sda1             485M   53M  407M  12% /boot

Create extra disk partition:


#fdisk /dev/sda

Command (m for help): p

Disk /dev/sda: 536.9 GB, 536870912000 bytes
255 heads, 63 sectors/track, 65270 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00098954

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          64      512000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              64        2611    20458496   8e  Linux LVM

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 3
First cylinder (2611-65270, default 2611): 
Using default value 2611
Last cylinder, +cylinders or +size{K,M,G} (2611-65270, default 65270): 
Using default value 65270

Command (m for help): t
Partition number (1-4): 3
Hex code (type L to list codes): 8e
Changed system type of partition 3 to 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 or after you run partprobe(8) or kpartx(8)
Syncing disks.

Trying to create a physical volume from the new partition:
# lvm pvcreate /dev/sda3
  Device /dev/sda3 not found (or ignored by filtering).

OK! I rebooted the server and everything work fine:
#lvm pvcreate /dev/sda3
  Writing physical volume data to disk "/dev/sda3"
  Physical volume "/dev/sda3" successfully created

Add this physical volume to the volume group 
#lvm vgextend "vg_vzldap1" /dev/sda3
  Volume group "vg_vzldap1" successfully extended

Check free physical extent:
#vgdisplay 
  --- Volume group ---
  VG Name               vg_vzldap1
  System ID             
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  4
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               2
  Max PV                0
  Cur PV                2
  Act PV                2
  VG Size               499.50 GiB
  PE Size               4.00 MiB
  Total PE              127872
  Alloc PE / Size       4994 / 19.51 GiB
  Free  PE / Size       122878 / 479.99 GiB
  VG UUID               HdmJKI-riIm-td3J-DdKI-XCTd-UaKH-iAU4wd

# lvm lvresize -l 122878 /dev/vg_vzldap1/lv_root
File descriptor 7 (pipe:[10297]) leaked on lvm invocation. Parent PID 1668: bash
  Extending logical volume lv_root to 479.99 GiB
  Logical volume lv_root successfully resized
# resize2fs /dev/vg_vzldap1/lv_root
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/vg_vzldap1/lv_root is mounted on /; on-line resizing required
old desc_blocks = 2, new_desc_blocks = 30
Performing an on-line resize of /dev/vg_vzldap1/lv_root to 125827072 (4k) blocks.
The filesystem on /dev/vg_vzldap1/lv_root is now 125827072 blocks long.

Check the new partitions size
# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_vzldap1-lv_root
                      473G  2.7G  446G   1% /
tmpfs                 1.9G     0  1.9G   0% /dev/shm
/dev/sda1             485M   53M  407M  12% /boot




1 comment:

Anonymous said...

thank you very much sir