qemu教程_QEMU实例教程

qemu教程

qemu教程

Qemu is a very old virtualization technology used to virtualize system components and run operating systems on it. Before KVM and XEN QEMU was used heavily but it can not race with VMWARE or VIRTUAL PC. But with the KVM Qemu get superfast speed for computing by using hardware-based virtualization. QEMU acts as a hardware supplier and KVM is the CPU. KVM resides in Linux kernel and there is a little configuration for it. A virtualization configuration is made on the QEMU.

Qemu是一种非常古老的虚拟化技术,用于虚拟化系统组件并在其上运行操​​作系统。 在大量使用KVM和XEN QEMU之前,但它无法与VMWARE或VIRTUAL PC竞争。 但是借助KVM,Qemu可以通过使用基于硬件的虚拟化来获得超快的计算速度。 QEMU充当硬件供应商,KVM是CPU。 KVM驻留在Linux内核中,并且需要一些配置。 在QEMU上进行了虚拟化配置。

qemu-kvm或qemu或qemu-system-x86_64 (qemu-kvm or qemu or qemu-system-x86_64)

Qemu is a very old and big project which has different user bases and intersecting with different projects. Qemu is used in the Linux Kernel Virtualization project named KVM. So this project also provides Qemu with different command names but with more features. qemu-system-x86_64 is the binary or command for Qemu which is used to create 64-bit x86 VMs.

Qemu是一个非常古老而庞大的项目,它具有不同的用户基础,并且与不同的项目相交。 Qemu用于名为KVMLinux内核虚拟化项目。 因此,该项目还为Qemu提供了不同的命令名称,但具有更多功能。 qemu-system-x86_64是Qemu的二进制或命令,用于创建64位x86 VM。

安装Qemu (Install Qemu)

We can install Qemu with the qemu package name for different distributions.

我们可以使用qemu软件包名称安装Qemu,以用于不同的发行版。

为Ubuntu,Debian,Mint,Kali安装Qemu (Install Qemu For Ubuntu, Debian, Mint, Kali)

We will use the following command.

我们将使用以下命令。

$ sudo apt install qemu
Install Qemu For Ubuntu, Debian, Mint, Kali
Install Qemu For Ubuntu, Debian, Mint, Kali
为Ubuntu,Debian,Mint,Kali安装Qemu

安装Qemu For Fedora,CentOS,Red Hat (Install Qemu For Fedora, CentOS, Red Hat)

We will use both dnf and yum package managers according to distribution for rpm based install.

根据基于rpm的安装,我们将根据分发使用dnf和yum软件包管理器。

$ sudo dnf install qemu

OR

要么

$ sudo yum install qemu

qemu命令帮助 (qemu Command Help)

We can list short help information about the qemu like below by using -h option.

我们可以使用-h选项列出有关qemu简短帮助信息,如下所示。

$ qemu-system-x86_64 -h
Help
Help
帮帮我

qemu命令语法(qemu Command Syntax)

Qemu syntax is the same as most of the Linux commands.

Qemu语法与大多数Linux命令相同。

qemu-system-x86_64 OPTIONS IMAGE
  • OPTIONS are provided for VM options like Ram size, features, CPU, Graphics, etc.

    OPTIONS提供了VM选项,如RAM大小,功能,CPU,显卡等。

  • IMAGE is the file name of the disk for the VM.

    IMAGE是VM磁盘的文件名。

LEARN MORE  How To Clone VM with Libguestfs?
了解更多信息如何使用Libguestfs克隆VM?

下载云映像 (Download Cloud Images)

Popular Linux distributions like Fedora, CentOS, Debian, Ubuntu, RedHat provides virtual machine images in various formats like raw, qcow2, vmdk, etc. We will download the Fedora 25 cloud image from the following link which is provided by the Fedora Project. Download with wget like below.

流行Linux发行版(例如Fedora,CentOS,Debian,Ubuntu,RedHat)提供各种格式的虚拟机映像,例如raw,qcow2,vmdk等。我们将从以下Fedora项目提供的链接中下载Fedora 25云映像。 使用如下的wget下载。

$ wget http://www.nic.funet.fi/pub/mirrors/fedora.redhat.com/pub/fedora/linux/releases/30/Cloud/x86_64/images/Fedora-Cloud-Base-30-1.2.x86_64.qcow2
Download Cloud Images
Download Cloud Images
下载云映像

设置Qemu VM的CPU和核心计数(Set CPU and Core Count for Qemu VM)

