5. qemu命令行參數

2020-12-13 CSDN技術社區

KVM 實際調用的是qemu-system-x86_64命令
參數如下


root@:/etc/libvirt/qemu# kvm -help
QEMU emulator version 2.3.0 (Debian 1:2.3+dfsg-5ubuntu9.2), Copyright (c) 2003-2008 Fabrice Bellard
usage: qemu-system-x86_64 [options] [disk_image]

'disk_image' is a raw hard disk image for IDE hard disk 0

Standard options:
-h or -help display this help and exit
-version display version information and exit
-machine [type=]name[,prop[=value][,...]]
selects emulated machine ('-machine help' for list)
property accel=accel1[:accel2[:...]] selects accelerator
supported accelerators are kvm, xen, tcg (default: tcg)
kernel_irqchip=on|off controls accelerated irqchip support
vmport=on|off|auto controls emulation of vmport (default: auto)
kvm_shadow_mem=size of KVM shadow MMU
dump-guest-core=on|off include guest memory in a core dump (default=on)
mem-merge=on|off controls memory merge support (default: on)
iommu=on|off controls emulated Intel IOMMU (VT-d) support (default=off)
aes-key-wrap=on|off controls support for AES key wrapping (default=on)
dea-key-wrap=on|off controls support for DEA key wrapping (default=on)
suppress-vmdesc=on|off disables self-describing migration (default=off)
-cpu cpu select CPU ('-cpu help' for list)
-smp [cpus=]n[,maxcpus=cpus][,cores=cores][,threads=threads][,sockets=sockets]
set the number of CPUs to 'n' [default=1]
maxcpus= maximum number of total cpus, including
offline CPUs for hotplug, etc
cores= number of CPU cores on one socket
threads= number of threads on one CPU core
sockets= number of discrete sockets in the system
-numa node[,mem=size][,cpus=cpu[-cpu]][,nodeid=node]
-numa node[,memdev=id][,cpus=cpu[-cpu]][,nodeid=node]
-add-fd fd=fd,set=set[,opaque=opaque]
Add 'fd' to fd 'set'
-set group.id.arg=value
set <arg> parameter for item <id> of type <group>
i.e. -set drive.$id.file=/path/to/image
-global driver.prop=value
set a global default for a driver property
-boot [order=drives][,once=drives][,menu=on|off]
[,splash=sp_name][,splash-time=sp_time][,reboot-timeout=rb_time][,strict=on|off]
'drives': floppy (a), hard disk (c), CD-ROM (d), network (n)
'sp_name': the file's name that would be passed to bios as logo picture, if menu=on
'sp_time': the period that splash picture last if menu=on, unit is ms
'rb_timeout': the timeout before guest reboot when boot failed, unit is ms
-m[emory] [size=]megs[,slots=n,maxmem=size]
configure guest RAM
size: initial amount of guest memory (default: 128MiB)
slots: number of hotplug slots (default: none)
maxmem: maximum amount of guest memory (default: none)
NOTE: Some architectures might enforce a specific granularity
-mem-path FILE provide backing storage for guest RAM
-mem-prealloc preallocate guest memory (use with -mem-path)
-k language use keyboard layout (for example 'fr' for French)
-audio-help print list of audio drivers and their options
-soundhw c1,... enable audio support
and only specified sound cards (comma separated list)
use '-soundhw help' to get the list of supported cards
use '-soundhw all' to enable all of them
-balloon none disable balloon device
-balloon virtio[,addr=str]
enable virtio balloon device (default)
-device driver[,prop[=value][,...]]
add device (based on driver)
prop=value,... sets driver properties
use '-device help' to print all possible drivers
use '-device driver,help' to print all possible properties
-name string1[,process=string2][,debug-threads=on|off]
set the name of the guest
string1 sets the window title and string2 the process name (on Linux)
When debug-threads is enabled, individual threads are given a separate name (on Linux)
NOTE: The thread names are for debugging and not a stable API.
-uuid %08x-%04x-%04x-%04x-%012x
specify machine UUID

Block device options:
-fda/-fdb file use 'file' as floppy disk 0/1 image
-hda/-hdb file use 'file' as IDE hard disk 0/1 image
-hdc/-hdd file use 'file' as IDE hard disk 2/3 image
-cdrom file use 'file' as IDE cdrom image (cdrom is ide1 master)
-drive [file=file][,if=type][,bus=n][,unit=m][,media=d][,index=i]
[,cyls=c,heads=h,secs=s[,trans=t]][,snapshot=on|off]
[,cache=writethrough|writeback|none|directsync|unsafe][,format=f]
[,serial=s][,addr=A][,rerror=ignore|stop|report]
[,werror=ignore|stop|report|enospc][,id=name][,aio=threads|native]
[,readonly=on|off][,copy-on-read=on|off]
[,discard=ignore|unmap][,detect-zeroes=on|off|unmap]
[[,bps=b]|[[,bps_rd=r][,bps_wr=w]]]
[[,iops=i]|[[,iops_rd=r][,iops_wr=w]]]
[,bps_max=bm][[,bps_rd_max=rm][,bps_wr_max=wm]]]
[,iops_max=im][[,iops_rd_max=irm][,iops_wr_max=iwm]]]
[[,iops_size=is]]
use 'file' as a drive image
-mtdblock file use 'file' as on-board Flash memory image
-sd file use 'file' as SecureDigital card image
-pflash file use 'file' as a parallel flash image
-snapshot write to temporary files instead of disk image files
-hdachs c,h,s[,t]
force hard disk 0 physical geometry and the optional BIOS
translation (t=none or lba) (usually QEMU can guess them)
-fsdev fsdriver,id=id[,path=path,][security_model={mapped-xattr|mapped-file|passthrough|none}]
[,writeout=immediate][,readonly][,socket=socket|sock_fd=sock_fd]
-virtfs local,path=path,mount_tag=tag,security_model=[mapped-xattr|mapped-file|passthrough|none]
[,writeout=immediate][,readonly][,socket=socket|sock_fd=sock_fd]
-virtfs_synth Create synthetic file system image

