Linux virtual machines on KVM use virtio disks

Source: Internet
Author: User

Linux virtual machines on KVM use virtio disks

System: centos6.6 64-bit

There are few articles on the net, how to change the disk of Linux virtual machine to use Virtio disk

Because the CENTOS6 or above system already contains the Virtio driver, there is no need to execute the following statement to load the kernel module

modprobe virtio  virtio_pci  virtio_blk  virtio_netmkinitrd  --with  virtio  --with  Virtio_pci   --with  virtio_blk   --with  virtio_net  -F boot/initrd-$ (uname - r). IMG  $ (uname -R)

Here's a concrete way.

On the physical machine, Sir, a virtual machine.


1. Install a Linux machine
Qemu-img create-f Qcow2/data/kvmimg/gzxtest04.qcow2 30G

Virt-install--name=gzxtest04--ram 4096--vcpus=8--autostart--HVM \
--disk path=/data/kvmimg/gzxtest04.qcow2,size=60,format=qcow2 \
--cdrom/data/download/centos-6.6-x86_64-bin-dvd1.iso \
--graphics vnc,listen=0.0.0.0,port=5907 \
--network bridge=br0,model=e1000--force--connect Qemu:///system

2. Start the virtual machine and install the centos6.6 system.

3. After installing the system, turn off the virtual machine using the Poweroff command.

4. Back up the virtual machine's XML file first

Virsh dumpxml gzxtest04 > ~/gzxtest04.xml  

5. Modify the virtual machine's XML file

Virsh Edit gzxtest04

<disk type= ' file ' device= ' disk ' >
<driver name= ' qemu ' type= ' qcow2 ' cache= ' None '/>
<source file= '/data/kvmimg/gzxtest04.qcow2 '/>
<target dev= ' hda ' bus= ' ide '/>
<alias name= ' ide0-0-0 '/>
<address type= ' drive ' controller= ' 0 ' bus= ' 0 ' target= ' 0 ' unit= ' 0 '/>
</disk>

Revision changed to
<disk type= ' file ' device= ' disk ' >
<driver name= ' qemu ' type= ' qcow2 ' cache= ' none ' io= ' native '/>
<source file= '/data/kvmimg/gzxtest04.qcow2 '/>
<target dev= ' Vda ' bus= ' Virtio '/>
</disk>

In fact, delete address type this line, in driver name this line add io= ' native ', dev= ' hda ' changed to VDA, bus= ' IDE ' changed to Virtio

6. Start the virtual machine

Virsh Start gzxtest04

7, in the virtual machine can see that the original HDX partition has all become VDX

8. Modify the Grub Device mapping table in the virtual machine

sed -i  "S/hda/vda"  

Done

Background knowledge
Caching mode for KVM virtual machine disks
1, default, do not specify the cache mode, 1.2 version QEMU-KVM before the writethough,1.2 version QEMU-KVM, CentOS virtual machine default cache mode is None
2. Writethough: Using O_dsync semantics
3, writeback: not o_dsync semantics is not o_direct semantics, the virtual machine data arrives the host page caches pages cache to return to the virtual machine writes the Success report, the page cache mechanism management data merges writes the host storage device
4, none: Using O_direct semantics, I/O directly between the QEMU-KVM user space cache and the host storage device, requires I/O mode set to Aio=native, cannot use the host page cache, equivalent to direct access to the disk, has superior performance
5, unsafe: The same as writeback, but can not issue the brush disk instructions, only when the virtual machine is closed will be the data brush disk, unsafe
6. Directsync: Simultaneous use of O_dsync semantics and o_direct semantics

Data consistency in cache mode
Writethough, None, Directsync
To ensure data consistency, some file systems are incompatible with none or Directsync mode, and these file systems do not support o_direct semantics

Writeback
Data consistency cannot be guaranteed, when data reporting is completed and a real merge is written to the storage device last time window, this mode loses data when the host fails because the data still exists in the host's page cache


Unsafe
does not guarantee data consistency, ignoring the brush disk instructions, only when the virtual machine is closed will be the data brush disk, unsafe

Reference article: https://easyengine.io/tutorials/kvm/enable-virtio-existing-vms/

If there is a wrong place, welcome everyone to shoot brick O (∩_∩) o

The copyright of this article is owned by the author and cannot be reproduced without the author's consent.

Linux virtual machines on KVM use virtio disks

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.