KVM如何在线添加新硬盘:

1)新建一个qcow2格式的大小为5G,磁盘名称为centos67_add.qcow2的磁盘

[root@kvm-server01 ~]# cd /kvmdata/
[root@kvm-server01 kvmdata]# ls
centos67.qcow2  win2003.qcow2
[root@kvm-server01 kvmdata]# qemu-img create -f qcow2 centos67_add.qcow2 5G
Formatting 'centos67_add.qcow2', fmt=qcow2 size=5368709120 encryption=off cluster_size=65536

2)查看磁盘的详细信息

[root@kvm-server01 kvmdata]# qemu-img info centos67_add.qcow2 
p_w_picpath: centos67_add.qcow2
file format: qcow2
virtual size: 5.0G (5368709120 bytes)
disk size: 136K
cluster_size: 65536

3)将磁盘附加到虚拟机centos67中

[root@kvm-server01 kvmdata]# virsh attach-disk centos67 /kvmdata/centos67_add.qcow2 vda --cache=none --subdriver=qcow2
Disk attached successfully

4)在虚拟机中进行验证

[root@centos67-mini ~]# fdisk -l
Disk /dev/sda: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0007bea2
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          64      512000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              64        1306     9972736   8e  Linux LVM
Disk /dev/mapper/VolGroup-lv_root: 9168 MB, 9168748544 bytes
255 heads, 63 sectors/track, 1114 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Disk /dev/mapper/VolGroup-lv_swap: 1040 MB, 1040187392 bytes
255 heads, 63 sectors/track, 126 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Disk /dev/vda: 5368 MB, 5368709120 bytes
16 heads, 63 sectors/track, 10402 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

注:再次说明只有RHEL/CentOS/OEL6.x及高版本的在线添加磁盘,虚拟机直接可以在线识别。