USB options:
-usb enable the USB driver (will be the default soon)
-usbdevice name add the host or guest USB device 'name'

Display options:
-display sdl[,frame=on|off][,alt_grab=on|off][,ctrl_grab=on|off]
[,window_close=on|off]|curses|none|
gtk[,grab_on_hover=on|off]|
vnc=<display>[,<optargs>]
select display type
-nographic disable graphical output and redirect serial I/Os to console
-curses use a curses/ncurses interface instead of SDL
-no-frame open SDL window without a frame and window decorations
-alt-grab use Ctrl-Alt-Shift to grab mouse (instead of Ctrl-Alt)
-ctrl-grab use Right-Ctrl to grab mouse (instead of Ctrl-Alt)
-no-quit disable SDL window close capability
-sdl enable SDL
-spice [port=port][,tls-port=secured-port][,x509-dir=<dir>]
[,x509-key-file=<file>][,x509-key-password=<file>]
[,x509-cert-file=<file>][,x509-cacert-file=<file>]
[,x509-dh-key-file=<file>][,addr=addr][,ipv4|ipv6|unix]
[,tls-ciphers=<list>]
[,tls-channel=[main|display|cursor|inputs|record|playback]]
[,plaintext-channel=[main|display|cursor|inputs|record|playback]]
[,sasl][,password=<secret>][,disable-ticketing]
[,image-compression=[auto_glz|auto_lz|quic|glz|lz|off]]
[,jpeg-wan-compression=[auto|never|always]]
[,zlib-glz-wan-compression=[auto|never|always]]
[,streaming-video=[off|all|filter]][,disable-copy-paste]
[,disable-agent-file-xfer][,agent-mouse=[on|off]]
[,playback-compression=[on|off]][,seamless-migration=[on|off]]
enable spice
at least one of {port, tls-port} is mandatory
-portrait rotate graphical output 90 deg left (only PXA LCD)
-rotate <deg> rotate graphical output some deg left (only PXA LCD)
-vga [std|cirrus|vmware|qxl|xenfb|tcx|cg3|none]
select video card type
-full-screen start in full screen
-vnc display start a VNC server on display

i386 target only:
-win2k-hack use it when installing Windows 2000 to avoid a disk full bug
-no-fd-bootchk disable boot signature checking for floppy disks
-no-acpi disable ACPI
-no-hpet disable HPET
-acpitable [sig=str][,rev=n][,oem_id=str][,oem_table_id=str][,oem_rev=n][,asl_compiler_id=str][,asl_compiler_rev=n][,{data|file}=file1[:file2]...]
ACPI table description
-smbios file=binary
load SMBIOS entry from binary file
-smbios type=0[,vendor=str][,version=str][,date=str][,release=%d.%d]
[,uefi=on|off]
specify SMBIOS type 0 fields
-smbios type=1[,manufacturer=str][,product=str][,version=str][,serial=str]
[,uuid=uuid][,sku=str][,family=str]
specify SMBIOS type 1 fields
-smbios type=2[,manufacturer=str][,product=str][,version=str][,serial=str]
[,asset=str][,location=str]
specify SMBIOS type 2 fields
-smbios type=3[,manufacturer=str][,version=str][,serial=str][,asset=str]
[,sku=str]
specify SMBIOS type 3 fields
-smbios type=4[,sock_pfx=str][,manufacturer=str][,version=str][,serial=str]
[,asset=str][,part=str]
specify SMBIOS type 4 fields
-smbios type=17[,loc_pfx=str][,bank=str][,manufacturer=str][,serial=str]
[,asset=str][,part=str][,speed=%d]
specify SMBIOS type 17 fields

