大家好,又见面了,我是全栈君。
kvm常见问题总结
1.利用virt-install脚本安装guest windows 2008系统virtio和软盘版下载地址http://alt.fedoraproject.org/pub/alt/virtio-win/latest/images/bin/
http://down.51cto.com/data/745983
virt-install –arch=x86_64 –accelerate -v -n windows2008_2 -r 1024 –vcpus=3 -c /media/windows2008.iso –vnc –vncport=5903 –vnclisten=0.0.0.0 –virt-type=kvm –disk path=/dev/vg01/sys2008_2,cache=writeback,bus=virtio,device=disk –disk path=/media/virtio.vfd,device=floppy -w bridge:br1,model=virtio –soundhw=ac97 –video=cirrus –os-type=’windows’ –os-variant=win2k8 –connect qemu:///system
2.启动进入安装程序以后会发现找不到硬盘
此时选择Load Driver或者加载驱动,选择从软盘加载。 注意选择的驱动和Windows版本要匹配。 装好驱动以后,硬盘就出来了。
3.增加宿主机/dev/vg01/sys2008_2 逻辑卷标空间
[root@SN-test01 ~]# lvresize -L +100G /dev/vg01/sys2008_2 //利用lvresiz增加100G空间,如果要减少就-100G即可,增加后关闭虚拟机然后重启就可以看见多出一个扩展分区出来。
Extending logical volume sys2008_2 to 100.00 GiB
Logical volume sys2008_2 successfully resized
4.[root@SN-test01 ~]# virsh list
Id Name State
—————————————————-
18 windows2008_2 running
[root@SN-test01 ~]# virsh shutdown 18
[root@SN-test01 ~]# virsh start windows2008_2
5.进入系统windows2008系统开始菜单运行中diskpart工具扩展逻辑卷
list disk
select disk number(磁盘号)
list partition
select volume number(磁盘号)
extend
6.挂载光驱和弹出光驱
[root@SN-test01 ~]# virsh
virsh # domblklist windows2008_2 //查看虚拟机块设备。
Target Source
————————————————
vda /dev/vg01/sys2008_2
fda /media/virtio.vfd
hdc /media/windows2008.iso
virsh #change-media windows2008_2 –eject /media/windows2008.iso
virsh # change-media –domain windows2008_2 hdc /media/virtio.iso
succeeded to complete action update on media
7.虚拟机windows2008_2添加第二块硬盘和添加第二块网卡
[root@SN-test01 ~]#lvcreate -L 10G /dev/vg01/sys2008_2_1 //创建一个sys2008_2_1的逻辑卷
[root@SN-test01 ~]# virsh
virsh # domblklist windows2008_2 //查看虚拟机块设备。
Target Source
————————————————
vda /dev/vg01/sys2008_2
fda /media/virtio.vfd
hdc /media/windows2008.iso
virsh # attach-disk windows2008_2 /dev/vg01/sys2008_2_1 vdb //添加一块10G的硬盘进去即使生效。但是虚拟机配置文件不会添加,重启后就没了,如果要将运行状态保存至XML文件中,可以用dumpxml命令,用之前最好将XML做个备份。
virsh dumpxml windows2008_2>/root/windows2008_2.xml //备份xml到当前目录
[root@SN-test01 ~]# virsh dumpxml windows2008_2>/etc/libvirt/qemu/windows2008_2.xml //覆盖原有的xml
virsh # define windows2008_2.xml //定义生效下次关机重启生效。
Domain windows2008_2 defined from windows2008_2.xml
virsh # domblklist windows2008_2
Target Source
————————————————
vda /dev/vg01/sys2008_2
vdb /dev/vg01/sys2008_2_1//多出来的10G硬盘去windows2008磁盘管理格式化即可。
fda /media/virtio.vfd
hdc /media/windows2008.iso
virsh # domiflist windows2008_2 //查看网卡信息
Interface Type Source Model MAC
——————————————————-
vnet2 bridge br1 virtio 52:54:00:fa:6b:a1
virsh # attach-interface windows2008_2 –type bridge –source br2 –mac 52:54:00:fa:6b:a2 –model virtio//默认不加–model参数是瑞昱的8139网卡临时生效重启后不失效,关机重新加载配置文件后会丢失网卡。
Interface attached successfully
virsh # domiflist windows2008_2
Interface Type Source Model MAC
——————————————————-
vnet2 bridge br1 virtio 52:54:00:fa:6b:a1
vnet3 bridge br2 – 52:54:00:60:c1:f3 //新增加网卡br2
vnet2 bridge br1 virtio 52:54:00:fa:6b:a2//为virtio网卡
[root@SN-test01 ~]# virsh dumpxml windows2008_2>/etc/libvirt/qemu/windows2008_2.xml //更新xml文件
[root@SN-test01 ~]# virsh
virsh # define windows2008_2.xml //定义生效下次关机重启生效undefine id删除虚拟机,destroy id或者名字.
Domain windows2008_2 defined from windows2008_2.xml
8.[root@SN-test01 ~]# virt-top //查看虚拟机使用情况
virt-top 14:33:35 – x86_64 24/24CPU 1999MHz 32059MB 1.1%
3 domains, 3 active, 3 running, 0 sleeping, 0 paused, 0 inactive D:0 O:0 X:0
CPU: 1.1% Mem: 3072 MB (3072 MB by guests)
ID S RDRQ WRRQ RXBY TXBY %CPU %MEM TIME NAME
22 R 0 7 7886 0 0.4 3.0 1:13.25 windows2008_2
9.删除网卡和磁盘
virsh # detach-interface windows2008_2 –type bridge –mac 52:54:00:fa:6b:a2 //临时删除网卡
Interface detached successfully
virsh # domiflist windows2008_2 //查看虚拟机2008网卡资源
Interface Type Source Model MAC
——————————————————-
vnet2 bridge br1 virtio 52:54:00:fa:6b:a1
virsh # detach-disk windows2008_2 /dev/vg01/sys2008_2_1 //临时删除添加的磁盘vdb
Disk detached successfully
virsh # domblklist windows2008_2 //查看虚拟机2008网卡资源
Target Source
————————————————
vda /dev/vg01/sys2008_2
fda /media/virtio.vfd
hdc –
[root@SN-test01 ~]# virsh dumpxml windows2008_2>/etc/libvirt/qemu/windows2008_2.xml //覆盖文件最好首先备份一下xml以免出错。
[root@SN-test01 ~]# virsh define /etc/libvirt/qemu/windows2008_2.xml
Domain windows2008_2 defined from /etc/libvirt/qemu/windows2008_2.xml//重新定义windows2008_2.xml配置文件下次重新关机重启生效。
9.[root@SN-test01 ~]# cat /etc/libvirt/qemu/windows2008_2.xml //windows2008_2虚拟机配置文件如下:
<domain type=’kvm’ id=’21’>
<name>windows2008_2</name>
<uuid>f10a5009-b73d-fdb8-5519-4e46cd548100</uuid>
<memory unit=’KiB’>1048576</memory>
<currentMemory unit=’KiB’>1048576</currentMemory>
<vcpu placement=’static’>3</vcpu>
<os>
<type arch=’x86_64′ machine=’rhel6.4.0′>hvm</type>
<boot dev=’hd’/>
</os>
<features>
<acpi/>
<apic/>
<pae/>
</features>
<clock offset=’localtime’>
<timer name=’rtc’ tickpolicy=’catchup’/>
</clock>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>restart</on_crash>
<devices>
<emulator>/usr/libexec/qemu-kvm</emulator>
<disk type=’block’ device=’disk’>
<driver name=’qemu’ type=’raw’ cache=’writeback’ io=’native’/>
<source dev=’/dev/vg01/sys2008_2’/>
<target dev=’vda’ bus=’virtio’/>
<alias name=’virtio-disk0’/>
<address type=’pci’ domain=’0x0000′ bus=’0x00′ slot=’0x05′ function=’0x0’/>
</disk>
<disk type=’block’ device=’disk’>
<driver name=’qemu’ type=’raw’/>
<source dev=’/dev/vg01/sys2008_2_1’/> //添加的第二块磁盘
<target dev=’vdb’ bus=’virtio’/>//设备总线为virtio模式
<alias name=’virtio-disk1’/> //为磁盘1
<address type=’pci’ domain=’0x0000′ bus=’0x00′ slot=’0x07′ function=’0x0’/>
</disk>
<disk type=’file’ device=’floppy’> //定义软驱
<driver name=’qemu’ type=’raw’ cache=’none’/>
<source file=’/media/virtio.vfd’/>
<target dev=’fda’ bus=’fdc’/>
<alias name=’fdc0-0-0’/>
<address type=’drive’ controller=’0′ bus=’0′ target=’0′ unit=’0’/>
</disk>
<disk type=’file’ device=’cdrom’>//定义cdrom
<driver name=’qemu’ type=’raw’/>
<target dev=’hdc’ bus=’ide’ tray=’open’/>
<readonly/>
<alias name=’ide0-1-0’/>
<address type=’drive’ controller=’0′ bus=’1′ target=’0′ unit=’0’/>
</disk>
<controller type=’usb’ index=’0′>
<alias name=’usb0’/>
<address type=’pci’ domain=’0x0000′ bus=’0x00′ slot=’0x01′ function=’0x2’/>
</controller>
<controller type=’fdc’ index=’0′>
<alias name=’fdc0’/>
</controller>
<controller type=’ide’ index=’0′>
<alias name=’ide0’/>
<address type=’pci’ domain=’0x0000′ bus=’0x00′ slot=’0x01′ function=’0x1’/>
</controller>
<interface type=’bridge’> //定义桥接
<mac address=’52:54:00:fa:6b:a1’/> //定义mac物理地址
<source bridge=’br1’/>//桥接到br1上
<target dev=’vnet2’/>//虚拟机网卡为vnet2
<model type=’virtio’/>//网卡类型为1000m网卡
<alias name=’net0’/>//第一块网卡
<address type=’pci’ domain=’0x0000′ bus=’0x00′ slot=’0x03′ function=’0x0’/>//局部总线地址
</interface>
<interface type=’bridge’>//第二块网卡定义
<mac address=’52:54:00:fa:6b:a2’/>
<source bridge=’br1’/>
<target dev=’vnet3’/>
<model type=’virtio’/>
<alias name=’net1’/>
<address type=’pci’ domain=’0x0000′ bus=’0x00′ slot=’0x08′ function=’0x0’/>
</interface>
<serial type=’pty’>
<source path=’/dev/pts/4’/>
<target port=’0’/>
<alias name=’serial0’/>
</serial>
<console type=’pty’ tty=’/dev/pts/4′>
<source path=’/dev/pts/4’/>
<target type=’serial’ port=’0’/>
<alias name=’serial0’/>
</console>
<input type=’tablet’ bus=’usb’>
<alias name=’input0’/>
</input>
<input type=’mouse’ bus=’ps2’/>
<graphics type=’vnc’ port=’5903′ autoport=’no’ listen=’0.0.0.0′>
<listen type=’address’ address=’0.0.0.0’/>
</graphics>
<sound model=’ac97′>
<alias name=’sound0’/>
<address type=’pci’ domain=’0x0000′ bus=’0x00′ slot=’0x04′ function=’0x0’/>
</sound>
<video>
<model type=’cirrus’ vram=’9216′ heads=’1’/>
<alias name=’video0’/>
<address type=’pci’ domain=’0x0000′ bus=’0x00′ slot=’0x02′ function=’0x0’/>
</video>
<memballoon model=’virtio’>
<alias name=’balloon0’/>
<address type=’pci’ domain=’0x0000′ bus=’0x00′ slot=’0x06′ function=’0x0’/>
</memballoon>
</devices>
<seclabel type=’dynamic’ model=’selinux’ relabel=’yes’>
<label>system_u:system_r:svirt_t:s0:c50,c772</label>
<imagelabel>system_u:object_r:svirt_image_t:s0:c50,c772</imagelabel>
</seclabel>
</domain>
本文转自zh888 51CTO博客,原文链接:http://blog.51cto.com/zh888/1175476,如需转载请自行联系原作者
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/107954.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...