# qemu-img -h | grep “Supported formats”
Supported formats: raw cow qcow vdi vmdk cloop dmg bochs vpc vvfat qcow2 qed vhdx parallels nbd blkdebug null host_cdrom host_floppy host_device file gluster
vmdk:vmware
vdi: virtulbox
qcow2:qemu-img
raw:dd 命令
convert 格式转换 [-c] [-p] [-f fmt] [-t cache] [-T src_cache] [-O output_fmt] [-o options] [-S sparse_size] filename [filename2 […]] output_filename
resize 重新调整大小 vmdk vdi qcow2 raw不支持
qemu-kvm的标准选项主要涉及指定主机类型、CPU模式、NUMA、软驱设备、光驱设备及硬件设备等。
基础命令
◇ -name name:设定虚拟机名称;
# qemu-kvm -m 128 -smp 2 -name test -hda
◇ -M machine:指定要模拟的主机类型,如Standard PC、ISA-only PC或Intel-Mac等,可以使用“qemu-kvm -M ?”获取所支持的所有类型;
# qemu-kvm -M ?
Supported machines are:
pc RHEL 6.6.0 PC (alias of rhel6.6.0)
rhel6.6.0 RHEL 6.6.0 PC (default)
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
rhel5.5.0 RHEL 5.5.0 PC
rhel5.4.4 RHEL 5.4.4 PC
rhel5.4.0 RHEL 5.4.0 PC
◇ -m megs:设定虚拟机的RAM大小;
# qemu-kvm -m 128 -smp 2 -name test -hda
◇ -cpu model:设定CPU模型,如coreduo、qemu64等,可以使用“qemu-kvm -cpu ?”获取所支持的所有模型;
# qemu-kvm -cpu ?
x86 Opteron_G5 AMD Opteron 63xx class CPU
x86 Opteron_G4 AMD Opteron 62xx class CPU
x86 Opteron_G3 AMD Opteron 23xx (Gen 3 Class Opteron)
x86 Opteron_G2 AMD Opteron 22xx (Gen 2 Class Opteron)
x86 Opteron_G1 AMD Opteron 240 (Gen 1 Class Opteron)
x86 Broadwell Intel Core Processor (Broadwell)
x86 Haswell Intel Core Processor (Haswell)
x86 SandyBridge Intel Xeon E312xx (Sandy Bridge)
x86 Westmere Westmere E56xx/L56xx/X56xx (Nehalem-C)
x86 Nehalem Intel Core i7 9xx (Nehalem Class Core i7)
x86 Penryn Intel Core 2 Duo P9xxx (Penryn Class Core 2)
x86 Conroe Intel Celeron_4x0 (Conroe/Merom Class Core 2)
x86 cpu64-rhel5 QEMU Virtual CPU version (cpu64-rhel5)
x86 cpu64-rhel6 QEMU Virtual CPU version (cpu64-rhel6)
x86 n270 Intel(R) Atom(TM) CPU N270 @ 1.60GHz
x86 athlon QEMU Virtual CPU version 0.12.1
x86 pentium3
x86 pentium2
◇ -smp n[,cores=cores][,threads=threads][,sockets=sockets][,maxcpus=maxcpus]:设定模拟的SMP架构中CPU的个数等、每个CPU的核心数及CPU的socket数目等;PC机上最多可以模拟255颗CPU;maxcpus用于指定热插入的CPU个数上限;
# qemu-kvm -m 128 -smp 2 -name test -hda
◇ -numa opts:指定模拟多节点的numa设备;
防止资源竞争问题
◇ -fda file
◇ -fdb file:使用指定文件(file)作为软盘镜像,file为/dev/fd0表示使用物理软驱;
◇ -hda file
◇ -hdb file
◇ -hdc file
◇ -hdd file:使用指定file作为硬盘镜像;
◇ -cdrom file:使用指定file作为CD-ROM镜像,需要注意的是-cdrom和-hdc不能同时使用;将file指定为/dev/cdrom可以直接使用物理光驱;
◇ -drive option[,option[,option[,…]]]:定义一个硬盘设备;可用子选项有很多。
file=/path/to/somefile:硬件映像文件路径;
if=interface:指定硬盘设备所连接的接口类型,即控制器类型,如ide、scsi、sd、mtd、floppy、pflash及virtio等;
index=index:设定同一种控制器类型中不同设备的索引号,即标识号;
media=media:定义介质类型为硬盘(disk)还是光盘(cdrom);
snapshot=snapshot:指定当前硬盘设备是否支持快照功能:on或off;
cache=cache:定义如何使用物理机缓存来访问块数据,其可用值有:
none:不打开缓存功能
writeback:回写
unsafe:性能最好,有数据安全性问题
writethrough:通写性能较差
format=format:指定映像文件的格式,具体格式可参见qemu-img命令;
◇ -boot [order=drives][,once=drives][,menu=on|off]:定义启动设备的引导次序,每种设备使用一个字符表示;不同的架构所支持的设备及其表示字符不尽相同,在x86 PC架构上,a、b表示软驱、c表示第一块硬盘,d表示第一个光驱设备,n-p表示网络适配器;默认为硬盘设备;
-boot order=dc,once=d:一旦重启后不再光驱启动
例如:
# qemu-kvm -name cirros -m 128 -smp 2 -drive file=/root/cirros-0.3.5-x86_64-disk.img,if=virtio,media=disk,cache=writeback,format=qcow2
VNC server running on `::1:5900′