Network options:
-net nic[,vlan=n][,macaddr=mac][,model=type][,name=str][,addr=str][,vectors=v]
create a new Network Interface Card and connect it to VLAN 'n'
-net user[,vlan=n][,name=str][,net=addr[/mask]][,host=addr][,restrict=on|off]
[,hostname=host][,dhcpstart=addr][,dns=addr][,dnssearch=domain][,tftp=dir]
[,bootfile=f][,hostfwd=rule][,guestfwd=rule][,smb=dir[,smbserver=addr]]
connect the user mode network stack to VLAN 'n', configure its
DHCP server and enabled optional services
-net tap[,vlan=n][,name=str][,fd=h][,fds=x:y:...:z][,ifname=name][,script=file][,downscript=dfile][,helper=helper][,sndbuf=nbytes][,vnet_hdr=on|off][,vhost=on|off][,vhostfd=h][,vhostfds=x:y:...:z][,vhostforce=on|off][,queues=n]
connect the host TAP network interface to VLAN 'n'
use network scripts 'file' (default=/etc/qemu-ifup)
to configure it and 'dfile' (default=/etc/qemu-ifdown)
to deconfigure it
use '[down]script=no' to disable script execution
use network helper 'helper' (default=/usr/lib/qemu/qemu-bridge-helper) to
configure it
use 'fd=h' to connect to an already opened TAP interface
use 'fds=x:y:...:z' to connect to already opened multiqueue capable TAP interfaces
use 'sndbuf=nbytes' to limit the size of the send buffer (the
default is disabled 'sndbuf=0' to enable flow control set 'sndbuf=1048576')
use vnet_hdr=off to avoid enabling the IFF_VNET_HDR tap flag
use vnet_hdr=on to make the lack of IFF_VNET_HDR support an error condition
use vhost=on to enable experimental in kernel accelerator
(only has effect for virtio guests which use MSIX)
use vhostforce=on to force vhost on for non-MSIX virtio guests
use 'vhostfd=h' to connect to an already opened vhost net device
use 'vhostfds=x:y:...:z to connect to multiple already opened vhost net devices
use 'queues=n' to specify the number of queues to be created for multiqueue TAP
-net bridge[,vlan=n][,name=str][,br=bridge][,helper=helper]
connects a host TAP network interface to a host bridge device 'br'
(default=br0) using the program 'helper'
(default=/usr/lib/qemu/qemu-bridge-helper)
-net l2tpv3[,vlan=n][,name=str],src=srcaddr,dst=dstaddr[,srcport=srcport][,dstport=dstport],txsession=txsession[,rxsession=rxsession][,ipv6=on/off][,udp=on/off][,cookie64=on/off][,counter][,pincounter][,txcookie=txcookie][,rxcookie=rxcookie][,offset=offset]
connect the VLAN to an Ethernet over L2TPv3 pseudowire
Linux kernel 3.3+ as well as most routers can talk
L2TPv3. This transport allows connecting a VM to a VM,
VM to a router and even VM to Host. It is a nearly-universal
standard (RFC3391). Note - this implementation uses static
pre-configured tunnels (same as the Linux kernel).
use 'src=' to specify source address
use 'dst=' to specify destination address
use 'udp=on' to specify udp encapsulation
use 'srcport=' to specify source udp port
use 'dstport=' to specify destination udp port
use 'ipv6=on' to force v6
L2TPv3 uses cookies to prevent misconfiguration as
well as a weak security measure
use 'rxcookie=0x012345678' to specify a rxcookie
use 'txcookie=0x012345678' to specify a txcookie
use 'cookie64=on' to set cookie size to 64 bit, otherwise 32
use 'counter=off' to force a 'cut-down' L2TPv3 with no counter
use 'pincounter=on' to work around broken counter handling in peer
use 'offset=X' to add an extra offset between header and data
-net socket[,vlan=n][,name=str][,fd=h][,listen=[host]:port][,connect=host:port]
connect the vlan 'n' to another VLAN using a socket connection
-net socket[,vlan=n][,name=str][,fd=h][,mcast=maddr:port[,localaddr=addr]]
connect the vlan 'n' to multicast maddr and port
use 'localaddr=addr' to specify the host address to send packets from
-net socket[,vlan=n][,name=str][,fd=h][,udp=host:port][,localaddr=host:port]
connect the vlan 'n' to another VLAN using an UDP tunnel
-net dump[,vlan=n][,file=f][,len=n]
dump traffic on vlan 'n' to file 'f' (max n bytes per packet)
-net none use it alone to have zero network devices. If no -net option
is provided, the default is '-net nic -net user'
-netdev [user|tap|bridge|vhost-user|socket|hubport],id=str[,option][,option][,...]

Character device options:
-chardev null,id=id[,mux=on|off]
-chardev socket,id=id[,host=host],port=port[,to=to][,ipv4][,ipv6][,nodelay][,reconnect=seconds]
[,server][,nowait][,telnet][,reconnect=seconds][,mux=on|off] (tcp)
-chardev socket,id=id,path=path[,server][,nowait][,telnet][,reconnect=seconds][,mux=on|off] (unix)
-chardev udp,id=id[,host=host],port=port[,localaddr=localaddr]
[,localport=localport][,ipv4][,ipv6][,mux=on|off]
-chardev msmouse,id=id[,mux=on|off]
-chardev vc,id=id[[,width=width][,height=height]][[,cols=cols][,rows=rows]]
[,mux=on|off]
-chardev ringbuf,id=id[,size=size]
-chardev file,id=id,path=path[,mux=on|off]
-chardev pipe,id=id,path=path[,mux=on|off]
-chardev pty,id=id[,mux=on|off]
-chardev stdio,id=id[,mux=on|off][,signal=on|off]
-chardev braille,id=id[,mux=on|off]
-chardev serial,id=id,path=path[,mux=on|off]
-chardev tty,id=id,path=path[,mux=on|off]
-chardev parallel,id=id,path=path[,mux=on|off]
-chardev parport,id=id,path=path[,mux=on|off]
-chardev spicevmc,id=id,name=name[,debug=debug]
-chardev spiceport,id=id,name=name[,debug=debug]

