您的位置:首页 > 其它

使用QEMU创建虚拟机

2016-06-28 15:10 1816 查看
下载安装:

wget http://wiki.qemu-project.org/download/qemu-2.0.0.tar.bz2[/code] 
tar xjvf qemu-2.0.0.tar.bz2                                  //git clone git://git.qemu-project.org/qemu.git
cd qemu-2.0.0
./configure --enable-kvm --enable-debug --enable-vnc --enable-werror  --target-list="x86_64-softmmu"
make -j8
make install


说明:

--enable-kvm:编译KVM模块,使QEMU可以利用KVM来访问硬件提供的虚拟化服务。
--enable-vnc:启用VNC。
--enalbe-werror:编译时,将所有的警告当作错误处理。
--target-list:选择目标机器的架构。默认是将所有的架构都编译,但为了更快的完成编译,指定需要的架构即可。


[root@server-mysql qemu-2.0.0]# ./configure --help

Usage: configure [options]
Options: [defaults in brackets after descriptions]

Standard options:
--help                   print this message
--prefix=PREFIX          install in PREFIX [/usr/local]
--interp-prefix=PREFIX   where to find shared libraries, etc.
use %M for cpu name [/usr/gnemul/qemu-%M]
--target-list=LIST       set target list (default: build everything)
Available targets: aarch64-softmmu alpha-softmmu
arm-softmmu cris-softmmu i386-softmmu lm32-softmmu
m68k-softmmu microblazeel-softmmu microblaze-softmmu
mips64el-softmmu mips64-softmmu mipsel-softmmu
mips-softmmu moxie-softmmu or32-softmmu
ppc64-softmmu ppcemb-softmmu ppc-softmmu
s390x-softmmu sh4eb-softmmu sh4-softmmu
sparc64-softmmu sparc-softmmu unicore32-softmmu
x86_64-softmmu xtensaeb-softmmu xtensa-softmmu
aarch64-linux-user alpha-linux-user armeb-linux-user
arm-linux-user cris-linux-user i386-linux-user
m68k-linux-user microblazeel-linux-user
microblaze-linux-user mips64el-linux-user
mips64-linux-user mipsel-linux-user mips-linux-user
mipsn32el-linux-user mipsn32-linux-user
or32-linux-user ppc64abi32-linux-user
ppc64-linux-user ppc-linux-user s390x-linux-user
sh4eb-linux-user sh4-linux-user
sparc32plus-linux-user sparc64-linux-user
sparc-linux-user unicore32-linux-user
x86_64-linux-user

