Tag Archives: QEMU-KVM

Building virtual machine environment based on kvm-qemu under ubuntu12.10 (12)

In addition to the initial mounting of the optical drive in the definition file of the virtual machine, Libvirt also has a dynamic platter mount method, which USES the Attach -device command in the virsh command. The format of this command is as follows:

dev@devhost:/opt/vm/xpvm1$sudo virsh attach-device < domain-name> filename

Where filename is a file defined in XML format (we’ll call it Disk.xml) :

< Disk type = “file” device = “cdrom” & gt; < The source file = “/ opt/vm/drivers. Iso/& gt;” < Target HDC dev = “”/& gt; < readonly/> < /disk>

The virtual machine was originally mounted ona CD-ROM called Windows_xp_professional_sp3_x89.ISO:

< domain type=’kvm’> & lt; name> XP_VM< /name> & lt; uuid> 91f15b08-e115-4016-a522-b550ff593af9< /uuid> & lt; memory> 1024000< /memory> & lt; currentMemory> 1024000< /currentMemory> & lt; vcpu> 1< /vcpu> & lt; os> & lt; Type the arch = ‘x86_64 machine =’ PC ‘& gt; hvm< /type> & lt; boot dev=’hd’/> & lt; boot dev=’cdrom’/> & lt; Bootmenu enable = ‘yes’/& gt; & lt; /os> & lt; features> & lt; acpi/> & lt; apic/> & lt; pae/> & lt; /features> & lt; cpu> & lt; The topology sockets = ‘1’ cores = ‘1’ threads = ‘1’/& gt; & lt; /cpu> & lt; = ‘localtime’ clock offset/& gt; & lt; on_poweroff> destroy< /on_poweroff> & lt; on_reboot> restart< /on_reboot> & lt; on_crash> restart< /on_crash> & lt; devices> & lt; emulator> /usr/bin/qemu-system-x86_64< /emulator> & lt; = ‘disk disk type =’ file ‘device’ & gt; & lt; Qemu driver name = ‘ ‘type =’ qcow2 ‘/ & gt; & lt; The source file = ‘/ opt/vm/xpvm1 xp_c. Img’ lock = ‘exclusive’/& gt; & lt; Target dev = ‘hda bus =’ ide ‘/ & gt; & lt; /disk> & lt; = ‘disk disk type =’ file ‘device’ & gt; & lt; Qemu driver name = ‘ ‘type =’ qcow2 ‘/ & gt; & lt; The source file = ‘/ opt/vm/xpvm1 xp_d. Img’ lock = ‘exclusive’/& gt; & lt; target dev=’hdb’ bus=’ide’/> & lt; /disk> & lt; = ‘cdrom disk type =’ file ‘device’ & gt; & lt; source file=’/opt/vm/windows_xp_professional_sp3_x86.iso’/> & lt; target dev=’hdc’/> & lt; readonly/> & lt; /disk> & lt; The channel type = ‘spicevmc & gt; & lt; Target type = ‘virtio’ name = ‘com. Redhat. Spice. 0’/& gt; & lt; Alias name = ‘virserial – channel1’/& gt; & lt; /channel> & lt; Interface type = ‘bridge’ & gt; & lt; MAC address = ’52:54:00:7 b: a8: d8’/& gt; & lt; The source bridge = ‘virbr0/& gt; & lt; = ‘vnet1’ target dev/& gt; & lt; The model type = ‘virtio/& gt; & lt; /interface> & lt; Input type = ‘tablet’ bus = ‘usb’/& gt; & lt; Graphics type=’spice’ port=’4000′ autoport=’no’ listen=’0.0.0.0′> & lt; Listen type = ‘address’ address = ‘0.0.0.0’/& gt; & lt; Agent_mouse mode = ‘off’/& gt; & lt; /graphics> & lt; Memballoon model = ‘virtio & gt; & lt; alias name=’balloon0’/> & lt; /memballoon> & lt; Sound model = ‘ac97 & gt; & lt; Address type=’ PCI ‘domain=’0x0000′ bus=’0x00′ slot=’0x04’ function=’0x0’/> & lt; /sound> & lt; video> & lt; The model type = ‘QXL vram =’ 65536 ‘heads =’ 1 ‘/ & gt; & lt; /video> & lt; /devices> & lt; qemu:commandline> & lt; Qemu: arg value = “-” CPU/& gt; & lt; Qemu: arg value = “kvm64″/& gt; & lt; /qemu:commandline> < /domain>

 
After installing the system, what you see in the virtual machine is:

 
Instead of re-closing and defining a new disc file, we can change the disc using the Virsh Attach – Device command:
 

dev@devhost:/opt/vm/xpvm1$sudo virsh attaching -device XP_VM disk.xml

 

The advantage of doing this is that in some cases we can achieve the effect of a hot plug disc without having to restart the virtual machine.
Note: It should be noted that, after testing, there must first be an initial optical device in the defined XML, otherwise the execution of another optical device will fail: internal Error No device with bus ‘ide’ and target ‘HDC’ reported error.
That is, this is actually a swap, not a dynamic mount, and the cd-ROM device itself must be defined in XML before the virtual machine can be started.