Changes between Version 10 and Version 11 of extend-disk-on-kvm-guest
- Timestamp:
- Aug 2, 2011, 1:27:04 PM (13 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
extend-disk-on-kvm-guest
v10 v11 1 1 = How do I extend the disk space for a KVM guest? = 2 3 Each 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 5 This example shows that chavez has space available: 6 7 {{{ 8 0 chavez:~# vgs 9 VG #PV #LV #SN Attr VSize VFree 10 vg_chavez0 1 7 0 wz--n- 499.52g 57.52g 11 0 chavez:~# 12 }}} 13 14 There's no need to allocate more space from the host, since chavez already has 57GB free. 15 16 Here's an example of a host without any available disk space: 17 18 {{{ 19 0 mandela:~# vgs 20 VG #PV #LV #SN Attr VSize VFree 21 vg_mandela0 1 6 0 wz--n- 69.52g 0 22 0 mandela:~# 23 }}} 24 25 mandela has no available disk space, so additional space must be allocated from the host, ken. 2 26 3 27 Our KVM guests are each allocated a single logical volume from the KVM host's volume group (typically named after the host). 4 28 5 The first and easiest step is to login to the host, check available disk space , and then run the lvextend command:29 The first and easiest step is to login to the host, check available disk space: 6 30 7 31 {{{ … … 9 33 VG #PV #LV #SN Attr VSize VFree 10 34 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 35 0 ken:~# 36 }}} 37 38 ken has 1.29 TB available. 39 40 Next check how much space is already allocated to your guest: 41 42 {{{ 43 0 ken:~# lvs | grep mandela 44 mandela vg_ken0 -wi-ao 20.00g 16 45 0 ken:~# 17 46 }}} 18 47 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. 48 The, add more space: 20 49 21 After rebooting, you can confirm the new size by running: 50 {{{ 51 lvextend --size 35G vg_ken0/mandela 52 Extending logical volume mandela to 35.00 GiB 53 Logical volume mandela successfully resized 54 0 ken:~# 55 }}} 56 57 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]). You will need to execute: `shutdown -h now`, so that the underlying block devices get reinitialized by a new process. 58 59 After rebooting, you can confirm the new size on the guest by running: 22 60 23 61 {{{ … … 27 65 You 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). 28 66 29 Next, run parted and print the current partition table. It's often easier to manage if you look at units in sectors:67 Next, on the guest, run parted and print the current partition table. It's often easier to manage if you look at units in sectors: 30 68 31 69 {{{ … … 33 71 }}} 34 72 35 You can optionally create a new partition with the remaining space: 73 Note carefully the start sector for the last partition. You will need this exact number in the step below. 36 74 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): 75 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). 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. 47 76 48 77 {{{ … … 51 80 mkpart primary STARTSECTOR -1 52 81 }}} 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].55 82 56 83 Next, check to see if your changes are reflected in /proc/partitions: … … 62 89 You may need to reboot a second time before they will show up. 63 90 64 Once your partition table is reflecting the new size :91 Once your partition table is reflecting the new size, run the following command: 65 92 66 93 {{{