之后出现 “No bootable device."这种情况
需要在xml里面定义<bootmenu enable='yes'/>
例如
<os> <type>hvm</type> <loader>/usr/lib/xen/boot/hvmloader</loader> <boot dev='network'/> <boot dev='cdrom'/> <boot dev='hd'/> <bootmenu enable='yes'/> </os>
修改配置文件配置桥接
使用的操作系统为红帽6.5
/etc/sysconfig/network-scripts
注意桥接的TYPE是Bridge,大小写注意
注意修改后要
service NetworkManager stop
service network restart
iptables -L
iptables -F
setenforce 0
[root@rhel65 network-scripts]# cat ifcfg-br0 DEVICE=br0 TYPE=Bridge ONBOOT=yes NM_CONTROLLED=yes BOOTPROTO=static IPADDR=192.168.137.41 NETMASK=255.255.255.0 GATEWAY=192.168.137.1 [root@rhel65 network-scripts]# cat ifcfg-eth0 DEVICE=eth0 TYPE=Ethernet ONBOOT=yes NM_CONTROLLED=yes BOOTPROTO=none BRIDGE=br0 [root@rhel65 network-scripts]# 建立后是这样 [root@rhel65 network-scripts]# ifconfig br0 Link encap:Ethernet HWaddr 00:0C:29:15:24:FE inet addr:192.168.137.41 Bcast:192.168.137.255 Mask:255.255.255.0 inet6 addr: fe80::20c:29ff:fe15:24fe/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:245 errors:0 dropped:0 overruns:0 frame:0 TX packets:21 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:18987 (18.5 KiB) TX bytes:3398 (3.3 KiB) eth0 Link encap:Ethernet HWaddr 00:0C:29:15:24:FE inet6 addr: fe80::20c:29ff:fe15:24fe/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:2804971 errors:0 dropped:0 overruns:0 frame:0 TX packets:1305100 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:4049756104 (3.7 GiB) TX bytes:88229516 (84.1 MiB) lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:16436 Metric:1 RX packets:12 errors:0 dropped:0 overruns:0 frame:0 TX packets:12 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:720 (720.0 b) TX bytes:720 (720.0 b) virbr0 Link encap:Ethernet HWaddr 52:54:00:C6:19:77 inet addr:192.168.122.1 Bcast:192.168.122.255 Mask:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:0 (0.0 b) TX bytes:0 (0.0 b) [root@rhel65 network-scripts]#
实用libvirt建立虚拟机,网络并使vm用tap的桥接访问外网百度
定义libvirt的xml文件
[root@haoning172 opt]# virsh dumpxml centos <domain type='kvm'> <name>centos</name> <uuid>d07d7290-9b1d-f33e-f54a-70a82125242e</uuid> <memory unit='KiB'>1048576</memory> <currentMemory unit='KiB'>1048576</currentMemory> <vcpu placement='static'>1</vcpu> <os> <type arch='x86_64' machine='rhel6.5.0'>hvm</type> <boot dev='hd'/> <bootmenu enable='yes'/> </os> <features> <acpi/> <apic/> <pae/> </features> <clock offset='utc'/> <on_poweroff>destroy</on_poweroff> <on_reboot>restart</on_reboot> <on_crash>restart</on_crash> <devices> <emulator>/usr/libexec/qemu-kvm</emulator> <disk type='file' device='disk'> <driver name='qemu' type='raw' cache='none'/> <source file='/opt/centos.img'/> <target dev='vda' bus='virtio'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/> </disk> <disk type='file' device='cdrom'> <driver name='qemu' type='raw'/> <source file='/opt/CentOS-6.5-x86_64.iso'/> <target dev='hdc' bus='ide'/> <readonly/> <address type='drive' controller='0' bus='1' target='0' unit='0'/> </disk> <controller type='usb' index='0'> <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/> </controller> <controller type='ide' index='0'> <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/> </controller> <interface type='bridge'> <mac address='52:54:00:aa:90:80'/> <source bridge='br0'/> <model type='virtio'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/> </interface> <serial type='pty'> <target port='0'/> </serial> <console type='pty'> <target type='serial' port='0'/> </console> <input type='mouse' bus='ps2'/> <graphics type='vnc' port='5900' autoport='no' listen='0.0.0.0'> <listen type='address' address='0.0.0.0'/> </graphics> <sound model='ich6'> <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/> </sound> <video> <model type='cirrus' vram='9216' heads='1'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/> </video> <memballoon model='virtio'> <address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/> </memballoon> </devices> </domain>
qemu-img create -f qcow2 rhel_qcow2.img 10G
如果是ubuntu可能有个事不兼容额问题
qemu-img amend -f qcow2 -o compat=0.10 rhel_qcow2.img
参考 http://blog.csdn.net/bluesy2008/article/details/49079125
virsh define rhel
virsh dumpxml rhel
virsh edit rhel
virsh start rhel
装好系统后
在vm中使用
ifconfig eth0 192.168.137.44 netmask 255.255.255.0
route add default gw 192.168.137.1
vim /etc/resolv.conf
ping www.baidu.com
在主机上
virsh list
virsh vncdisplay 1
virsh destroy 1
redhat7.1上建立vm
[root@localhost ~]# cat qemu.sh #!/bin/sh /usr/libexec/qemu-kvm -m 2048 -enable-kvm /opt/rhel.qcow2 -cdrom /opt/rhel-server-6.5-x86_64-dvd.iso -vnc 192.168.137.100:1 -daemonize [root@localhost ~]# cat net.sh #!/bin/sh brctl addbr br0 brctl addif br0 p4p1 brctl stp br0 on ifconfig p4p1 0 dhclient br0 ifconfig br0 192.168.137.100 netmask 255.255.255.0 route add default gw 192.168.137.1 br0 route -n [root@localhost ~]#