Changes between Version 10 and Version 11 of extend-disk-on-kvm-guest


Ignore:
Timestamp:
Aug 2, 2011, 9:27:04 AM (8 years ago)
Author:
Jamie McClelland
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • extend-disk-on-kvm-guest

    v10 v11  
    11= How do I extend the disk space for a KVM guest? =
     2
     3Each guest is running logical volume manager. If you need to allocate more disk space on a guest, run the vgs command to determine if you already have un-allocated disk space available.
     4
     5This example shows that chavez has space available:
     6
     7{{{
     80 chavez:~# vgs
     9  VG         #PV #LV #SN Attr   VSize   VFree
     10  vg_chavez0   1   7   0 wz--n- 499.52g 57.52g
     110 chavez:~#
     12}}}
     13
     14There's no need to allocate more space from the host, since chavez already has 57GB free.
     15
     16Here's an example of a host without any available disk space:
     17
     18{{{
     190 mandela:~# vgs
     20  VG          #PV #LV #SN Attr   VSize  VFree
     21  vg_mandela0   1   6   0 wz--n- 69.52g    0
     220 mandela:~#
     23}}}
     24
     25mandela has no available disk space, so additional space must be allocated from the host, ken.
    226
    327Our KVM guests are each allocated a single logical volume from the KVM host's volume group (typically named after the host).
    428
    5 The first and easiest step is to login to the host, check available disk space, and then run the lvextend command:
     29The first and easiest step is to login to the host, check available disk space:
    630
    731{{{
     
    933  VG      #PV #LV #SN Attr   VSize VFree
    1034  vg_ken0   1  16   0 wz--n- 1.82t 1.29t
    11 0 ken:~# lvs | grep mirabal
    12   mirabal  vg_ken0 -wi-ao  20.00g                                     
    13 0 ken:~# lvextend --size 35G vg_ken0/mirabal
    14   Extending logical volume mirabal to 35.00 GiB
    15   Logical volume mirabal successfully resized
     350 ken:~#
     36}}}
     37
     38ken has 1.29 TB available.
     39
     40Next check how much space is already allocated to your guest:
     41
     42{{{
     430 ken:~# lvs | grep mandela
     44  mandela  vg_ken0 -wi-ao  20.00g                                     
    16450 ken:~#
    1746}}}
    1847
    19 Next, you will need to reboot the guest before the change in disk space is recognized by the guest ([http://comments.gmane.org/gmane.comp.emulators.kvm.devel/64203 this is apparently a requirement until someone implements online disk resizing]).  Under kvm-manager, i think that means you need to do a `shutdown -h`, so that the underlying block devices get reinitialized by a new process.
     48The, add more space:
    2049
    21 After rebooting, you can confirm the new size by running:
     50{{{
     51lvextend --size 35G vg_ken0/mandela
     52  Extending logical volume mandela to 35.00 GiB
     53  Logical volume mandela successfully resized
     540 ken:~#
     55}}}
     56
     57Next, you will need to reboot the guest before the change in disk space is recognized by the guest ([http://comments.gmane.org/gmane.comp.emulators.kvm.devel/64203 this is apparently a requirement until someone implements online disk resizing]).  You will need to execute: `shutdown -h now`, so that the underlying block devices get reinitialized by a new process.
     58
     59After rebooting, you can confirm the new size on the guest by running:
    2260
    2361{{{
     
    2765You should see that the base disk (e.g. /dev/vda) reflects the new size, although all of the partitions reflect their old sizes (e.g. /dev/vda2).
    2866
    29 Next, run parted and print the current partition table. It's often easier to manage if you look at units in sectors:
     67Next, on the guest, run parted and print the current partition table. It's often easier to manage if you look at units in sectors:
    3068
    3169{{{
     
    3371}}}
    3472
    35 You can optionally create a new partition with the remaining space:
     73Note carefully the start sector for the last partition. You will need this exact number in the step below.
    3674
    37 {{{
    38 parted /dev/vda
    39 }}}
    40 
    41 {{{
    42 unit s
    43 mkpart primary STARTSECTOR -1
    44 }}}
    45 
    46 Or, you can delete the last partition, and re-create it with a higher end sector (yes, you can do this without destroying the data on the disk):
     75Delete the last partition, and re-create it with a higher end sector (yes, you can do this without destroying the data on the disk). Replace STARTSECTOR with the start sector of the output from the command above. Specifying -1 as the end sector means go as far to the end as possible. If you get a message saying that the sector you requested is not possible, accept a different one, you can safely say yes.
    4776
    4877{{{
     
    5180mkpart primary STARTSECTOR -1
    5281}}}
    53 
    54 When creating new partitions, it's a good idea to ensure that the [wiki:disk_alignment the disks start on sectors that are multiples of 8192].
    5582
    5683Next, check to see if your changes are reflected in /proc/partitions:
     
    6289You may need to reboot a second time before they will show up.
    6390
    64 Once your partition table is reflecting the new size:
     91Once your partition table is reflecting the new size, run the following command:
    6592
    6693{{{