wiki:increasing_logical_volume_size

Version 1 (modified by Ross, 13 years ago) ( diff )

--

Working With Logical Volumes

You can increase the size of a logical volume on a virtual server without taking the server off line. If a server's drive space fills up or you simply want to increase disk size, take the following steps.

Logical Volume Manager Commands

Each virtual server uses LVM to manage disk allocation. There exist both physical and logical volumes in this setup.

Physical Volumes

Physical volumes represent the 'actual' disk space being used. They feed into volume groups which represent the total allocated disk space for a given virtual server. In order to determine physical volumes and volume groups issue the command:

pvs

You should see output that looks like this:

0 daza:~# pvs
  PV         VG       Fmt  Attr PSize  PFree
  /dev/hda2  vg_daza0 lvm2 a-   49.52G 4.14G
0 daza:~# 

PV = Physical Volume and VG = Volume Group

Volume Groups

In order to extend a logical volume, you will need to know how much space is available in the volume group. Issue the following command:

vgs

You should see output similar to this:

0 daza:~# vgs                                                                                                                                                                                                                  
  VG       #PV #LV #SN Attr   VSize    VFree                                                                                                                                                                                     
  vg_daza0   1   5   0 wz--n- 49.52G 7.14G                                                                                                                                                                                     
0 daza:~# lvs 

Notice that VFree describes how much free space you have in the volume group.

Logical Volumes

To acquire the logical volume information do:

lvs

The command output should look like this:

1 daza:~# lvs
  LV           VG       Attr   LSize   Origin Snap%  Move Log Copy%  Convert
  home.members vg_daza0 -wi-ao  35.59G                                      
  root         vg_daza0 -wi-ao   1.86G                                      
  swap         vg_daza0 -wi-ao 488.00M                                      
  usr          vg_daza0 -wi-ao   2.79G                                      
  var          vg_daza0 -wi-ao   4.66G                                      
0 daza:~# 

Each of the above lines represents a logical volume assigned to a volume group. In this case, we have logical volumes home.members, root, swap, usr, and var, all inside the volume group vg_daza0.

Increasing Logical Volume Size

To increase the logical volume size, issue a command like this (replacing as needed the values, +3G, VOLUME_GROUP, LOGICAL_VOLUME) :

lvextend --size +3G VOLUME_GROUP/LOGICAL_VOLUME

In order to tell the file system to fill up the extra container space we just created, we do:

resize2fs /dev/mapper/VOLUME_GROUP-LOGICAL_VOLUME

This should resize the file system and complete the process.

Example: Full Log of Increasing LV size on Daza

0 daza:~# pvs                                                                                                                                                                                                                  
  PV         VG       Fmt  Attr PSize  PFree                                                                                                                                                                                   
  /dev/hda2  vg_daza0 lvm2 a-   49.52G 7.14G                                                                                                                                                                                   
0 daza:~# vgs                                                                                                                                                                                                                  
  VG       #PV #LV #SN Attr   VSize  VFree                                                                                                                                                                                     
  vg_daza0   1   5   0 wz--n- 49.52G 7.14G                                                                                                                                                                                     
0 daza:~# lvs                                                                                                                                                                                                                  
  LV           VG       Attr   LSize   Origin Snap%  Move Log Copy%  Convert                                                                                                                                                   
  home.members vg_daza0 -wi-ao  32.59G                                                                                                                                                                                         
  root         vg_daza0 -wi-ao   1.86G                                                                                                                                                                                         
  swap         vg_daza0 -wi-ao 488.00M                                                                                                                                                                                         
  usr          vg_daza0 -wi-ao   2.79G                                                                                                                                                                                         
  var          vg_daza0 -wi-ao   4.66G                                                                                                                                                                                         
0 daza:~# lvextend --size +3G vg_da^Gza0/home.members                                                                                                                                                                          
  Extending logical volume home.members to 35.59 GB                                                                                                                                                                            
  Logical volume home.members successfully resized                                                                                                                                                                             
0 daza:~# df -h /home/members                                                                                                                                                                                                  
Filesystem            Size  Used Avail Use% Mounted on                                                                                                                                                                         
/dev/mapper/vg_daza0-home.members                                                                                                                                                                                              
                       33G   31G     0 100% /home/members                                                                                                                                                                      
0 daza:~# resize2fs /dev/mapper/vg_^Gdaza0-home.members                                                                                                                                                                        
resize2fs 1.41.3 (12-Oct-2008)                                                                                                                                                                                                 
Filesystem at /dev/mapper/vg_daza0-home.members is mounted on /home/members; on-line resizing required                                                                                                                         
old desc_blocks = 3, new_desc_blocks = 3                                                                                                                                                                                       
Performing an on-line resize of /dev/mapper/vg_daza0-home.members to 9330688 (4k) blocks.                                                                                                                                      
The filesystem on /dev/mapper/vg_daza0-home.members is now 9330688 blocks long.                                                                                                                                                
                                                                                                                                                                                                                               
0 daza:~# resize2fs /dev/mapper/vg_daza0-home.members df -h /home/members                                                                                                                                                      
Filesystem            Size  Used Avail Use% Mounted on                                                                                                                                                                         
/dev/mapper/vg_daza0-home.members                                                                                                                                                                                              
                       36G   31G  2.9G  92% /home/members                                                                                                                                                                      
0 daza:~# vgs                                                                                                                                                                                                                  
  VG       #PV #LV #SN Attr   VSize  VFree                                                                                                                                                                                     
  vg_daza0   1   5   0 wz--n- 49.52G 4.14G                                                                                                                                                                                     
0 daza:~# lvs                                                                                                                                                                                                                  
  LV           VG       Attr   LSize   Origin Snap%  Move Log Copy%  Convert                                                                                                                                                   
  home.members vg_daza0 -wi-ao  35.59G                                                                                                                                                                                         
  root         vg_daza0 -wi-ao   1.86G                                                                                                                                                                                         
  swap         vg_daza0 -wi-ao 488.00M                                                                                                                                                                                         
  usr          vg_daza0 -wi-ao   2.79G                                                                                                                                                                                         
  var          vg_daza0 -wi-ao   4.66G                                                                                                                                                                                         
0 daza:~# w                                               
Note: See TracWiki for help on using the wiki.