[Operation and Maintenance] Kvm Qemu-Kvm Command

KVM qemu-kvm command.KVM learning~

kvm and virt command, qemu-kvm is closer to the underlying system.
Install qemu-kvm , because Red Hat wants everyone to use libvirt , which they respect . Tools based on libvirt such as virt -manager and virt -install provide a very convenient virtual machine management interface, but they actually encapsulate the qemu-kvm tool after secondary development . Therefore, directly using the qemu-kvm command can also Complete previous tasks.
So put qemu-kvm under / usr / libexec /, not under PATH, you need to create a soft link yourself


CentOS installs two important commands:
qemu-kvm : manage kvm
qemu-img : manage disks

#Install qemu-kvm components, add soft links
[ root@localhost ~]# yum -y install qemu-kvm
[ root@localhost ~]# ln -s / usr / libexec / qemu-kvm / usr /local/bin

1. KVM qemu-kvm command.CPU simulation




- cpu specifies the simulated CPU
#View optional CPU models
[ root@localhost ~]# qemu-kvm - cpu ?



- smp specifies the number of CPUs
maxcpus = maximum number of cpus ]
cores= number of cores
threads=Number of threads


Second, the definition of memory


-m megs: set the RAM size of the virtual machine


Three, disk image file simulation

disk file definition


file=: hard disk image file path
media=: Specify the media device type, including disk, and cdrom
if= : Specify the interface type connected to the hard disk device, such as ide, sd , virtio , etc.
file=/path : hard disk image file path
index=index: Set the index number of the different devices in the same controller type, that is, the identification number
snapshot=snapshot: Specifies whether the current hard disk device supports the snapshot function: on or off
cache=cache: defines how to use the physical machine cache to access block data, the available values are none, writeback, unsafe and writethrough (write through)
format=format: specifies the format of the image file. For the specific format, please refer to the qemu-img command


IKVM qemu-kvm command.mage file definition




It should be noted that - cdrom and - hdc cannot be used at the same time: specifying file as /dev/ cdrom can directly use the physical CD-ROM drive


4. Network configuration parameters

NIC configuration (front-end)

View supported analog network card models



tap device configuration (backend)





How Tap/Tun Works
The principle of the TUN/TAP virtual network device is relatively simple. He adds a TUN/TAP virtual network device driver and a character device /dev/net/tun associated with it to the Linux kernel. The character device tun is used as user space. Interface for exchanging data with kernel space. The user space application can interact with the driver in the kernel through this device file, and its operation method is no different from the ordinary file operation. When the kernel sends a data packet to a virtual network device, the data packet is stored in a queue related to the device, and it will not be copied to the user space until the user space program reads it through the descriptor of the open character device tun. In the buffer, the effect is equivalent to sending the data packet directly to the user space. The principle is similar when sending packets through the system call write.

Original link: https://blog.csdn.net/xiakewudi/java/article/details/76851076




Help document:
Use the network script file configuration (configure the tap interface and the bridge interface to create a bridge), the default location is the configuration script of / etc / qemu-ifup or the specified script
Use script=no or downscript =no to disable script configuration
If the tap interface name is not specified, it will default to a tapXX



5. Other options


-name name : Specifies the name of the virtual machine


-boot defines the boot order of the device
Each device is represented by one character.
a,b means floppy drive, c means the first hard disk, d means the first CD-ROM drive, np means the network adapter.
For example: -boot order= dc,once =d


- nographic disables graphical output, prints directly on the terminal


- daemonize the virtual machine to start in the background


- vnc :n or xxxx:x enable vnc

Create a test virtual machine

#Write a script to configure the default bridge and add execution permissions
#$1 The tap device number created by qemu is passed as a parameter to the script, and bridge is the bridge created on the system
[ root@localhost ~]# vim / etc / qemu-ifup
#!/ bin/bash
bridge=virbr0
if [ -n "$1 " ];then
ip link set $1 up
sleep 1
brctl addif $bridge $1
exit 0
else
echo "Error: no interface specified"
exit 1
fi
[ root@localhost ~]# chmod +x / etc / qemu-ifup


#Start the cirros test machine
[ root@localhost isos]# qemu-kvm -name test- cirros -m 512 -drive file=cirros-0.3.4-x86_64-disk.img -net nic -net tap -nographic -vnc : 1

The startup is successful, and the virtual machine output is in the foreground. You can also use VNC to connect to port 5901 to log in.

System information output at startup


brctl show to view the bridge connection, at this time the tap0 interface has been connected to virbr0


The virtual machine is connected to the bridge through tap0 to bridge with the physical machine virbr0-nic interface
ssh connection can be made on the physical machine


Related Articles

Explore More Special Offers

  1. Short Message Service(SMS) & Mail Service

    50,000 email package starts as low as USD 1.99, 120 short messages start at only USD 1.00