Changes between Initial Version and Version 1 of extend-logical-volume


Ignore:
Timestamp:
Apr 4, 2012, 5:10:23 PM (13 years ago)
Author:
Ross
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • extend-logical-volume

    v1 v1  
     1 = How to extend a logical volume on a KVM guest =
     2
     3Sometimes a logical volume on our guests fill up, meaning that data cannot be written to parts of the file system.  For example, vg_stone0-var will have no remaining space making it impossible to write to the /var directory. 
     4
     5 == Step One: figure out file system and logical volume size ==
     6
     7In order to determine if this is the case, you can run
     8
     9{{{
     10# df -h
     11}}}
     12
     13The output will look like this:
     14
     15{{{
     160 stone:~# df -h
     17Filesystem            Size  Used Avail Use% Mounted on
     18/dev/mapper/vg_stone0-root
     19                      3.8G  957M  2.7G  27% /
     20tmpfs                1007M     0 1007M   0% /lib/init/rw
     21udev                 1001M  108K 1001M   1% /dev
     22tmpfs                1007M     0 1007M   0% /dev/shm
     23/dev/vda1             236M   22M  202M  10% /boot
     24/dev/mapper/vg_stone0-tmp
     25                      961M   19M  894M   3% /tmp
     26/dev/mapper/vg_stone0-var
     27                      6.9G  4.6G  2.1G  69% /var
     28/dev/mapper/vg_stone0-home
     29                       30G   24G  4.3G  85% /home
     300 stone:~#
     31}}}
     32
     33If the fifth column says 100% then the file system is full.  In order to check if any space exists on the logical volume, you can run:
     34
     35{{{
     36# lvdisplay
     37}}}
     38
     39The output should look something like this.
     40
     41{{{
     420 stone:~# lvdisplay /dev/vg_stone0/var
     43  --- Logical volume ---
     44  LV Name                /dev/vg_stone0/var
     45  VG Name                vg_stone0
     46  LV UUID                quZZX4-zRSb-sGyH-1V1b-nBx9-A2rX-oGau0V
     47  LV Write Access        read/write
     48  LV Status              available
     49  # open                 1
     50  LV Size                7.00 GiB
     51  Current LE             1792
     52  Segments               2
     53  Allocation             inherit
     54  Read ahead sectors     auto
     55  - currently set to     256
     56  Block device           253:3
     57   
     580 stone:~#
     59}}}
     60
     61You will want to check the LV Size and make sure it's the same size as the df -h command above.  If it's larger than the output of df -h, then more space has been allotted to the drive and you can skip to step 3.
     62
     63If you've determined that the LV Size needs extending from the proceeding step, you'll need to check and see if the volume group has available space:
     64
     65{{{
     660 stone:~# vgs
     67  VG        #PV #LV #SN Attr   VSize  VFree
     68  vg_stone0   1   5   0 wz--n- 49.76g 7.52g
     690 stone:~#
     70}}}
     71
     72If you do not see enough VFree space, you'll need to follow the instructions on [wiki:extend-disk-on-kvm-guest].
     73
     74 == Step Two: Extend the logical volume ==
     75
     76  Once you've done that, then execute the following command for the logical volume.
     77
     78{{{
     79# lvextend --size 10GB /dev/mapper/vg_stone0-var
     80}}}
     81
     82Make sure that the number after --size is the total size of the logical volume you want.
     83
     84 == Step Three: Extend the file system ==
     85
     86Once you've extended the logical volume, you need to extend the file system as well. The following command will extend the file system.
     87
     88{{{
     89resize2fs /dev/mapper/LVNAME
     90}}}
     91
     92You may be asked to run e2fsck when running the above command.  If so run:
     93
     94{{{
     95e2fsck /dev/mapper/LVNAME
     96}}}
     97
     98When running this command, you may be asked to allow e2fsck to fix parts of the file system.  Generally, you should answer yes to such requests.
     99
     100Then rerun resize2fs command.  If it succeeds, you should have extended the logical volume.  Repeat Step One and make sure everything looks correct.
     101
     102 == Something's not Right ==
     103
     104If you have done all of the above and the file system seems to be acting in an unusual manner.  You may need to run fsck to fix the file system.  The easiest way to accomplish this is to restart the guest with a -F option. 
     105
     106'''NOTE:''' This is the desperate response approach.
     107
     108{{{
     109# shutdown -hF now
     110}}}