ubuntu 虚拟化 KVM 或qemu 命令介绍

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.





KVM虚拟机和QEMU(命令行选项)
引用

# 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格式)

猜你喜欢

转载自powertech.iteye.com/blog/2293156