Aumenta disco KVM

De Slacam_Wiki
Ir para: navegação, pesquisa

Aumentar a partição de disco de uma VM

METHOD #1: Partitions are ext2/ext3/ext4 based

The nuts of this method are as follows:

  1. 1. stop the VM
  2. 2. move the current image

mv mykvm.img mykvm.img.bak

  1. 3. create a new image

qemu-img create -f raw addon.raw 30G

  1. 4. concatenate the 2 images

cat mykvm.img.bak addon.raw >> mykvm.img

Now with the larger mykvm.img file in hand, boot gparted and extend the existing partition into the newly added disk space. This last step basically extends the OS partition so that it can make use of the extra space.

METHOD #2: Partitions are LVM based

Here are the steps that I roughly followed to resize a KVM guest that used LVM internally.

   Shutdown the VM
   add more space to the guest's "image file" (something like: cat old.img 10G_addon.raw >> new.img
   start the VM (using the newly created new.img)
   run fdisk inside VM and delete & re-create LVM partition

% fdisk /dev/vda ... Device Boot Start End Blocks Id System /dev/vda1 * 1 13 104391 83 Linux /dev/vda2 14 3263 26105625 8e Linux LVM

Command (m for help): d Partition number (1-4): 2

Command (m for help): p

Disk /dev/vda: 48.3 GB, 48318382080 bytes 255 heads, 63 sectors/track, 5874 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System /dev/vda1 * 1 13 104391 83 Linux

Command (m for help): n Command action

 e   extended
 p   primary partition (1-4)

p Partition number (1-4): 2 First cylinder (14-5874, default 14): 14 Last cylinder or +size or +sizeM or +sizeK (14-5874, default 5874): Using default value 5874

Command (m for help): p

Disk /dev/vda: 48.3 GB, 48318382080 bytes 255 heads, 63 sectors/track, 5874 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System /dev/vda1 * 1 13 104391 83 Linux /dev/vda2 14 5874 47078482+ 83 Linux

Command (m for help): t Partition number (1-4): 2 Hex code (type L to list codes): 8e Changed system type of partition 2 to 8e (Linux LVM)

Command (m for help): p

Disk /dev/vda: 48.3 GB, 48318382080 bytes 255 heads, 63 sectors/track, 5874 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System /dev/vda1 * 1 13 104391 83 Linux /dev/vda2 14 5874 47078482+ 8e Linux LVM

Command (m for help): w The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy. The kernel still uses the old table. The new table will be used at the next reboot. Syncing disks. %

   Reboot the VM
   Resize the LVM physical volume
   % pvdisplay 
     --- Physical volume ---
     PV Name               /dev/vda2
     VG Name               VolGroup00
     PV Size               24.90 GB / not usable 21.59 MB
     Allocatable           yes (but full)
     PE Size (KByte)       32768
     Total PE              796
     Free PE               0
     ...
   % pvresize /dev/vda2
   % pvdisplay
     --- Physical volume ---
     PV Name               /dev/vda2
     VG Name               VolGroup00
     PV Size               44.90 GB / not usable 22.89 MB
     Allocatable           yes 
     PE Size (KByte)       32768
     Total PE              1436
     Free PE               640
     ...
   Resize the LVM Logical Volume
     % lvresize /dev/VolGroup00/LogVol00 -l +640
     Extending logical volume LogVol00 to 43.88 GB
     Logical volume LogVol00 successfully resized
   Grow the File system
     % resize2fs /dev/VolGroup00/LogVol00 
     resize2fs 1.39 (29-May-2006)
     Filesystem at /dev/VolGroup00/LogVol00 is mounted on /; on-line resizing required
     Performing an on-line resize of /dev/VolGroup00/LogVol00 to 11501568 (4k) blocks.
     The filesystem on /dev/VolGroup00/LogVol00 is now 11501568 blocks long.

The above is my example, but I followed the steps on this website