KVM Virtual Machine and QEMU

Source: Internet
Author: User

Install the KVM Virtual Machine and qemu kvm in Ubuntu [test environment 10.04] to install the kvm and nic bridging tools: sudo aptitude install kvm qemu bridge-utils uml-utilities configure the bridging network to first create a br0 device: brctl addbr br0 # after creating a bridge interface, you only need to add the NIC to this bridge interface: brctl addif br0 eth0 # Add eth0 to br0, important my network configuration file/etc/network/interfaces content is as follows: auto loiface lo inet loopback # auto eth0 # iface eth0 inet dhcp auto br0iface br0 inet dhcpbridge_ports eth0 main idea: configure the br0 interface to be the same as the previous normal network port (I am eth0 here), and then disable the previous network port configuration. (I commented out the eth0 configuration.) Add "bridge_ports eth0" in the br0 configuration ". Note: if the address is a static address, you can change it according to the corresponding settings. Start a virtual machine and configure it. How to Use it varies from person to person. I use it in the background and use vnc to remotely connect to the virtual machine. Therefore, I use the following small script to start uqkvm (if you do not know vnc, or do not understand shell script, the following instructions may be useless to you. Due to limited energy and capabilities, only scripts are provided below, which cannot be described one by one .) :#! /Bin/sh # Introduction: Try KVM quickly # KVM_CMD =/usr/bin/kvmQEMU_IFUP =/etc/init. d/qemu-ifupHOST = 172.16.70.3 # default MEM = 512 # Memory TAP = 2 # Number of NICs (0 <TAP <10) # Your DISK image DISK = # all other kvm parameters OTHER = test-n "$1" & TAP = $1 test-n "$ DISK" & HDA =" -hda $ DISK "| HDA ="-hda $2 "shift 2 OTHER =$ @ # specify NET ="-net nic, macaddr = 32: 32: 32: 32: 32: 3 $ TAP-net tap, ifname = tap $ TAP, script = $ QEMU_IFUP "VNC ="-vnc $ HOST: $ TAP "RUN_CMD =" $ KV M_CMD-m $ MEM $ HDA $ NET $ VNC-localtime -- daemonize $ OTHER "echo" run the command: $ RUN_CMD "$ RUN_CMD if test $? = 0; then echo "KVM runs successfully. Please use VNC link $ HOST: $ TAP..." exit 0 else echo "KVM failed to run. Please check whether the command line has an error! The/etc/init. d/qemu-ifup file used in exit 1fi is as follows :#! /Bin/bash switch = br0 if [-n "$1"]; then/sbin/ip link set $1 up sleep 0.5 s/usr/sbin/brctl addif $ switch $1 exit 0 else echo "Error: no interface specified "exit 1 fiuqkvm script is used as follows :. /uqkvm 3 GreenOS. img-cdrom/data/lab/LessWatts/GTGS-lesswatts_xfce-201004201555.iso-boot d if you only need to start the system :#. /uqkvm 3 GreenOS. run the command:/usr/bin/kvm-m 512-hda GreenOS. img-net nic, macaddr = 32: 32: 32: 32: 32: 33-net tap, ifname = t Ap3, script =/etc/init. d/qemu-ifup-vnc 172.16.70.3: 3-localtime -- daemonizepci_add_option_rom: failed to find romfile "pxe-rtl8139.bin" KVM run successfully, please use VNC link 172.16.70.3: 3... view the bridging device information: $ sudo brctl showbridge name bridge id STP enabled interfacesbr0 8000.0001028c5009 no eth0 tap3 visible tap2 and eth0 are on br0. RHEL/Fedora/CentOSyum install bridge-utils kvmbridge-utils is a NIC bridging tool. Example 1: redhat system KVM create disk # qemu-img create-f qcow2 turbo-10.5.5-rc2.img 20 GFormatting 'turbo-10.5.5-rc2.img ', fmt = qcow2, size = 20971520 kB # file turbo-10.5.5-rc2.imgturbo-10.5.5-rc2.img: QEMU Copy-On-Write disk image version 2, size 5 + 0 configure the network script under/etc/sysconfig/network-scripts # cat/etc/sysconfig/network-scripts/ifcfg-br0DEVICE = br0ON BOOT = yesBOOTPROTO = staticIPADDR = connector = 255.255.252.0GATEWAY = 172.16.68.1TYPE = Bridge # cat/etc/sysconfig/network-scripts/ifcfg-eth0 # 3Com Corporation 3c905B 100 BaseTX [Cyclone] DEVICE = eth0 # BOOTPROTO dhcp # HWADDR = 00: 01: 02: 8C: 50: 09 ONBOOT = yesBRIDGE = br0 adds a bridge network interface, add the configured eth0 to the bridge interface brctl addbr br0 # create a bridge interface brctl addif br0 eth0 # Add eth0 to br0. It is important to use the following script: # cat/etc/init. d/qemu-ifup #! /Bin/bash switch = br0 if [-n "$1"]; then/sbin/ip link set $1 up sleep 0.5 s/usr/sbin/brctl addif $ switch $1 exit 0 else echo "Error: no interface specified "exit 1fi you can use a bridge Nic to start qemu-kvm and use two files of GTES10.5.5 to install the system through NFS: # qemu-kvm-m 512-hda turbo-10.5.5-rc2.img-kernel vmlinuz \-initrd. img-net nic-net tap, script =/etc/init. d/qemu-ifup -- daemonize can also be installed using iso. In this way, linux of multiple iso distributions must change disks on the qemu console: # Qemu-kvm-m 512-hda turbo-10.5.5-rc2.img-cdrom your iso path \-net nic-net tap, script =/etc/init. d/qemu-ifup-boot d -- daemonize enter the qemu console, and press Ctrl + Alt + 2 to go to the console when you focus on the qemu interface: (qemu) change cdrom if the command above your other iso prompts "device not found ". A device ing error may occur. (qemu) info block... (qemu) change ide1-cd0 iso file QEMU common use vnc # 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 -- run the kvm Virtual Machine on daemonize and start the vnc server. In this way, we can use the vnc client to connect 172.16.70.30: 5092. QEMU option: general option-M machine: select the simulated machine (we can enter-M? -Fda file-fdb file uses file as a floppy disk image. we can also use the/dev/fd0 as the file name to use the host floppy disk. -hda file-hdb file-hdc file-hdd file uses file as the image of Hard Disk 0, 1, 2, and 3. -cdrom file uses a file as a CD-ROM image (but we cannot use '-hdc' and '-cdrom' at the same time '). we can use the CD-ROM of the host by using '/dev/cdrom' as the file name. -boot [a | c | d] By floppy disk (a), hard disk (c) or CD-ROM (d ). it is started by hard disk by default. -snapshot: Write a temporary file instead of a disk image file. in this case, the disk image file we use is not written back. however, we can forcibly write back the disk image file by pressing C-a s. -m megs: Set the virtual memory size to megs M bytes. the default value is MB. -smp n Mode An SMP system with n CPUs is proposed. it is the target PC and can support a maximum of 255 CPUs. -In general, Qemu uses SDL to display VGA output. with this option, we can disable all graphical output, so that Qemu is just a simple command line program. the simulated string port will be redirected to the command line. therefore, we can still use the serial port command on the Qemu platform to debug the Linux kernel. -k language uses the keyboard layout language (for example, fr is French ). this option is used only when it is difficult to obtain a PC keyboard. we do not need to use this option on PC/Linux or PC/Windows hosts. the default value is en-us. The available layout is as follows: ar de-ch es fo fr-ca hu ja mk no pt-br svda en-gb et fr-ch is lt nl pl ru thde en-us fi fr-be hr it lv nl-be pt sl tr-audio-he The lp option displays the Audio Subsystem help: Driver list and callable parameters. -soundhw card1, card2 .... or-soundhw all allows sound and selects sound hardware. use? Can I list all available sound hardware qemu-soundhw sb16, adlib hdaqemu-soundhw es1370 hdaqemu-soundhw all hdaqemu-soundhw? -Set the localtime to the local time (UTC time by default ). if this option is on MS-DOS or Windows, the correct date is required. -full-screen is enabled in full screen mode. -pidfile file stores the Qemu process PID in the file. this option is quite useful if it is started by a script. -win2k-hack can use this option when installing Windows 2000 to avoid disk errors. on Windows 2000, we no longer need this option (this option reduces the speed of IDE transmission ). USB option-usb allows a USB driver (which will soon become the default option)-Add a USB device name to the USB device devname. we can view the monitor command usb_add to obtain more detailed information. network option-net nic [, vlan = n] [, macaddr = addr] Create a New nic and connect to VLAN n (n = 0 by default. on PC, NIC is currently N E2000. as an option, the MAC address can be changed. if the-net option is not specified, a single NIC is created. -net user [, vlan = n] uses the user mode network stack, so that you do not need the Administrator permission to run. if the-net option is not specified, this will be the default situation. -net tap [, vlan = n] [, fd = h] [, ifname = name] [, script = file] connect the TAP Network Interface name with VLAN n, use the network configuration script file for configuration. the default network configuration script is/etc/qemu-ifup. if no name is specified, the OS will automatically specify one. fd = h can be used to specify the handle of an opened TAP host interface. for example: qemu linux. the img-net nic-net tap is a more complex example (two NICs, each connected to a TAP device): qemu linux. img-net nic, vlan = 0-net t Ap, 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] use TCP socket to connect VLAN n to the VLAN of another remote Qemu VM. if listen is specified, Qemu listens to the connection request on the port (host is optional). connect can be used to connect to another Qemu instance using the listen option. fd = h specifies an opened TCP socket. for example: # launch a first QEMU instanceqemu linux. img-net nic, macaddr = 52: 54: 00: 12: 34: 56-net socket, listen =: 1234 # connec T the VLAN 0 of this instance to the VLAN 0 of the first instanceqemu linux. img-net nic, macaddr = 52: 54: 00: 12: 34: 57-netsocket, connect = 127.0.0.1: 1234-net socket [, vlan = n] [, fd = h] [, mcast = maddr: port] creates a VLAN n, and shares it with other QEMU virtual machines using the UDP multi-address communication socket, in particular, each QEMU that uses a multi-access communication address and port uses the same bus. here we should pay attention to the following points: Several qemus can run on different hosts but use the same bus (Here we assume that correct multi-access communication is set for these hosts) mcast is compatible with Linux in user mode. use fd = h to specify an opened UDP multi-access communication set interface. example: # launch one QE MU instanceqemu linux. img-net nic, macaddr = 52: 54: 00: 12: 34: 56-netsocket, 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-netsocket, 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-netsocket, mcast = 230.0.0.1: 1234 example of Linux in user mode: # launch QEMU instance (note mcast ad Dress selected is UML's default) qemu linux. img-net nic, macaddr = 52: 54: 00: 12: 34: 56-netsocket, mcast = 239.192.168.1: 1102 # launch UML/path/to/linux ubd0 =/path/to/root_fs eth0 = mcast-net none indicates that no network device needs to be configured. if the-net option is not specified, it is used to override the active default configuration. -tftp prefix: when a user-mode network stack is used, a built-in TFTP server is activated. all files starting with prefix will be downloaded from the host to the local using a TFTP client. the local TFTP client must be configured in binary mode (using the bin command of the Unix TFTP client ). the Host IP address on the client is as follows. -smb dir-redir [tcp | ud P]: host-port: [guest-host]: guest-port when using the user mode grid stack, redirects the TCP or UDP connection that is connected to the host port to the client port guest-port. If no client port is specified, its value is 10.0.2.15 (the default address is specified by the built-in DHCP server ). For example, to redirect an X11 connection from screen 1 to screen 0 on the client, we can use the following method: # on the hostqemu-redir tcp: 6001: 6000 [...] # this host xterm shocould open in the guest X11 serverxterm-display: 1To redirect telnet connections from host port 5555 to telnet port onthe guest, use the following: # on the hostqemu-redir tcp: 5555: 23 [...] telnet localhost 5555 and then connect to the client's telnet server when we use it on the host's telnet localhost 5555. Linux boot options when we use these options, we can use a specified kernel without installing it in a disk image. This is quite useful for simple testing of various kernels. '-Kernel bzimage' uses bzImage as the kernel image. '-Append cmdline' uses cmdline as the kernel command line. '-Initrd file' uses file as the initial ram disk. The debug option '-serial dev' redirects the virtual string to the device dev of the host. The available devices are as follows: vc virtual terminal pty (Linux) pseudo TTY (automatically allocates a new TTY) null device/dev/XXX "(Linux) uses the tty of the host. For example, '/dev/ttys0 '. The serial port parameters of the host are set through simulation. /Dev/parportN (Linux) uses the host's parallel port N. Currently, only SPP parallel features can be used. File: filename writes the output to the file filename. No characters are readable. Stdio (Unix) standard input/output pipe: filename (Unix) famous pipe filename in graphics mode, the default device is vc, but not stdio. this option can be used multiple times, and up to four serial ports can be simulated. '-Parallel dev' redirects the virtual parallel port to the device dev of the host (the same as that of the serial port ). On a Linux host, '/dev/parportn' can be used to use hardware configurations connected to the corresponding port. This option can be used multiple times, and up to three parallel ports can be simulated. '-Monitor dev' redirects the browser to the device dev of the host (the same as that of the serial port ). The default device in the graphic mode is vc, and the device in the non-graphic mode is stdio. '-S' waits for gdb to connect to port 1234.'-p port' to change the gdb connection port. '-S' does not start the CPU at startup (we must enter 'C' in the monitor)'-d' to output the log to/tmp/qemu. log'-hdachs c, h, s, [, t] 'forces the physical parameters of Hard Disk 0 (1 <= c <= 16383, 1 <= h <= 16, 1 <= s <= 63), and you can select the forced BIOS conversion mode (t = none, lba or auto ). common QEMU can detect these parameters. this option is quite useful for older MS-DOS Disk Images. '-std-vga' simulates a Bochs VBE extended standard VGA graphics card (Cirrus Logic GD5446 pci vga by default) '-loadvm file' to start from a saved state. during graphic simulation, we can use the following key combinations: Ctrl-Alt-f full screen Ctrl-Alt-n to switch the virtual terminal 'n '. the standard terminal ing is as follows: n = 1: The target system displays n = 2: the browser n = 3: The serial Ctrl-Alt captures the mouse and keyboard on the virtual console, we can use Ctrl-Up, Ctrl-Down, Ctrl-PageUp, and Ctrl-PageDown to move on the screen. during simulation, if we use the '-nographic' option, we can use Ctrl-a h to get the terminal command: ctrl-a h print help information Ctrl-a x exit simulate Ctrl-a s Save the disk information into the file (if it is-snapshot) ctrl-a B interrupt Ctrl-a c switch between the console and the monitor Ctrl-a send Ctrl-a disk image from 0.6.1, QEMU supports multiple disk image formats, including increasing Disk Images, compressed and encrypted Disk Images. we can use the following command to create a disk image: qemu-img create myimage. img mysize here myimage. img is the file name of the disk image, and mysize is the size indicated by K. we can use M prefix to represent the size or G as the prefix to use G to represent the size. the qemu-img option supports the following commands: '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 command parameter filename disk image file name. the base_image read-only disk image can be used as the basis for copying to the write image. copies on the write image only store the modified data. fmt disk image format. in most cases, it can be automatically detected. the following format is supported: rawraw disk format (default ). this format has the advantages of simplicity and ease of porting to other simulators. if our file system supports holes (for example, ext2 or ext3 on Linux), then only the written part is left blank. use qemu-img info to obtain the actual image size or use ls-ls on Unix/Linux. qcowQEMU image format. the most common format. he can use it to obtain a small image (if our file system does not support holes, for example, on Windows, this is quite useful), he can use AES encryption or zlib-based compression. linux copy of cow user mode in image writing format. used as the increasing image format in QEMU. this option is only for compatibility with previous versions and cannot be used on Win32. vmdkVMware 3 or 4 compatible image format. cloopLinux compresses the circular image, reusing the directly compressed CD-ROM image. size: the size of the disk image in K format. at the same time, M or G can be used as the prefix. output_filename target disk image file name output_fmt target format-c indicates that the target image must be compressed (only in qcow format)-e indicates that the target image must be encrypted (only in qcow format)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.