Advanced options (experts only):
--source-path=PATH       path of source code [/root/qemu-2.0.0]
--cross-prefix=PREFIX    use PREFIX for compile tools []
--cc=CC                  use C compiler CC [cc]
--iasl=IASL              use ACPI compiler IASL [iasl]
--host-cc=CC             use C compiler CC [cc] for code run at
build time
--cxx=CXX                use C++ compiler CXX [c++]
--objcc=OBJCC            use Objective-C compiler OBJCC [cc]
--extra-cflags=CFLAGS    append extra C compiler flags QEMU_CFLAGS
--extra-ldflags=LDFLAGS  append extra linker flags LDFLAGS
--make=MAKE              use specified make [make]
--install=INSTALL        use specified install [install]
--python=PYTHON          use specified python [python -B]
--smbd=SMBD              use specified smbd [/usr/sbin/smbd]
--static                 enable static build [no]
--mandir=PATH            install man pages in PATH
--datadir=PATH           install firmware in PATH/qemu
--docdir=PATH            install documentation in PATH/qemu
--bindir=PATH            install binaries in PATH
--libdir=PATH            install libraries in PATH
--sysconfdir=PATH        install config in PATH/qemu
--localstatedir=PATH     install local state in PATH (set at runtime on win32)
--with-confsuffix=SUFFIX suffix for QEMU data inside datadir/libdir/sysconfdir [/qemu]
--enable-modules         enable modules support
--enable-debug-tcg       enable TCG debugging
--disable-debug-tcg      disable TCG debugging (default)
--enable-debug-info       enable debugging information (default)
--disable-debug-info      disable debugging information
--enable-debug           enable common debug build options
--enable-sparse          enable sparse checker
--disable-sparse         disable sparse checker (default)
--disable-strip          disable stripping binaries
--disable-werror         disable compilation abort on warning
--disable-stack-protector disable compiler-provided stack protection
--disable-sdl            disable SDL
--enable-sdl             enable SDL
--with-sdlabi            select preferred SDL ABI 1.2 or 2.0
--disable-gtk            disable gtk UI
--enable-gtk             enable gtk UI
--disable-virtfs         disable VirtFS
--enable-virtfs          enable VirtFS
--disable-vnc            disable VNC
--enable-vnc             enable VNC
--disable-cocoa          disable Cocoa (Mac OS X only)
--enable-cocoa           enable Cocoa (default on Mac OS X)
--audio-drv-list=LIST    set audio drivers list:
Available drivers: oss alsa sdl esd pa fmod
--block-drv-whitelist=L  Same as --block-drv-rw-whitelist=L
--block-drv-rw-whitelist=L
set block driver read-write whitelist
(affects only QEMU, not qemu-img)
--block-drv-ro-whitelist=L
set block driver read-only whitelist
(affects only QEMU, not qemu-img)
--disable-xen            disable xen backend driver support
--enable-xen             enable xen backend driver support
--disable-xen-pci-passthrough
--enable-xen-pci-passthrough
--disable-brlapi         disable BrlAPI
--enable-brlapi          enable BrlAPI
--disable-vnc-tls        disable TLS encryption for VNC server
--enable-vnc-tls         enable TLS encryption for VNC server
--disable-vnc-sasl       disable SASL encryption for VNC server
--enable-vnc-sasl        enable SASL encryption for VNC server
--disable-vnc-jpeg       disable JPEG lossy compression for VNC server
--enable-vnc-jpeg        enable JPEG lossy compression for VNC server
--disable-vnc-png        disable PNG compression for VNC server (default)
--enable-vnc-png         enable PNG compression for VNC server
--disable-vnc-ws         disable Websockets support for VNC server
--enable-vnc-ws          enable Websockets support for VNC server
--disable-curses         disable curses output
--enable-curses          enable curses output
--disable-curl           disable curl connectivity
--enable-curl            enable curl connectivity
--disable-fdt            disable fdt device tree
--enable-fdt             enable fdt device tree
--disable-bluez          disable bluez stack connectivity
--enable-bluez           enable bluez stack connectivity
--disable-slirp          disable SLIRP userspace network connectivity
--disable-kvm            disable KVM acceleration support
--enable-kvm             enable KVM acceleration support
--disable-rdma           disable RDMA-based migration support
--enable-rdma            enable RDMA-based migration support
--enable-tcg-interpreter enable TCG with bytecode interpreter (TCI)
--enable-system          enable all system emulation targets
--disable-system         disable all system emulation targets
--enable-user            enable supported user emulation targets
--disable-user           disable all user emulation targets
--enable-linux-user      enable all linux usermode emulation targets
--disable-linux-user     disable all linux usermode emulation targets
--enable-bsd-user        enable all BSD usermode emulation targets
--disable-bsd-user       disable all BSD usermode emulation targets
--enable-guest-base      enable GUEST_BASE support for usermode
emulation targets
--disable-guest-base     disable GUEST_BASE support
--enable-pie             build Position Independent Executables
--disable-pie            do not build Position Independent Executables
--fmod-lib               path to FMOD library
--fmod-inc               path to FMOD includes
--oss-lib                path to OSS library
--enable-uname-release=R Return R for uname -r in usermode emulation
--cpu=CPU                Build for host CPU [x86_64]
--disable-uuid           disable uuid support
--enable-uuid            enable uuid support
--disable-vde            disable support for vde network
--enable-vde             enable support for vde network
--disable-netmap         disable support for netmap network
--enable-netmap          enable support for netmap network
--disable-linux-aio      disable Linux AIO support
--enable-linux-aio       enable Linux AIO support
--disable-cap-ng         disable libcap-ng support
--enable-cap-ng          enable libcap-ng support
--disable-attr           disables attr and xattr support
--enable-attr            enable attr and xattr support
--disable-blobs          disable installing provided firmware blobs
--enable-docs            enable documentation build
--disable-docs           disable documentation build
--disable-vhost-net      disable vhost-net acceleration support
--enable-vhost-net       enable vhost-net acceleration support
--enable-trace-backend=B Set trace backend
Available backends: nop, stderr, dtrace, simple, ust, ftrace
--with-trace-file=NAME   Full PATH,NAME of file to store traces
Default:trace-<pid>
--disable-spice          disable spice
--enable-spice           enable spice
--enable-rbd             enable building the rados block device (rbd)
--disable-libiscsi       disable iscsi support
--enable-libiscsi        enable iscsi support
--disable-libnfs         disable nfs support
--enable-libnfs          enable nfs support
--disable-smartcard-nss  disable smartcard nss support
--enable-smartcard-nss   enable smartcard nss support
--disable-libusb         disable libusb (for usb passthrough)
--enable-libusb          enable libusb (for usb passthrough)
--disable-usb-redir      disable usb network redirection support
--enable-usb-redir       enable usb network redirection support
--enable-lzo             enable the support of lzo compression library
--enable-snappy          enable the support of snappy compression library
--disable-guest-agent    disable building of the QEMU Guest Agent
--enable-guest-agent     enable building of the QEMU Guest Agent
--with-vss-sdk=SDK-path  enable Windows VSS support in QEMU Guest Agent
--with-win-sdk=SDK-path  path to Windows Platform SDK (to build VSS .tlb)
--disable-seccomp        disable seccomp support
--enable-seccomp         enables seccomp support
--with-coroutine=BACKEND coroutine backend. Supported options:
gthread, ucontext, sigaltstack, windows
--disable-coroutine-pool disable coroutine freelist (worse performance)
--enable-coroutine-pool  enable coroutine freelist (better performance)
--enable-glusterfs       enable GlusterFS backend
--disable-glusterfs      disable GlusterFS backend
--enable-gcov            enable test coverage analysis with gcov
--gcov=GCOV              use specified gcov [gcov]
--enable-tpm             enable TPM support
--disable-libssh2        disable ssh block device support
--enable-libssh2         enable ssh block device support
--disable-vhdx           disables support for the Microsoft VHDX image format
--enable-vhdx            enable support for the Microsoft VHDX image format
--disable-quorum         disable quorum block filter support
--enable-quorum          enable quorum block filter support


