V: KVM Virtual machine Disk expansion
Two different ways:
1. Add a new virtual disk
2. Expansion of the original disk capacity size
Attention:
Disk snapshots and disk dynamic scaling are supported only for disks with a disk format of Qcow2.
Test the virtual machine disk size and format.
Method One: Add a new disk
1. View the size of an existing disk
[[email protected] vm]# qemu-img info api1-qcow2.img image:api1-qcow2.imgfile format:qcow2virtual size:8.0g (8589934 592 bytes) Disk size:1.5gcluster_size:65536
<disk type= ' file ' device= ' disk ' > <driver name= ' qemu ' type= ' qcow2 ' cache= ' None '/> <source file= '/V M/api1-qcow2.img '/> <target dev= ' vda ' bus= ' virtio '/> <address type= ' pci ' domain= ' 0x0000 ' bus= ' 0x00 ' slot= ' 0x05 ' function= ' 0x0 '/> </disk>
2. Add a Qcow2 disk with a size of 10G
CD/VM && qemu-img create-f qcow2 api1-qcow2_add1.img 8G
[Email protected] vm]# qemu-img info api1-qcow2_add1.img image:api1-qcow2_add1.imgfile format:qcow2virtual size:10g (10737418240 bytes) disk size:140kcluster_size:65536
[[email protected] vm]# LL/VM total dosage 3161404-rwxr-xr-x 1 qemu qemu 1580662784 January 14:55 api2-qcow2.img-rw-r--r--1 root Root 197120 January 14:53 api1-qcow2_add1.img-rw-r--r--1 qemu qemu 1653407744 January one 14:55 api1-qcow2.img
3. Add api1-qcow2_add1.img to the configuration file
[[email protected] vm]# virsh shutdown api1 Domain Api4 was closed
[[email protected] vm]# Virsh list--all Id name status--------------------------------------------- -------2 api2 running-api1 off
Virsh edit Api1, add a new disk
<disk type= ' file ' device= ' disk ' > <driver name= ' qemu ' type= ' qcow2 ' cache= ' None '/> <source file= '/V M/api1-qcow2_add1.img '/> <target dev= ' vdb ' bus= ' virtio '/></disk>
4. Log in to the API1 terminal, then view, and partition/dev/vdb
[Email protected] ~]# fdisk-ldisk/dev/vdb:8589 MB, 8589934592 bytes16 heads, + sectors/track, 16644 cylindersunits = Cylinders of 1008 * 516096 = bytessector size (logical/physical): bytes/512 bytesi/o size (minimum/optimal): 51 2 bytes/512 Bytesdisk identifier:0x00000000
5. Format the partition/dev/vdb and convert to LVM format.
Fdisk/dev/vdb >> LVM
[[email protected] ~]# fdisk -ldisk /dev/ vdb: 8589 mb, 8589934592 bytes16 heads, 63 sectors/track, 16644 Cylindersunits = cylinders of 1008 * 512 = 516096 bytessector size (logical/physical): 512 bytes / 512 bytesi/o size (minimum/ Optimal): 512 bytes / 512 bytesdisk identifier: 0xa91642d5 Device Boot Start End Blocks Id System/dev/vdb1 1 &NBSP;&NBSP;&NBSP;16644&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;8388544+&NBSP;&NBSP;8E&NBSP;&NBSP;LINUX&NBSP;LVM
[Email protected] ~]# pvcreate/dev/vdb1 physical Volume "/DEV/VDB1" successfully created
[[email protected] ~]# VGS VG #PV #LV #SN Attr vsize vfree VolGroup 1 2 0 wz--n-7.51g 0
[Email protected] ~]# vgextend volgroup/dev/vdb1 Volume Group "VolGroup" successfully extended
[[email protected] ~]# lvs lv VG Attr lsize pool origin data% meta% move log cpy% Sync convert lv_root volgroup -wi-ao---- 6.71g lv_swap Volgroup -wi-ao---- 816.00m
[[email protected] ~]# lvextend -l +100% Free /dev/volgroup/lv_root size of logical volume volgroup/lv_ root changed from 6.71 gib (1718 extents) to 14.71 GiB (3765 extents). logical volume lv_root successfully resized
[Email protected] ~]# resize2fs/dev/volgroup/lv_rootresize2fs 1.41.12 (17-may-2010) Filesystem at/dev/volgroup/lv_ Root is mounted on/; On-line resizing Requiredold desc_blocks = 1, new_desc_blocks = 1Performing A on-line resize of/dev/volgroup/lv_root to 3855360 (4k) blocks. The filesystem on/dev/volgroup/lv_root is now 3855360 blocks long.
6. Check the disk size of the VM again
[Email protected] ~]# df-hfilesystem Size used Avail use% mounted On/dev/mapper/volgroup-lv_root 15G 652M 13G 5%/tmpfs 246M 0 246M 0%/dev/shm/dev/vda1 477M 25M 427 M 6%/boot
Method Two: Expand the size of the original disk
1. View the size of the original disk
[[Email protected] vm]# qemu-img info /vm/api2-qcow2.img image: /vm/api2-qcow2.imgfile format: qcow2virtual size: 8.0G (8589934592 bytes) disk size: 2.4gcluster_size: 65536snapshot list:id TAG VM SIZE DATE VM CLOCK2 api2_ftp 320M 2016-01-08 16:59:52 01:17:18.6393 api2_httpd 385m 2016-01-08 17:27:16 00:53:48.096
2. Close the VM, and then expand the api2-qcow2.img directly
[Email protected] vm]# Virsh shutdown api2
Domain API2 is closed
[[email protected] vm]# virsh list --all Id name Status---------------------------------------------------- 3 api1 running - api2 Close
[[email protected] vm]# qemu-img resize api2-qcow2.img +8GThis image format does not support resize //prompt cannot extend
for this format does not support
[[email protected] vm]# virsh welcomes the use of virsh, a virtualized interactive terminal. Input: ' Help ' to get the command information ' quit ' exit virsh # snapshot-list api2 name Creation Time Status------------------------------------------------------------ api2_ftp 2016-01-08 16:59:52 +0800 running api2_httpd 2016-01-08 17:27:16 + 0800 runningvirsh # snapshot-delete apiapi1-qcow2_add1.img api1-qcow2.img api2-qcow2.img virsh # snapshot-delete api2 api2_ftpDomain snapshot api2_ftp deletedvirsh # snapshot-delete api2 api2_httpddomain snapshot api2_httpd deleted
[Email protected] vm]# qemu-img resize api2-qcow2.img +8gimage resized.
3. View the disks that have been expanded
[[email protected] vm]# qemu-img info api2-qcow2.img image:api2-qcow2.imgfile format:qcow2virtual size:16g (171798 69184 bytes) disk size:2.4gcluster_size:65536
4. Start the VM, then partition, and format
[[email protected] vm]# virsh start api2 domain Api2 started
[Email protected] ~]# Pvcreate/dev/vda3 physical Volume "/dev/vda3" successfully created
[[email protected] ~]# VGS VG #PV #LV #SN Attr vsize vfree VolGroup 1 2 0 wz--n-7.51g 0
[Email protected] ~]# vgextend volgroup/dev/vda3 Volume Group "VolGroup" successfully extended
[Email protected] ~]# lvextend-l +100%free/dev/volgroup/lv_root Size of Logical volume Volgroup/lv_root changed FR Om 6.71 GIB (1718 extents) to 14.71 Gib (3765 extents). Logical Volume Lv_root successfully resized
[Email protected] ~]# resize2fs/dev/volgroup/lv_rootresize2fs 1.41.12 (17-may-2010) Filesystem at/dev/volgroup/lv_ Root is mounted on/; On-line resizing Requiredold desc_blocks = 1, new_desc_blocks = 1Performing A on-line resize of/dev/volgroup/lv_root to 3855360 (4k) blocks. The filesystem on/dev/volgroup/lv_root is now 3855360 blocks long.
[Email protected] ~]# df-hfilesystem Size used Avail use% mounted On/dev/mapper/volgroup-lv_root 15G 655M 13G 5%/tmpfs 246M 0 246M 0%/dev/shm/dev/vda1 477M 25M 427 M 6%/boot
The disk was successfully added.
This article from the "Do not ask for the best, only better" blog, please be sure to keep this source http://yujianglei.blog.51cto.com/7215578/1733873
KVM Summary Document II (CentOS-6.5)