Here’s an explanation of how to resize KVM virtual image.
# uname –ri
3.5.0-28-generic x86_64
tail -1 /etc/lsb-release
DISTRIB_DESCRIPTION="Linux Mint 12 Lisa"
# qemu-system-x86_64 --version
QEMU emulator version 1.2.0 (qemu-kvm-1.2.0+noroms-0ubuntu2.12.10.3, Debian), Copyright (c) 2003-2008 Fabrice Bellard
# libvirtd --version
libvirtd (libvirt) 0.9.13
|
before resizing the virtual image.
This VM has two partitions /dev/vda1 for / and /dev/vda2 for swap.
on the VM
root@ubuntu12-04-vm1:~# fdisk –l
Disk /dev/vda: 5368 MB, 5368709120 bytes
4 heads, 32 sectors/track, 81920 cylinders, total 10485760 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0007c82d
Device Boot Start End Blocks Id System
/dev/vda1 63 7998046 3998992 83 Linux
/dev/vda2 7999488 9998335 999424 82 Linux swap / Solaris
root@ubuntu12-04-vm1:~# cat /etc/fstab
# /etc/fstab: static file system information.
# <file system> <mount point> <type> <options> <dump> <pass>
proc /proc proc defaults 0 0
/dev/sda1 / ext4 defaults 0 0
/dev/sda2 swap swap defaults 0 0
root@ubuntu12-04-vm1:~# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/vda1 3.8G 3.4G 201M 95% /
udev 243M 4.0K 243M 1% /dev
tmpfs 99M 220K 99M 1% /run
none 5.0M 0 5.0M 0% /run/lock
none 246M 0 246M 0% /run/shm
|
shutdown the VM
on the KVM host
virsh # shutdown ubuntu12-vm1
Domain ubuntu12-vm1 is being shutdown
|
back up the virtual image.
on the KVM host
mint-1 images # cp ubuntu12-04-vm1.qcow2 ubuntu12-04-vm1.qcow2.backup
|
resize the virtual image
on the KVM
before resizing
mint-1 images # kvm-img info ubuntu12-04-vm1.qcow2
image: ubuntu12-04-vm1.qcow2
file format: qcow2
virtual size: 5.0G (5368709120 bytes)
disk size: 3.9G
cluster_size: 65536
|
resize the virtual image
mint-1 images # kvm-img resize ubuntu12-04-vm1.qcow2 +10G
Image resized.
|
after resizing
mint-1 images # kvm-img info ubuntu12-04-vm1.qcow2
image: ubuntu12-04-vm1.qcow2
file format: qcow2
virtual size: 15G (16106127360 bytes)
disk size: 3.9G
cluster_size: 65536
|
boot gparted to resize /dev/vda1
on the KVM host , start virt-manager and edit the VM settings
go to boot options. boot from CD-ROM
mount gparted iso to boot gparted.
boot the VM
delete swap partition ( /dev/vda2 ) which is next to /dev/vda1.
To resize /dev/vda1 , unallocated space needs to be next to /dev/vda1.
delete swap ( /dev/vda2 )
resize /dev/vda1
create a swap partition
click Apply
shutdown the gprated
go to virt-manager and edit the VM configuration.
boot the VM via vHDD
I was able to resize /dev/vda1 from 3.8GB to 14GB :D
on the VM
root@ubuntu12-04-vm1:~# fdisk –l
Disk /dev/vda: 16.1 GB, 16106127360 bytes
255 heads, 63 sectors/track, 1958 cylinders, total 31457280 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0007c82d
Device Boot Start End Blocks Id System
/dev/vda1 63 28671999 14335968+ 83 Linux
/dev/vda2 28672000 31457279 1392640 82 Linux swap / Solaris
root@ubuntu12-04-vm1:~#
root@ubuntu12-04-vm1:~# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/vda1 14G 3.4G 9.5G 27% /
udev 243M 4.0K 243M 1% /dev
tmpfs 99M 228K 99M 1% /run
none 5.0M 0 5.0M 0% /run/lock
none 246M 0 246M 0% /run/shm
|
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.