命令行创建及启动虚拟机

1.使用qemu-img创建虚拟机镜像。虚拟机镜像用来模拟虚拟机的硬盘,在启动虚拟机之前需要创建镜像文件。

qemu-img create -f qcow2 fedora.img 1G


fedora.img
-f选项用于指定镜像的格式,qcow2格式是QEMU最常用的镜像格式,采用来写时复制技术来优化性能。fedora.img是镜像文件的名字,10G是镜像文件大小。镜像文件创建完成后,可使用qemu-system-x86来启动x86架构的虚拟机




安装KVM模块.加速虚拟机

检查KVM是否可用:

QEMU使用KVM来提升虚拟机性能,如果不启用KVM会导致性能损失。要使用KVM,首先要检查硬件是否有虚拟化支持:

grep -E 'vmx|svm' /proc/cpuinfo

如果有输出则表示硬件有虚拟化支持。其次要检查kvm模块是否已经加载:

[root@server]lsmod | grep kvm
kvm_intel             142999  0
kvm                   444314  1 kvm_intel
如果kvm_intel/kvm_amd、kvm模块被显示出来,则kvm模块已经加载。
最好要确保qemu在编译的时候使能了KVM,即在执行configure脚本的时候加入了–enable-kvm选项。


启动虚拟机安装操作系统


执行下面的命令启动带有cdrom的虚拟机:

[root@server-mysql ~]# qemu-system-x86_64 -m 50 fedora.img -cdrom ./ReactOS-LiveCD.iso
-m 指定虚拟机内存大小,默认单位是MB,
-enable-kvm使用KVM进行加速,
-cdrom添加fedora的安装镜像。可在弹出的窗口中操作虚拟机,安装操作系统,安装完成后重起虚拟机便会从硬盘(fedora.img)启动。
之后再启动虚拟机只需要执行:

[root@server-mysql ~]#qemu-system-x86_64 -m 50m fedora.img






图形官理界面:virt-manager

Minimum version requirements of major components:

python >= 2.7
gtk3 >= 3.14
libvirt-python >= 0.6.0
pygobject3 >= 3.14
libosinfo >= 0.2.10

安装:
python setup.py install
 http://blog.csdn.net/reblue520/article/details/51456848
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: