Saturday, February 1, 2014

Extending LVM

I have a 1TB hard disk. The 400GB of the hard disk(/dev/cciss/c0d0p2) is configured as LVM, with the remaining 600GB left unutilized. Now I want to extend the logical volume(LVM) by 600GB by utilizing the unused 600GB.

The LV name is /dev/rootvg/scribe
Get the current size of LVM /dev/rootvg/scribe by using lvdisplay command. It should show LV Size 389.97 GB

Currently the disk hard disk consists of just two partitions

/dev/cciss/c0d0p1 - This is configured as /boot partition and not part of LVM
/dev/cciss/c0d0p2 - Configured as part of LVM /dev/rootvg/scribe

# fdisk -l

Disk /dev/cciss/c0d0: 1199.8 GB, 1199865640960 bytes
255 heads, 63 sectors/track, 145875 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

           Device Boot      Start         End      Blocks   Id  System
/dev/cciss/c0d0p1   *           1          13      104391   83  Linux
/dev/cciss/c0d0p2              14       65283   524281275   8e  Linux LVM

Now let us go about extending the Logical Volume /dev/rootvg/scribe by adding extra 600GB.

1) Create a partition of the unused 600GB

fdisk /dev/cciss/c0d0

p - to display the existing partition table
n - to create new partition

Once created

p - should display /dev/cciss/c0d0p3 as regular Linux partition
t - to convert newly created partition(/dev/cciss/c0d0p3) to lvm type
Enter partition number - 3(probably)
Hex code : 8e (Now the partition is converted to lvm type)

p - should show that /dev/cciss/c0d0p3 is of type lvm
w - to write the partition table to the disk

2) The newly added partition will not be visible on the system
   Check the same using
    ls /dev/cciss/   - We shall see that c0d0p3 is missing

   partprobe - Running partprobe reloads the partition table and brings the partition up. No need to reboot the system.

    ls /dev/cciss/ - We shall now see the c0d0p3

3) Now need to add /dev/cciss/c0d0p3 as part of physical volume(PV) 
     pvdisplay
This will show only the physical volume (/dev/cciss/c0d0p2)
   PV Name               /dev/cciss/c0d0p2

Now run the command
    pvcreate /dev/cciss/c0d0p3
This command creates a header on each partition so it can be used for LVM.

Now run pvdisplay to see your new PV.
   pvdisplay

It should now show
  PV Name               /dev/cciss/c0d0p2
  PV Name               /dev/cciss/c0d0p3

"VG Name" for /dev/cciss/c0d0p3 should be empty.
Since "/dev/cciss/c0d0p2 is already part of LVM, the "VG Name" for /dev/cciss/c0d0p2 will be displayed as rootvg

Need to add /dev/cciss/c0d0p3 as part of the volume group rootvg

4) Run the vgdisplay command to get the "VG Name"
    vgdisplay

5) Use command vgextend to add the PV(/dev/cciss/c0d0p3) to the VG rootvg
  vgextend  rootvg  /dev/cciss/c0d0p3

6)  Run   pvdisplay command to see the value of "VG Name" for PV /dev/cciss/c0d0p3. It shall display as rootvg
   
 7) Run command vgdisplay to see the new size of the VG rootvg.
     Mainly note the value of "VG size". It should be nearly 1TB.
     Also note "Free  PE / Size" and "Total PE". Earlier "Free  PE / Size" shall be "0 / 0". Now it shall show some values.

8) Now comes the extension of Logical Volume /dev/rootvg/scribe
   Run the command
    lvdisplay
   to get the names of existing Logical Volumes.

  From "vgdisplay" command get the value of "Free PE/ Size". It will show the available "Physical Extent / Disk Size".

  Now extend the Logical Volume "/dev/rootvg/scribe"
   lvextend -l +19755 /dev/rootvg/scribe
               (OR)
   lvextend -L+617.34 /dev/rootvg/scribe

  Run the command
    lvdisplay

Check the "LV Size" for "LV Name : /dev/rootvg/scribe". It should be more than current "LV Size 389.97 GB".

 --- Logical volume ---
  LV Name                /dev/rootvg/scribe
  VG Name                rootvg
  LV UUID                P08Qra-MnjE-5tgd-4Muw-c7r5-kY7o-6zUAu2
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                1007.31 GB
  Current LE             32234
  Segments               2
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:2

9) Now need to grow the filesystem for the LV /dev/rootvg/scribe

  umount /scribe
  e2fsck -f /dev/rootvg/scribe
  resize2fs /dev/rootvg/scribe
  mount -a

 Use "df" command to see the new filesystem size

# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/cciss/c0d0p1      99M   13M   81M  14% /boot
tmpfs                  12G     0   12G   0% /dev/shm
/dev/mapper/rootvg-scribe
                      992G  407M  941G   1% /scribe

No comments:

Post a Comment