[root@localhost ~]# yum install pciutilshtml
[root@localhost ~]# lscpu;lspcinode
Architecture: x86_64 CPU op-mode(s): 32-bit, 64-bit Byte Order: Little Endian CPU(s): 4 On-line CPU(s) list: 0-3 Thread(s) per core: 2 Core(s) per socket: 2 Socket(s): 1 NUMA node(s): 1 Vendor ID: GenuineIntel CPU family: 6 Model: 60 Model name: Intel(R) Core(TM) i3-4170 CPU @ 3.70GHz Stepping: 3 CPU MHz: 3700.000 BogoMIPS: 7399.71 Virtualization: VT-x L1d cache: 32K L1i cache: 32K L2 cache: 256K L3 cache: 3072K NUMA node0 CPU(s): 0-3 00:00.0 Host bridge: Intel Corporation 4th Gen Core Processor DRAM Controller (rev 06) 00:02.0 VGA compatible controller: Intel Corporation 4th Generation Core Processor Family Integrated Graphics Controller (rev 06) 00:03.0 Audio device: Intel Corporation Xeon E3-1200 v3/4th Gen Core Processor HD Audio Controller (rev 06) 00:14.0 USB controller: Intel Corporation 9 Series Chipset Family USB xHCI Controller 00:16.0 Communication controller: Intel Corporation 9 Series Chipset Family ME Interface #1 00:19.0 Ethernet controller: Intel Corporation Ethernet Connection I217-V 00:1a.0 USB controller: Intel Corporation 9 Series Chipset Family USB EHCI Controller #2 00:1b.0 Audio device: Intel Corporation 9 Series Chipset Family HD Audio Controller 00:1c.0 PCI bridge: Intel Corporation 9 Series Chipset Family PCI Express Root Port 1 (rev d0) 00:1c.3 PCI bridge: Intel Corporation 9 Series Chipset Family PCI Express Root Port 4 (rev d0) 00:1d.0 USB controller: Intel Corporation 9 Series Chipset Family USB EHCI Controller #1 00:1f.0 ISA bridge: Intel Corporation 9 Series Chipset Family H97 Controller 00:1f.2 RAID bus controller: Intel Corporation SATA Controller [RAID mode] 00:1f.3 SMBus: Intel Corporation 9 Series Chipset Family SMBus Controller 02:00.0 PCI bridge: Intel Corporation 82801 PCI Bridge (rev 41)
[root@localhost ~]# cat /etc/centos-release
CentOS Linux release 7.2.1511 (Core)linux
[root@localhost ~]# lsmod |grep kvm
kvm_intel 162153 3
kvm 525259 1 kvm_intel
[root@localhost ~]# ll /lib/modules/3.10.0-327.el7.x86_64/kernel/arch/x86/kvm/
total 1180
-rw-r--r--. 1 root root 104261 Nov 20 2015 kvm-amd.ko
-rw-r--r--. 1 root root 271245 Nov 20 2015 kvm-intel.ko
-rw-r--r--. 1 root root 824605 Nov 20 2015 kvm.koes6
[root@localhost ~]# yum install bridge-utils qemu-kvm
[root@localhost ~]# rpm -qa|grep kvm
qemu-kvm-common-1.5.3-105.el7_2.4.x86_64
qemu-kvm-1.5.3-105.el7_2.4.x86_64
[root@localhost ~]# /usr/libexec/qemu-kvm -version
QEMU emulator version 1.5.3 (qemu-kvm-1.5.3-105.el7_2.4), Copyright (c) 2003-2008 Fabrice Bellard
windows
[root@localhost ~]# /usr/libexec/qemu-kvm -machine ?centos
[root@localhost ~]# /usr/libexec/qemu-kvm -M ?api
Supported machines are: none empty machine pc RHEL 7.0.0 PC (i440FX + PIIX, 1996) (alias of pc-i440fx-rhel7.0.0) pc-i440fx-rhel7.0.0 RHEL 7.0.0 PC (i440FX + PIIX, 1996) (default) rhel6.6.0 RHEL 6.6.0 PC rhel6.5.0 RHEL 6.5.0 PC rhel6.4.0 RHEL 6.4.0 PC rhel6.3.0 RHEL 6.3.0 PC rhel6.2.0 RHEL 6.2.0 PC rhel6.1.0 RHEL 6.1.0 PC rhel6.0.0 RHEL 6.0.0 PC
[root@localhost ~]# /usr/libexec/qemu-kvm -cpu ?服務器
x86 qemu64 QEMU Virtual CPU version 1.5.3 x86 phenom AMD Phenom(tm) 9550 Quad-Core Processor x86 core2duo Intel(R) Core(TM)2 Duo CPU T7700 @ 2.40GHz x86 kvm64 Common KVM processor x86 qemu32 QEMU Virtual CPU version 1.5.3 x86 kvm32 Common 32-bit KVM processor x86 coreduo Genuine Intel(R) CPU T2600 @ 2.16GHz x86 486 x86 pentium x86 pentium2 x86 pentium3 x86 athlon QEMU Virtual CPU version 1.5.3 x86 n270 Intel(R) Atom(TM) CPU N270 @ 1.60GHz x86 cpu64-rhel6 QEMU Virtual CPU version (cpu64-rhel6) x86 Conroe Intel Celeron_4x0 (Conroe/Merom Class Core 2) x86 Penryn Intel Core 2 Duo P9xxx (Penryn Class Core 2) x86 Nehalem Intel Core i7 9xx (Nehalem Class Core i7) x86 Westmere Westmere E56xx/L56xx/X56xx (Nehalem-C) x86 SandyBridge Intel Xeon E312xx (Sandy Bridge) x86 Haswell Intel Core Processor (Haswell) x86 Broadwell Intel Core Processor (Broadwell) x86 Opteron_G1 AMD Opteron 240 (Gen 1 Class Opteron) x86 Opteron_G2 AMD Opteron 22xx (Gen 2 Class Opteron) x86 Opteron_G3 AMD Opteron 23xx (Gen 3 Class Opteron) x86 Opteron_G4 AMD Opteron 62xx class CPU x86 Opteron_G5 AMD Opteron 63xx class CPU x86 host KVM processor with all supported host features (only available in KVM mode) Recognized CPUID flags: pbe ia64 tm ht ss sse2 sse fxsr mmx acpi ds clflush pn pse36 pat cmov mca pge mtrr sep apic cx8 mce pae msr tsc pse de vme fpu hypervisor rdrand f16c avx osxsave xsave aes tsc-deadline popcnt movbe x2apic sse4.2|sse4_2 sse4.1|sse4_1 dca pcid pdcm xtpr cx16 fma cid ssse3 tm2 est smx vmx ds_cpl monitor dtes64 pclmulqdq|pclmuldq pni|sse3 avx512cd avx512er avx512pf smap adx rdseed avx512f mpx rtm invpcid erms bmi2 smep avx2 hle bmi1 fsgsbase 3dnow 3dnowext lm|i64 rdtscp pdpe1gb fxsr_opt|ffxsr mmxext nx|xd syscall perfctr_nb perfctr_core topoext tbm nodeid_msr tce fma4 lwp wdt skinit xop ibs osvw 3dnowprefetch misalignsse sse4a abm cr8legacy extapic svm cmp_legacy lahf_lm pmm-en pmm phe-en phe ace2-en ace2 xcrypt-en xcrypt xstore-en xstore kvm_pv_unhalt kvm_pv_eoi kvm_steal_time kvm_asyncpf kvmclock kvm_mmu kvm_nopiodelay kvmclock pfthreshold pause_filter decodeassists flushbyasid vmcb_clean tsc_scale nrip_save svm_lock lbrv npt
[root@localhost lib]# /usr/libexec/qemu-kvm -device ?網絡
Controller/Bridge/Hub devices: name "i82801b11-bridge", bus PCI name "ioh3420", bus PCI, desc "Intel IOH device id 3420 PCIE Root Port" name "pci-bridge", bus PCI, desc "Standard PCI Bridge" name "usb-host", bus usb-bus name "usb-hub", bus usb-bus name "x3130-upstream", bus PCI, desc "TI X3130 Upstream Port of PCI Express Switch" name "xio3130-downstream", bus PCI, desc "TI X3130 Downstream Port of PCI Express Switch" USB devices: name "ich9-usb-ehci1", bus PCI name "ich9-usb-ehci2", bus PCI name "ich9-usb-uhci1", bus PCI name "ich9-usb-uhci2", bus PCI name "ich9-usb-uhci3", bus PCI name "ich9-usb-uhci4", bus PCI name "ich9-usb-uhci5", bus PCI name "ich9-usb-uhci6", bus PCI name "nec-usb-xhci", bus PCI name "piix3-usb-uhci", bus PCI name "piix4-usb-uhci", bus PCI name "usb-ehci", bus PCI name "vt82c686b-usb-uhci", bus PCI Storage devices: name "ich9-ahci", bus PCI, alias "ahci" name "ide-cd", bus IDE, desc "virtual IDE CD-ROM" name "ide-drive", bus IDE, desc "virtual IDE disk or CD-ROM (legacy)" name "ide-hd", bus IDE, desc "virtual IDE disk" name "scsi-block", bus SCSI, desc "SCSI block device passthrough" name "scsi-cd", bus SCSI, desc "virtual SCSI CD-ROM" name "scsi-disk", bus SCSI, desc "virtual SCSI disk or CD-ROM (legacy)" name "scsi-generic", bus SCSI, desc "pass through generic scsi device (/dev/sg*)" name "scsi-hd", bus SCSI, desc "virtual SCSI disk" name "usb-bot", bus usb-bus name "usb-storage", bus usb-bus name "virtio-blk-device", bus virtio-bus name "virtio-blk-pci", bus PCI, alias "virtio-blk" name "virtio-scsi-device", bus virtio-bus name "virtio-scsi-pci", bus PCI Network devices: name "e1000", bus PCI, desc "Intel Gigabit Ethernet" name "rtl8139", bus PCI name "virtio-net-device", bus virtio-bus name "virtio-net-pci", bus PCI, alias "virtio-net" Input devices: name "ccid-card-passthru", bus ccid-bus, desc "passthrough smartcard" name "isa-serial", bus ISA name "pci-serial", bus PCI name "usb-ccid", bus usb-bus, desc "CCID Rev 1.1 smartcard reader" name "usb-kbd", bus usb-bus name "usb-mouse", bus usb-bus name "virtconsole", bus virtio-serial-bus name "virtio-serial-device", bus virtio-bus name "virtio-serial-pci", bus PCI, alias "virtio-serial" name "virtserialport", bus virtio-serial-bus Display devices: name "cirrus-vga", bus PCI, desc "Cirrus CLGD 54xx VGA" name "qxl", bus PCI, desc "Spice QXL GPU (secondary)" name "qxl-vga", bus PCI, desc "Spice QXL GPU (primary, vga compatible)" name "sga", bus ISA, desc "Serial Graphics Adapter" name "VGA", bus PCI Sound devices: name "AC97", bus PCI, desc "Intel 82801AA AC97 Audio" name "hda-duplex", bus HDA, desc "HDA Audio Codec, duplex (line-out, line-in)" name "hda-micro", bus HDA, desc "HDA Audio Codec, duplex (speaker, microphone)" name "hda-output", bus HDA, desc "HDA Audio Codec, output-only (line-out)" name "ich9-intel-hda", bus PCI, desc "Intel HD Audio Controller (ich9)" name "intel-hda", bus PCI, desc "Intel HD Audio Controller (ich6)" Misc devices: name "i6300esb", bus PCI name "ib700", bus ISA name "isa-debug-exit", bus ISA name "isa-debugcon", bus ISA name "kvm-pci-assign", bus PCI, alias "pci-assign", desc "KVM-based PCI passthrough" name "pc-testdev", bus ISA name "pci-testdev", bus PCI, desc "PCI Test Device" name "usb-redir", bus usb-bus name "usb-tablet", bus usb-bus name "vfio-pci", bus PCI, desc "VFIO-based PCI device assignment" name "virtio-balloon-device", bus virtio-bus name "virtio-balloon-pci", bus PCI, alias "virtio-balloon" name "virtio-rng-device", bus virtio-bus name "virtio-rng-pci", bus PCI Uncategorized devices: name "pvpanic", bus ISA
[root@localhost lib]# /usr/libexec/qemu-kvm -device VGA,?app
VGA.vgamem_mb=uint32 VGA.mmio=on/off VGA.addr=pci-devfn VGA.romfile=string VGA.rombar=uint32 VGA.multifunction=on/off VGA.command_serr_enable=on/off
[root@localhost lib]# /usr/libexec/qemu-kvm -device qxl,?
qxl.ram_size=uint32 qxl.vram_size=uint32 qxl.revision=uint32 qxl.debug=uint32 qxl.guestdebug=uint32 qxl.cmdlog=uint32 qxl.ram_size_mb=uint32 qxl.vram_size_mb=uint32 qxl.vram64_size_mb=uint32 qxl.vgamem_mb=uint32 qxl.surfaces=int32 qxl.addr=pci-devfn qxl.romfile=string qxl.rombar=uint32 qxl.multifunction=on/off qxl.command_serr_enable=on/off
[root@localhost lib]# /usr/libexec/qemu-kvm -device e1000,?
e1000.mac=macaddr e1000.vlan=vlan e1000.netdev=netdev e1000.bootindex=int32 e1000.autonegotiation=on/off e1000.addr=pci-devfn e1000.romfile=string e1000.rombar=uint32 e1000.multifunction=on/off e1000.command_serr_enable=on/off
命令行參數
[root@localhost lib]# /usr/libexec/qemu-kvm -h|more QEMU emulator version 1.5.3 (qemu-kvm-1.5.3-105.el7_2.4), Copyright (c) 2003-2008 Fabrice Bellard WARNING: Direct use of qemu-kvm from the command line is not supported by Red Hat. WARNING: Use libvirt as the stable management interface. WARNING: Some command line options listed here may not be available in future releases. -machine -cpu -smp n set the number of CPUs to 'n' [default=1] -boot [order=drives] 'drives': floppy (a), hard disk (c), CD-ROM (d), network (n) -m megs set virtual RAM size to megs MB [default=128] -name string1[,process=string2] set the name of the guest -cdrom file -display sdl[,frame=on|off][,alt_grab=on|off][,ctrl_grab=on|off] [,window_close=on|off]|curses|none| vnc=<display>[,<optargs>] select display type -nographic disable graphical output and redirect serial I/Os to console -spice [port=port][,password=<secret>] at least one of {port, tls-port} is mandatory -vga [std|cirrus|vmware|qxl|xenfb|none] select video card type -full-screen start in full screen -vnc display start a VNC server on display -net nic 其中,「-net nic」這個是必須的參數,代表這是一個網卡的配置。若是沒有,虛擬機啓動後就不會有網卡 -net user 用戶網絡模式 http://www.diyoms.com/cloud/836.html http://qemu.weilnetz.de/qemu-doc.html#Using-TAP-network-interfaces
用戶模式客戶機能夠直接鏈接宿主機和外部網絡,並且徹底由qemu自身徹底實現,不依賴於(bridge,dnsmasq,iptables等),不須要root權限 Qemu使用slirp實現了一套Tcp/ip協議棧,並且用這個協議棧實現了一套虛擬的NAT網絡。 qemu-kvm默認使用:-net nic -net user 優勢:簡單、獨立性好、不須要root權限、客戶機網絡隔離性好。 缺點: 一、性能差 二、不支持部分網絡功能(如ICMP),因此不能再客戶機中使用ping命令測試, 三、不能從宿主機或外部網絡直接訪問客戶機 -net user dhcpstart=addr 設置分配給客戶機的第一個Ip,在qemu內嵌的DHCP服務器中有16個IP地址能夠分配,默認是(如10.0.2.15~10.0.2.30) dns=addr 指定虛擬的DNS地址,該地址不能與宿主機同樣,默認爲網絡中的第三個IP地址(如:10.0.2.3) qemu-kvm centos6u5.img -m 1024 -smp 2 -net nic -net user,tftp=/root/tftp,hostfwd=tcp::5022-hostfwd=tcp::5080-:80
-net none use it alone to have zero network devices. If no -net option is provided, the default is '-net nic -net user' -net nic -net bridge Linux/Multiboot boot specific: -kernel bzImage use 'bzImage' as kernel image -append cmdline use 'cmdline' as kernel command line -initrd file use 'file' as initial ram disk -dtb file use 'file' as device tree image -daemonize daemonize QEMU after initializing -echr chr set terminal escape character instead of ctrl-a During emulation, the following keys are useful: ctrl-alt-f toggle full screen ctrl-alt-n switch to virtual console 'n' ctrl-alt toggle mouse and keyboard grab When using -nographic, press 'ctrl-a h' to get some help.
命令行參數解釋及實例
在qemu-kvm命令行中,添加「-nographic」參數能夠徹底關閉QEMU的圖形界面輸出,從而讓QEMU在該模式下徹底成爲簡單的命令行工具。而QEMU中模擬產生的串口被重定向到了當前的控制檯(console)中,因此若是在客戶機中對其內核進行配置從而讓內核的控制檯輸出重定向到串口後,就依然能夠在非圖形模式下管理客戶機系統或調試客戶機的內核。 在命令行直接安裝虛擬機 mount -o loop CentOS-6.5-x86_64-bin-DVD1.iso /mnt qemu-img create -f qcow2 cs66.qcow2 8G /usr/libexec/qemu-kvm -boot order=dc -hda cs66.qcow2 -cdrom CentOS-6.5-x86_64-bin-DVD1.iso -m 1024 -nographic -append console=ttyS0 -kernel /mnt/isolinux/vmlinuz -initrd /mnt/isolinux/initrd.img kill 掉上面的進程,重啓去掉一些參數再以下啓動 /usr/libexec/qemu-kvm -boot order=dc -hda cs66.qcow2 -m 1024 -nographic 宿主機是cs72,虛擬機是cs65 安裝好系統以後,先用spice啓動 1.先啓動/usr/libexec/qemu-kvm -boot order=dc -hda cs65.qcow2 -m 1024 -spice port=9987,password=1234 2.windows的spice客戶端去鏈接,進去以後,vi /boot/grub/grub.cfg,在內核行後加入console=ttyS0而後保存關機 3.再加-nographic參數後啓動,/usr/libexec/qemu-kvm -boot order=dc -hda cs65.qcow2 -m 1024 -nographic 這樣就在宿主機本地啓動了 man qemu-kvm debug/expert options
/usr/libexec/qemu-kvm -enable-kvm -monitor stdio 服務器啓動 /usr/libexec/qemu-kvm -boot dc -hda disk/cs65.qcow2 -m 1024 -vnc :2 -daemonize -net bridge -net nic -enable-kvm -monitor telnet:192.168.10.101:4444,server,nowait 客戶端鏈接 telnet 192.168.10.101 4444 /usr/libexec/qemu-kvm -boot dc -hda disk/cs65.qcow2 -m 1024 -vnc :2 -daemonize -net bridge -net nic -enable-kvm -monitor tcp:192.168.10.101:4445,server,nowait nc 192.168.10.101 4445 tcp – raw tcp sockets #下面第2點,個人舉例是RAW TCP socket telnet – the telnet protocol is used instead of raw tcp sockets. This is the preferred option over tcp as you can break out of the monitor using Ctrl-] then typing quit. You can’t break out of the monitor like this after connecting with the raw socket option 10.1.77.82 – Listen on this host/IP only. You can use 127.0.0.1 if you want to only allow connections locally. If you want to listen on any ip address on the server, just leave this blank so you end up with two consecutive colons ie 「::」 . 4444 – port number to listen on. server – listening in server mode nowait – qemu will wait for a client socket application to connect to the port before continuing unless this option is used. In most cases you’ll want to use the nowait option.
日誌問題追查
Jul 31 11:02:59 localhost kernel: kvm [1463]: vcpu0 disabled perfctr wrmsr: 0xc2 data 0xffff Jul 31 11:02:59 localhost kernel: kvm [1463]: vcpu0 unhandled rdmsr: 0x570
cpu標誌 [root@localhost ~]# cat /proc/cpuinfo flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf eagerfpu pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 fma cx16 xtpr pdcm pcid sse4_1 sse4_2 movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm arat pln pts dtherm tpr_shadow vnmi flexpriority ept vpid fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid xsaveopt 日誌中kvm報出來的關於cpu的狀況 [root@localhost ~]# tail -20 /var/log/messages-20160731 Jul 31 11:02:59 localhost kernel: kvm [1463]: vcpu0 disabled perfctr wrmsr: 0xc2 data 0xffff Jul 31 11:02:59 localhost kernel: kvm [1463]: vcpu0 unhandled rdmsr: 0x570 這是kvm支持的cpu特徵 [root@localhost ~]# /usr/libexec/qemu-kvm -cpu ?|grep msr pbe ia64 tm ht ss sse2 sse fxsr mmx acpi ds clflush pn pse36 pat cmov mca pge mtrr sep apic cx8 mce pae msr tsc pse de vme fpu perfctr_nb perfctr_core topoext tbm nodeid_msr tce fma4 lwp wdt skinit xop ibs osvw 3dnowprefetch misalignsse sse4a abm cr8legacy extapic svm cmp_legacy lahf_lm cpu flag msr概念 Model Specific Register (MSR) as the name implies is model specific and may change from processor model number (n) to processor model number (n+1). 讀寫方法 MSR 是CPU 的一組64 位寄存器,能夠分別經過RDMSR 和WRMSR 兩條指令進行讀和寫的操做,前提要在ECX 中寫入MSR 的地址。對於RDMSR 指令,將會返回相應的MSR 中64bit 信息到(EDX:EAX)寄存器中;對於WRMSR 指令,把要寫入的信息存入(EDX:EAX)中,執行寫指令後,便可將相應的信息存入ECX 指定的MSR 中。MSR 的指令必須執行在level 0 或實模式下。 做用 MSR 整體來是爲了設置CPU 的工做環境和標示CPU 的工做狀態,包括溫度控制,性能監控等,具體來講,分爲如下幾項: [root@localhost ~]# lsmod|grep papi [root@localhost ~]# modprobe papi modprobe: FATAL: Module papi not found. [root@localhost ~]# lsmod |grep perfctr [root@localhost ~]# modprobe perfctr modprobe: FATAL: Module perfctr not found. # modprobe perfctr 加載模塊 lsmod 顯示模塊 rmmod perfctr移除模塊 若perfctr模塊安裝成功後,你將看到perfctr模塊,而且你能夠在 /lib/modules/2.6.19-zkl-perfctr/kernel/drivers/perfctr中看到perfctr模塊perfctr.ko 須要使用PAPI獲得硬件級的數據,即與微指令相關的數據, 例如 L1/L2 cache miss、TLB miss、Cycle等,而PAPI須要perfctr(Performance-monitoring counters support)模塊的支持, 而Linux內核當中默認沒有perfctr模塊,而且perfctr只在某些內核上被支持,它其實是內核的一個補丁,須要從新編譯內核,打上補丁才能在內核上運行perfctr模塊。更多信息參考papi和perfctr的INSTALL文件。 PAPI (Performance Application Programming Interface),它是一套API,經過它能夠訪問CPU性能計數器的數據, 例如 L1/L2 Cache,CPU Cycle,CPU Instruction,TLB等. PAPI官網是: http://icl.cs.utk.edu/papi/ [root@localhost ~]# yum search papi Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * base: mirrors.hust.edu.cn * extras: mirrors.neusoft.edu.cn * updates: mirrors.neusoft.edu.cn =================================================== N/S matched: papi ==================================================== papi-devel.i686 : Header files for the compiling programs with PAPI papi-devel.x86_64 : Header files for the compiling programs with PAPI papi-static.i686 : Static libraries for the compiling programs with PAPI papi-static.x86_64 : Static libraries for the compiling programs with PAPI papi-testsuite.x86_64 : Set of tests for checking PAPI functionality papi.i686 : Performance Application Programming Interface papi.x86_64 : Performance Application Programming Interface pcp-pmda-papi.x86_64 : Performance Co-Pilot (PCP) metrics for Performance API and hardware counters