标签:kvm
关联新的块设备到KVM的虚拟机,运行以下命令root@kvm:~# dd if=/dev/zero of=/tmp/new_disk.img bs=1M count=1024
1024+0 records in
1024+0 records out
1073741824 bytes (1.1 GB) copied, 0.670831 s, 1.6 GB/s
root@kvm:~# virsh attach-disk kvm1 /tmp/new_disk.img vda --live
Disk attached successfully
root@kvm:~# virsh console kvm1
Connected to domain kvm1
Escape character is ^]
Debian GNU/Linux 8 debian ttyS0
debian login: root
Password:
...
root@debian:~# dmesg | grep vda
[ 3664.134978] sd 2:0:2:0: [vda] 2097152 512-byte logical blocks: (1.07 GB/1.00 GiB)
[ 3664.135248] sd 2:0:2:0: [vda] Write Protect is off
[ 3664.135251] sd 2:0:2:0: [vda] Mode Sense: 63 00 00 08
[ 3664.135340] sd 2:0:2:0: [vda] Write cache: enabled, read cache: enabled, doesn‘t support DPO or FUA
[ 3664.138254] vda: unknown partition table
[ 3664.139008] sd 2:0:2:0: [vda] Attached SCSI disk
root@debian:~# fdisk -l /dev/vda
Disk /dev/vda: 1 GiB, 1073741824 bytes, 2097152 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
root@kvm:~# virsh dumpxml kvm1
<domain type=‘kvm‘ id=‘23‘>
...
<devices>
<emulator>/usr/bin/qemu-system-x86_64</emulator>
<disk type=‘file‘ device=‘disk‘>
<driver name=‘qemu‘ type=‘raw‘/>
<source file=‘/tmp/kvm1.img‘/>
<target dev=‘hda‘ bus=‘ide‘/>
<alias name=‘ide0-0-0‘/>
<address type=‘drive‘ controller=‘0‘ bus=‘0‘ target=‘0‘ unit=‘0‘/>
</disk>
<disk type=‘file‘ device=‘disk‘>
<driver name=‘qemu‘ type=‘raw‘/>
<source file=‘/tmp/new_disk.img‘/>
<target dev=‘vda‘ bus=‘scsi‘/>
<alias name=‘scsi0-0-2‘/>
<address type=‘drive‘ controller=‘0‘ bus=‘0‘ target=‘0‘ unit=‘2‘/>
</disk>
</devices>
</domain>
root@kvm:~# virsh domblkstat kvm1 vda
vda rd_req 119
vda rd_bytes 487424
vda wr_req 0
vda wr_bytes 0
vda flush_operations 0
vda rd_total_times 29149092
vda wr_total_times 0
vda flush_total_times 0
root@kvm:~# virsh detach-disk kvm1 vda --live
Disk detached successfully
root@kvm:~# cp /tmp/new_disk.img /tmp/other_disk.img
root@kvm:~# cat other_disk.xml
<disk type=‘file‘ device=‘disk‘>
<driver name=‘qemu‘ type=‘raw‘ cache=‘none‘/>
<source file=‘/tmp/other_disk.img‘/>
<target dev=‘vdb‘/>
</disk>
root@kvm:~# virsh attach-device kvm1 --live other_disk.xml
Device attached successfully
root@kvm:~# virsh detach-device kvm1 other_disk.xml --live
Device detached successfully
标签:kvm
原文地址:http://blog.51cto.com/aishangwei/2124525