CPU is one of the most important parts of a system. We can set the CPU core count for the VM in Qemu. We will provide the -smp option which will enable multiple CPU cores with the core=2 value which will set the core count 2 in the given VM.

CPU是系统最重要的部分之一。 我们可以在Qemu中设置VM的CPU核心数。 我们将提供-smp选项,该选项将启用具有core=2值的多个CPU内核,这将在给定VM中设置内核计数2。

$ qemu-system-x86_64 -smp cores=2

从网络启动 (Boot From Network)

There are different ways to boot the VM system. Generally, images are used to boot but we can also boot from a network with the -boot order=nc option.

有多种启动VM系统的方法。 通常,映像用于引导,但是我们也可以使用-boot -boot order=nc选项从网络引导。

$ qemu-system-x86_64 -boot order=nc

设置Qemu VM的RAM或内存大小 (Set RAM or Memory Size For Qemu VM)

RAM is another important component of the VM. By default 128 MB RAM is set for the started VM. But we can also set the RAM size explicitly with the -m option which is the short form of the memory. We will also provide the size as MB where we will set 256 MB Ram in this example.

RAM是VM的另一个重要组件。 默认情况下,为启动的VM设置128 MB RAM。 但是我们也可以使用-m选项显式设置RAM的大小,这是内存的简称。 我们还将以MB为单位提供大小,在此示例中,我们将设置256 MB Ram。

$ qemu-system-x86_64 -m 256
Set RAM or Memory Size
Set RAM or Memory Size
设置RAM或内存大小

设置Qemu的VM名称(Set VM Name For Qemu)

We have also the option to set a name for the VM. We can use the -name option and provide the VM name. The VM name will be displayed in the Window header of the Qemu. In this example, we will set the VM name as poftut.com.

我们还可以选择为虚拟机设置名称。 我们可以使用-name选项并提供VM名称。 VM名称将显示在Qemu的Window标头中。 在此示例中,我们将虚拟机名称设置为poftut.com

$ qemu-system-x86_64 -name poftut.com

为Qemu VM指定磁盘文件或映像 (Specify Disk File or Image For Qemu VM)

We can specify the disk/image file with the -drive option. This will provides us some ability to specify extra drivers related options. file is used to specify the file size. Also if is used to provide the driver or interface type for the disk.

我们可以使用-drive选项指定磁盘/映像文件。 这将使我们能够指定额外的驱动程序相关选项。 file用于指定文件大小。 另外if用于提供磁盘的驱动程序或接口类型。

$ qemu-system-x86_64 -drive file=fedoraraw.qcow2,if=virtio

禁用Qemu VM的GUI (Disable GUI for Qemu VM)

By default, the VM console will be provided as a GUI window. But we can also disable the console and only provide the terminal of the system with the -nographic option.

默认情况下,VM控制台将作为GUI窗口提供。 但是我们也可以禁用控制台,仅向系统终端提供-nographic选项。

$ qemu-system-x86_64 -nographic

像virbr0一样连接到虚拟交换机 (Connect To Virtual Switch Like virbr0)

By default started guests will be connected with no network and the only single interface will be attached. This is not a practical and useful feature for most of the situations. We can add a network interface and connect this interface into a bridge device that is running in a host operating system. In this example, we will connect our guest with a virtio type network interface into a virtual switch/bridge called virbr0 .

默认情况下,启动的来宾系统将不连接网络,并且仅连接单个接口。 在大多数情况下,这不是实用且有用的功能。 我们可以添加网络接口,并将此接口连接到在主机操作系统中运行的桥接设备。 在此示例中,我们将通过virtio类型的网络接口将客户机连接到名为virbr0的虚拟交换机/桥中。

$ qemu-system-x86_64 -drive file=fedoraraw.qcow2,if=virtio -display none -net bridge,br=virbr0 -net nic,model=virtio

对Qemu VM使用远程磁盘映像 (Use Remote Disk Images For Qemu VM)

Generally, the best way to use VM disk images is locally but qemu also supports the remote disk images via network share with different protocols like SSH, etc. In this example, we will use a disk image named disk.img on the remote system via SSh by using file option.

通常,使用VM磁盘映像的最佳方法是在本地使用,但是qemu还通过与诸如SSH等不同协议的网络共享来支持远程磁盘映像。在本示例中,我们将通过以下disk.img在远程系统上使用名为disk.img的磁盘映像:通过使用file选项的SSh。

$ qemu-system-x86_64 -drive file=ssh://[email protected]/disk.img

翻译自: https://www.poftut.com/qemu-tutorial/

qemu教程

  • 8
    点赞
  • 68
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值