设为首页 收藏本站
查看: 1114|回复: 0

[经验分享] 使用QEMU创建虚拟机

[复制链接]

尚未签到

发表于 2017-6-24 16:31:39 | 显示全部楼层 |阅读模式
  下载安装:



wget http://wiki.qemu-project.org/download/qemu-2.0.0.tar.bz2


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:选择目标机器的架构。默认是将所有的架构都编译,但为了更快的完成编译,指定需要的架构即可。


[iyunv@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架构的虚拟机
DSC0000.png

  安装KVM模块.加速虚拟机



检查KVM是否可用:
QEMU使用KVM来提升虚拟机性能,如果不启用KVM会导致性能损失。要使用KVM,首先要检查硬件是否有虚拟化支持:
grep -E 'vmx|svm' /proc/cpuinfo
如果有输出则表示硬件有虚拟化支持。其次要检查kvm模块是否已经加载:
[iyunv@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的虚拟机:
[iyunv@server-mysql ~]# qemu-system-x86_64 -m 50 fedora.img -cdrom ./ReactOS-LiveCD.iso
-m 指定虚拟机内存大小,默认单位是MB,
-enable-kvm使用KVM进行加速,
-cdrom添加fedora的安装镜像。可在弹出的窗口中操作虚拟机,安装操作系统,安装完成后重起虚拟机便会从硬盘(fedora.img)启动。
之后再启动虚拟机只需要执行:
[iyunv@server-mysql ~]#qemu-system-x86_64 -m 50m fedora.img
DSC0001.png

DSC0002.png

  图形官理界面: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

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-387582-1-1.html 上篇帖子: Linux下运行Jmeter测试所遇问题汇总 下篇帖子: 制作 OpenStack Windows 镜像
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表