Device URL Syntax:
-iscsi [user=user][,password=password]
[,header-digest=CRC32C|CR32C-NONE|NONE-CRC32C|NONE
[,initiator-name=initiator-iqn][,id=target-iqn]
iSCSI session parameters
Bluetooth(R) options:
-bt hci,null dumb bluetooth HCI - doesn't respond to commands
-bt hci,host[:id]
use host's HCI with the given name
-bt hci[,vlan=n]
emulate a standard HCI in virtual scatternet 'n'
-bt vhci[,vlan=n]
add host computer to virtual scatternet 'n' using VHCI
-bt device:dev[,vlan=n]
emulate a bluetooth device 'dev' in scatternet 'n'

TPM device options:
-tpmdev passthrough,id=id[,path=path][,cancel-path=path]
use path to provide path to a character device; default is /dev/tpm0
use cancel-path to provide path to TPM's cancel sysfs entry; if
not provided it will be searched for in /sys/class/misc/tpm?/device

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

Debug/Expert options:
-serial dev redirect the serial port to char device 'dev'
-parallel dev redirect the parallel port to char device 'dev'
-monitor dev redirect the monitor to char device 'dev'
-qmp dev like -monitor but opens in 'control' mode
-qmp-pretty dev like -qmp but uses pretty JSON formatting
-mon [chardev=]name[,mode=readline|control][,default]
-debugcon dev redirect the debug console to char device 'dev'
-pidfile file write PID to 'file'
-singlestep always run in singlestep mode
-S freeze CPU at startup (use 'c' to start execution)
-realtime [mlock=on|off]
run qemu with realtime features
mlock=on|off controls mlock support (default: on)
-gdb dev wait for gdb connection on 'dev'
-s shorthand for -gdb tcp::1234
-d item1,... enable logging of specified items (use '-d help' for a list of log items)
-D logfile output log to logfile (default stderr)
-L path set the directory for the BIOS, VGA BIOS and keymaps
-bios file set the filename for the BIOS
-enable-kvm enable KVM full virtualization support
-xen-domid id specify xen guest domain id
-xen-create create domain using xen hypercalls, bypassing xend
warning: should not be used when xend is in use
-xen-attach attach to existing xen domain
xend will use this when starting QEMU
-no-reboot exit instead of rebooting
-no-shutdown stop before shutdown
-loadvm [tag|id]
start right away with a saved state (loadvm in monitor)
-daemonize daemonize QEMU after initializing
-option-rom rom load a file, rom, into the option ROM space
-rtc [base=utc|localtime|date][,clock=host|rt|vm][,driftfix=none|slew]
set the RTC base and clock, enable drift fix for clock ticks (x86 only)
-icount [shift=N|auto][,align=on|off]
enable virtual instruction counter with 2^N clock ticks per
instruction and enable aligning the host and virtual clocks
-watchdog i6300esb|ib700
enable virtual hardware watchdog [default=none]
-watchdog-action reset|shutdown|poweroff|pause|debug|none
action when watchdog fires [default=reset]
-echr chr set terminal escape character instead of ctrl-a
-virtioconsole c
set virtio console
-show-cursor show cursor
-tb-size n set TB size
-incoming tcp:[host]:port[,to=maxport][,ipv4][,ipv6]
-incoming rdma:host:port[,ipv4][,ipv6]
-incoming unix:socketpath
prepare for incoming migration, listen on
specified protocol and socket address
-incoming fd:fd
-incoming exec:cmdline
accept incoming migration on given file descriptor
or from given external command
-nodefaults don't create default devices
-chroot dir chroot to dir just before starting the VM
-runas user change to user id user just before starting the VM
-sandbox <arg> Enable seccomp mode 2 system call filter (default 'off').
-readconfig <file>
-writeconfig <file>
read/write config file
-nodefconfig
do not load default config files at startup
-no-user-config
do not load user-provided config files at startup
-trace [events=<file>][,file=<file>]
specify tracing options
-enable-fips enable FIPS 140-2 compliance
-object TYPENAME[,PROP1=VALUE1,...]
create an new object of type TYPENAME setting properties
in the order they are specified. Note that the 'id'
property must be set. These objects are placed in the
'/objects' path.
-msg timestamp[=on|off]
change the format of messages
on|off controls leading timestamps (default:on)
-dump-vmstate <file>
Output vmstate information in JSON format to file.
Use the scripts/vmstate-static-checker.py file to
check for possible regressions in migration code
by comparing two such vmstate dumps.
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.





[url=http://blog.csdn.net/ustc_dylan/article/details/5385691]KVM虛擬機和QEMU(命令行選項) [/url]
[quote]
# qemu-kvm -m 512 -hda xp.img -net nic,macaddr=00:00:11:33:02:02 /

-net tap,ifname=tap2,script=/etc/init.d/qemu-ifup /

-localtime -vnc 172.16.70.30:2 --daemonize

上面讓kvm虛擬機在後臺運行,並啟動vnc伺服器,這樣我們可以用vnc客 戶端連結172.16.70.30:5092這個地址。
QEMU選項:
一般選項

-M machine
選擇模擬的機器(我們可以輸入-M?提到一個模擬的機器列表)
-fda file
-fdb file
使用file作為軟盤鏡像.我們也可以通過將/dev/fd0作為文件名來使用主機軟盤.
-hda file
-hdb file
-hdc file
-hdd file
使用file作為硬碟0,1,2,3的鏡像.
-cdrom file
使用文件作為CD-ROM鏡像(但是我們不可以同時使 用'-hdc'和'-cdrom').我們可以通過使用'/dev/cdrom'作為文件名來 使用主機的CD-ROM.
-boot [a|c|d]
由軟盤(a),硬碟(c)或是CD-ROM(d).在默認的情況下由硬碟啟動.
-snapshot
寫入臨時文件而不是寫入磁碟鏡像文件.在這樣的情況下,並沒有寫回 我們所使用的磁碟鏡像文件.然而我們卻可以通過按下C-a s來強制寫 回磁碟鏡像文件.
-m megs
設置虛擬內存尺寸為megs M字節.在默認的情況下為128M.
-smp n
模擬一個有n個CPU的SMP系統.為PC機為目標,最多可以支持255個CPU.
-nographic
在通常情況下,Qemu使用SDL來顯示VGA輸出.使用這個選項,我們可以 禁止所有的圖形輸出,這樣Qemu只是一個簡單的命令行程序.模擬的串 口將會重定向到命令行.所以,我們仍然可以在Qemu平臺上使用串口命 令來調試Linux內核.
-k language
使用鍵盤布局語言(例如fr為法語).這個選項只有在不易得到PC鍵盤 的情況下使用.我們在PC/Linux或是PC/Windows主機不需要使用這個 選項.默認的為en-us,可用的布局如下:

ar de-ch es fo fr-ca hu ja mk no pt-br sv

da en-gb et fr fr-ch is lt nl pl ru th

de en-us fi fr-be hr it lv nl-be pt sl tr

-audio-help
這個選項將會顯示聲音子系統的幫助:驅動列表以及可調用的參數.
-soundhw card1,card2 .... or -soundhw all
允許聲音並選擇聲音硬體.使用?可以列出所有可用的聲音硬體

qemu -soundhw sb16,adlib hda

qemu -soundhw es1370 hda

qemu -soundhw all hda

qemu -soundhw ?

-localtime
設置時鐘為本地時間(默認為UTC時間).如果在MS-DOS或是Windows上 這個選項則需要正確的日期.
-full-screen
以全屏方式啟動.
-pidfile file
在file文件中存許Qemu的進程PID.如果我們是由腳本啟動的,這個選 項是相當有用的.
-win2k-hack
當安裝Windows 2000時可以使用這個選項來避免磁碟錯誤.在安裝上 Windows 2000系統,我們就不再需要這個選項(這個選項降低IDE的傳 輸速度).

USB選項

-usb
允許USB驅動(很快就將成為默認的選項)
-usbdevice devname
添加USB設備名.我們可以查看監視器命令usb_add來得到更為詳細的信息.

網絡選項

-net nic[,vlan=n][,macaddr=addr]
創建一個新的網卡並與VLAN n(在默認的情況下n=0)進行連接.在PC機 上,NIC當前為NE2000.作為可選項的項目,MAC地址可以進行改變.如果 沒有指定-net選項,則會創建一個單一的NIC.
-net user[,vlan=n]
使用用戶模式網絡堆棧,這樣就不需要管理員權限來運行.如果沒有指 定-net選項,這將是默認的情況.
-net tap[,vlan=n][,fd=h][,ifname=name][,script=file]
將TAP網絡接口name與VLAN n進行連接,並使用網絡配置腳本file進行 配置.默認的網絡配置腳本為/etc/qemu-ifup.如果沒有指定name,OS 將會自動指定一個.fd=h可以用來指定一個已經打開的TAP主機接口的 句柄.例如:

qemu linux.img -net nic -net tap

下面的是一個更為複雜的例子(兩個NIC,每一個連接到一個TAP設備):

qemu linux.img -net nic,vlan=0 -net tap,vlan=0,ifname=tap0 /

-net nic,vlan=1 -net tap,vlan=1,ifname=tap1

-net socket[,vlan=n][,fd=h][,listen=[host]:port][,connect=host:port]
使用TCP socket 將VLAN n與遠程的另一個Qemu虛擬機的VLAN進行連 接.如果指定了listen,Qemu將在port埠監聽連入請求(host是可選 的), connect可以用來使用listen選項與另一個Qemu實例進行連 接.fd=h指定了一個已經打開的TCP socket.例如:

# launch a first QEMU instance

qemu linux.img -net nic,macaddr=52:54:00:12:34:56 -net socket,listen=:1234

# connect the VLAN 0 of this instance to the VLAN 0 of the first instance

qemu linux.img -net nic,macaddr=52:54:00:12:34:57 -net

socket,connect=127.0.0.1:1234

-net socket[,vlan=n][,fd=h][,mcast=maddr:port]
創建一個VLAN n,並使用UDP 多址通信套掊口與其他的QEMU虛擬機進 行共享,尤其是對於每一個使用多址通信地址和埠的QEMU使用同一 個總線. 在這裡我們要注意以下幾點:

幾個QEMU可以運行在不同的主機上但卻使用同一個總線(在這裡假設 為這些主機設置了正確的多址通信)
mcast支持是與用戶模式Linux相兼容的.
使用fd=h指定一個已經打開的UDP 多址通信套接口.

例如:

# launch one QEMU instance

qemu linux.img -net nic,macaddr=52:54:00:12:34:56 -net

socket,mcast=230.0.0.1:1234

# launch another QEMU instance on same "bus"

qemu linux.img -net nic,macaddr=52:54:00:12:34:57 -net

socket,mcast=230.0.0.1:1234

# launch yet another QEMU instance on same "bus"

qemu linux.img -net nic,macaddr=52:54:00:12:34:58 -net

socket,mcast=230.0.0.1:1234

下面的為用戶模式Linux的例子:

# launch QEMU instance (note mcast address selected is UML's default)

qemu linux.img -net nic,macaddr=52:54:00:12:34:56 -net

socket,mcast=239.192.168.1:1102

# launch UML

/path/to/linux ubd0=/path/to/root_fs eth0=mcast

-net none
表明沒有網絡設備需要進行配置.如果沒有指定-net選項,則會用來覆 蓋活躍的默認配置.
-tftp prefix
當使用用戶模式網絡堆棧,激活一個內置的TFTP伺服器.所有的以 prefix開始的文件將會使用一個TFTP客戶端從主機下載到本地.在本 地的TFTP客戶端必須以二進位模式進行配置(使用Unix的TFTP客戶端 的bin命令).在客戶機上的主機IP位址如通常的10.0.2.2.
-smb dir
-redir [tcp|udp]:host-port:[guest-host]:guest-port
當使用用戶模式網格棧,將連接到主機埠host-port的TCP或是UDP 連接重定向到客戶機埠guest-port上。如果沒有指定客戶機埠, 他的值為10.0.2.15(由內建的DHCP伺服器指定默認地址)。例如: 要重定向從screen 1到客戶機screen 0的X11連接,我們可以使用下 面的方法:

# on the host

qemu -redir tcp:6001::6000 [...]

# this host xterm should open in the guest X11 server

xterm -display :1

To redirect telnet connections from host port 5555 to telnet port on

the guest, use the following:


# on the host

qemu -redir tcp:5555::23 [...]

telnet localhost 5555

然後當我們在主機telnet localhost 5555上使用時,我們連接到了 客戶機的telnet伺服器上。

Linux啟動選項

當我們使用這些選項時,我們可以使用一個指定的內核,而沒有將他 安裝在磁碟鏡像中。這對於簡單的測試各種內核是相當有用的。

`-kernel bzImage'
使用bzImage作為內核映像。
`-append cmdline'
使用cmdline作為內核的命令行。
`-initrd file'
使用file作為初始的ram磁碟。

調試選項

`-serial dev'
重定向虛擬串到主機的設備dev。可用的設備如下:
vc
虛擬終端
pty
(Linux)偽TTY(自動分配一個新的TTY)
null
空設備
/dev/XXX"
(Linux)使用主機的tty。例如,'/dev/ttyS0'。主機的串口參數通過模擬進行設置。
/dev/parportN
(Linux)使用主機的並口N。當前只可以使用SPP的並口特徵。
file:filename
將輸出寫入到文件filename中。沒有字符可讀。
stdio
(Unix)標準輸入/輸出
pipe:filename
(Unix)有名管道filename

在圖形模式下的默認設備為vc,而在非圖形模式下為stdio.這個選項 可以被多次使用,最多可以模擬4個串口。

'-parallel dev'

重定向虛擬並口到主機的設備dev(與串口相同的設備)。在Linux主 機上,`/dev/parportN'可以被用來使用與相應的並口相連的硬體設 備。這個選項可以使用多次,最多可以模擬3個並口。
`-monitor dev'

重定向臨視器到主機的設備dev(與串口相同的設備)。在圖形模式 下的默認設備為vc,而在非圖形模式下為stdio。
'-s'
等待gdb連接到埠1234.
`-p port'
改變gdb連接埠。
`-S'
在啟動時並不啟動CPU(我們必須在監視器中輸入'c')
'-d'
輸出日誌到/tmp/qemu.log
`-hdachs c,h,s,[,t]'
強制硬碟0的物理參數(1 <= c <= 16383, 1 <= h <= 16, 1 <= s <=63),並且可以選擇強制BIOS的轉換模式(t=none, lba or auto).通 常QEMU可以檢測這些參數.這個選項對於老的MS-DOS磁碟映像是相當 有用的.
`-std-vga'
模擬一個Bochs VBE擴展的標準VGA顯卡(默認情況下為Cirrus Logic GD5446 PCI VGA)
`-loadvm file'
從一個保存狀態啟動.

組合鍵

在圖形模擬時,我們可以使用下面的這些組合鍵:

Ctrl-Alt-f
全屏
Ctrl-Alt-n
切換虛擬終端'n'.標準的終端映射如下:

n=1 : 目標系統顯示
n=2 : 臨視器
n=3 : 串口

Ctrl-Alt
抓取滑鼠和鍵盤

在虛擬控制臺中,我們可以使用Ctrl-Up, Ctrl-Down, Ctrl-PageUp 和 Ctrl-PageDown在屏幕中進行移動.

在模擬時,如果我們使用`-nographic'選項,我們可以使用Ctrl-a h來得到終端命令:

Ctrl-a h
列印幫助信息
Ctrl-a x
退出模擬
Ctrl-a s
將磁碟信息保存入文件(如果為-snapshot)
Ctrl-a b
發出中斷
Ctrl-a c
在控制臺與監視器進行切換
Ctrl-a Ctrl-a
發送Ctrl-a

磁碟映像

從0.6.1起,QEMU支持多種磁碟映像格式,包括增長的磁碟映像,壓縮與加 密的磁碟映像.

我們可以用下面的命令來創建一個磁碟映像:

qemu-img create myimage.img mysize

這裡myimage.img是磁碟映像的文件名,而mysize是以K表示的尺寸.我們 可以使用M前綴來使用M表示尺寸或是G作為前綴使用G表示尺寸.

qemu-img選項

可以支持下面的一些命令:

`create [-e] [-b base_image] [-f fmt] filename [size]'

`commit [-f fmt] filename'

`convert [-c] [-e] [-f fmt] filename [-O output_fmt] output_filename'

`info [-f fmt] filename

命令參數

filename
磁碟映像文件名.
base_image
只讀的磁碟映像,可以作為拷貝到寫映像的基礎.寫映像 上的拷貝只存儲修改的數據.
fmt
磁碟映像格式.在大多數情況下可以自動檢測.可以支持下面的格式:

raw

raw 磁碟格式(默認).這種格式有簡單並且易於移植到其他模擬器的 優點.如果我們的文件系統支持holes(例如在Linux上的ext2或是 ext3),然後只有寫入的部分保持空白.使用qemu-img info來得到映 像使用的實際的大小或是在Unix/Linux上使用 ls -ls.
qcow

QEMU映像格式.最通用的格式.使用他可以獲得較小的映像(如果我們 的文件系統不支持holes,例如在Windows上,這是相當有用的),可以 選用AES加密或是基於zlib的壓縮.
cow

在寫映像格式上的用戶模式的Linux拷貝.在QEMU中作為增長的映像 格式使用.這個選項只是為了與以前版本的兼容,並不能在Win32上使 用.
vmdk

VMware 3 或是 4 兼容的映像格式.
cloop

Linux壓縮的循環映像,重用直接壓縮的CD-ROM映像.
size

以K表示的磁碟映像的尺寸.同時可以支持M或是G作為前綴.
output_filename

目的磁碟映像文件名
output_fmt

目標格式
-c

表明目標映像必須是壓縮的(只是qcow格式)
-e

表明目標映像必須是加密的(只是qcow格式)

[/quote]

相關焦點

  • C語言|命令行參數
    執行程序時,可以從命令行傳值給 C 程序。這些值被稱為命令行參數,它們對程序很重要,特別是當您想從外部控制程序,而不是在代碼內對這些值進行硬編碼時,就顯得尤為重要了。
  • RT-Thread教程一之Linux下開發環境及QEMU配置
    ,進入該目錄後可發現如下文件qemu-vexpress-a9 git:(master) tree .├── qemu-dbg.bat├── qemu-dbg.sh├── qemu-nographic.sh├── qemu.sh //這是我們的啟動腳本├── README.md├── rtconfig.h├── rtconfig.py├── rtconfig.pyc├
  • Python 命令行參數解析庫argparse
    output_source_dir,feature,levels,但是該函數print不能在命令行運行,只能在腳本內部調用,於是我們需要python標準庫內的argparse[1]來幫忙。使用步驟:1)import argparse    首先導入模塊2)parser = argparse.ArgumentParser()    創建一個解析對象3)parser.add_argument()    向該對象中添加你要關注的命令行參數和選項4)parser.parse_args()    進行解析對於第
  • Win10 學院:Setup.exe 命令行參數詳解
    通過在其後面添加各種各樣的命令行參數,我們可以在某種程度上自定義Windows10的安裝行為。下面,Win10之家也為大家帶來了部分命令行參數詳解。 ▼Win10系統安裝程序Setup.exe命令行參數詳解:
  • cUrl命令行工具下載使用心得及常用參數解釋
    主要的區別在於wget默認是保存到文件,而curl將輸出定向到命令行上。這使得curl能非常方便的查看站點的內容。如何下載Curl命令行工具?1. 進入下載頁,選擇需要的版本(適合自身作業系統): https://curl.haxx.se/download.html2. 根據自己的作業系統位數和是否需要SSL下載相應的版本。
  • 3分鐘短文:Laravel命令行的參數和可選項,分不清?怎麼可能!
    引言上一期我們介紹了laravel命令行的創建,以及使用方法。使用了一個沒有數據輸入和輸出的測試用例。 本期我們來介紹帶有命令行參數輸入,和命令行輸出信息的代碼用法。代碼時間聲明命令行位置參數,在類文件內$signature變量內書寫:protected $signature = 'password:reset {userId} {--sendEmail}';其中 userId是必填參數,需要填入一個數據;而 sendEmail 則是一個開關, 如果在命令行中帶有 --sendEmail 則返回true,否則返回默認值
  • 【python】命令行參數argparse用法詳解
    定義了一個叫echo的參數,默認必選中文名叫可選參數,有兩種方式:一種是通過一個-來指定的短參數,如-h;一種是通過--來指定的長參數,如--help測試1中,通過-v來指定參數值測試2中,通過--verbosity來指定參數值測試3中,通過-h來列印幫助信息測試4中,沒有給-v指定參數值,所以會報錯上一個用法中-v必須指定參數值
  • 命令行工具開發:如何快速實現命令行提示?
    不少同學喜歡開發命令行工具,主要是開發快捷,而且和其他命令行工具配合,藉助腳本,非常容易實現一些任務的自動化。命令行工具開發比較簡單,以Java舉一個例子,通常我們只需要一個命令行參數解析器,如Java,就有args4j, jopt,picocli等,轉換為結構化的對象,根據輸入的參數進行相關的邏輯判斷,完成對應的邏輯。
  • Android ADB 命令行
    用了 MBP,一直有個問題,不能像 Windows 一樣直接拷貝文件到手機 SD 卡上,Android ADB 好像可以直接拷貝,但由於忙,沒有去詳細了解,最近剛需,要解決,於是系列學習了 ADB 知識,發現新大陸,沒想到 ADB 這麼強大,以下是我記錄了 ADB 較常用的命令行,還有很多值得您去深掘,去學習。
  • Fragstats官方入門教程5 從R運行命令行版本的Fragstats
    教程5 從R運行命令行版本的FRAGSTATS在本教程中,你將從R運行命令行版本的FRAGSTATS:R開發核心團隊(2008年):R:一種用於統計計算的語言和環境。R統計計算基金會,奧地利,維也納。ISBN 3-900051-07-0, URL http://www.R-project.org。
  • python命令參數及模塊的導入學習
    python已經成為程式語言排行榜的老大了,要向不被時代淘汰,就要緊跟時代步伐,在IT編程世界的今天,不會python可是不行的,今天繼續學習python的命令及相關模塊導入學習。import 與 from...import
  • Linux運維中比較常見命令及參數
    tar參數:-c:建立一個壓縮文件的參數命令(create的意思)-x:解開一個壓縮文件的參數命令-t:查看tarfile裡面的文件(在參數執行時,c/x/t 僅能存在一個,因為不可能同時壓縮和解壓縮)
  • Python 命令行之旅:使用 docopt 實現 git 命令
    docopt不同於使用 argparse 時需要考慮嵌套解析器、各類參數等問題,在使用 docopt 只需將我們要實現的 git 命令用接口描述先定義清楚即可。程序結構程序結構上,除了開頭處定義接口描述外,其餘和使用 argparse 實現 git 命令的結構是一樣的:命令行程序需要一個 cli 函數來作為統一的入口,它負責構建解析器,並解析命令行參數我們還需要四個 handle_xxx 函數響應對應的子命令則基本結構如下:import osimport docoptfrom git.cmd import
  • JVM 常用命令行工具
    (JVM Statistics Monitoring Tool)是用於監視虛擬機各種運行狀態信息的命令行工具,可以顯示本地或者遠程虛擬機進程中的類加載、內存、垃圾收集、即時編譯等運行時數據jstat [ option vmid [interval[s|ms] [count]] ]如果是本地虛擬機進程,VMID 與 LVMID 是一致的;如果是遠程虛擬機進程,那 VMID
  • C語言命令行參數如何解析?你經常用的終端怎麼運行的你說不清楚!
    今天我們說下,命令行參數,我們在寫工具的時候,基本上都是帶著參數的。而在windows XP或更高版本,命令行的最大長度為8191個字符,Linux下可以用這個命令查看,getconf ARG_MAX,一般情況下都是比windows大很多。
  • Ping命令及其常用參數詳解
    一、命令原理Ping是ICMP的一個典型應用。Ping是檢測網絡連通的常用工具,同時也能收集其他相關信息。用戶可以在Ping命令中指定不同參數,如ICMP報文長度、發送的ICMP報文個數、等待回復響應的超時間等,設備根據配置的參數構造來發送ICMP報文,進行Ping測試。
  • Pytest之命令行執行
    使用Pyhton中的argparse可以實現與Jenkins中的參數化關聯起來,這樣建立一種機制後,我們只需要在參數化裡面定義我們需要被驗證的點來進行測試。如下代碼:#!/usr/bin/env python#!
  • cmd命令行 編譯Java 文件
    【問題引入】很多時候,需要用到命令行來進行Java文件的編譯。在用習慣了IDE 可能會不清楚如何在cmd命令行窗口進行編譯,簡單的都還好,帶有包路徑的可能會讓很多人覺得有點小頭疼。最近試了一下,發現了問題,就研究整理了一下記錄吧。
  • Python 命令行之旅:深入 argparse(二)
    劇照 | 《仙劍奇俠傳》前言在上一篇「深入 argparse (一)」的文章中,我們深入了解了 argparse 的包括參數動作和參數類別在內的基本功能,具備了編寫一個簡單命令行程序的能力。本文將繼續深入了解 argparse 的進階玩法,一窺探其全貌,助力我們擁有實現複雜命令行程序的能力。