KVM 虚拟机创建

准备工作

查看KVM⽀持的OS版本:
[root@kvm ~]# osinfo-query os | grep centos
 centos-stream8       | CentOS Stream 8                                    | 8        | http://centos.org/centos-stream/8       
 centos5.0            | CentOS 5.0                                         | 5.0      | http://centos.org/centos/5.0            
 centos5.1            | CentOS 5.1                                         | 5.1      | http://centos.org/centos/5.1            
 centos5.10           | CentOS 5.10                                        | 5.10     | http://centos.org/centos/5.10           
 centos5.11           | CentOS 5.11                                        | 5.11     | http://centos.org/centos/5.11           
 centos5.2            | CentOS 5.2                                         | 5.2      | http://centos.org/centos/5.2            
 centos5.3            | CentOS 5.3                                         | 5.3      | http://centos.org/centos/5.3            
 centos5.4            | CentOS 5.4                                         | 5.4      | http://centos.org/centos/5.4            
 centos5.5            | CentOS 5.5                                         | 5.5      | http://centos.org/centos/5.5            
 centos5.6            | CentOS 5.6                                         | 5.6      | http://centos.org/centos/5.6            
 centos5.7            | CentOS 5.7                                         | 5.7      | http://centos.org/centos/5.7            
 centos5.8            | CentOS 5.8                                         | 5.8      | http://centos.org/centos/5.8            
 centos5.9            | CentOS 5.9                                         | 5.9      | http://centos.org/centos/5.9            
 centos6.0            | CentOS 6.0                                         | 6.0      | http://centos.org/centos/6.0            
 centos6.1            | CentOS 6.1                                         | 6.1      | http://centos.org/centos/6.1            
 centos6.10           | CentOS 6.10                                        | 6.10     | http://centos.org/centos/6.10           
 centos6.2            | CentOS 6.2                                         | 6.2      | http://centos.org/centos/6.2            
 centos6.3            | CentOS 6.3                                         | 6.3      | http://centos.org/centos/6.3            
 centos6.4            | CentOS 6.4                                         | 6.4      | http://centos.org/centos/6.4            
 centos6.5            | CentOS 6.5                                         | 6.5      | http://centos.org/centos/6.5            
 centos6.6            | CentOS 6.6                                         | 6.6      | http://centos.org/centos/6.6            
 centos6.7            | CentOS 6.7                                         | 6.7      | http://centos.org/centos/6.7            
 centos6.8            | CentOS 6.8                                         | 6.8      | http://centos.org/centos/6.8            
 centos6.9            | CentOS 6.9                                         | 6.9      | http://centos.org/centos/6.9            
 centos7.0            | CentOS 7                                           | 7        | http://centos.org/centos/7.0            
 centos8              | CentOS 8                                           | 8        | http://centos.org/centos/8
准备 ISO 系统镜像文件

以CentOS-7.9为例,上传至宿主机:

/iso/CentOS-7-x86_64-Minimal-2009.iso

图形模式安装 KVM虚拟机

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
至此,后续步骤仅涉及操作系统安装,不再描述。

完全⽂本⽅式安装

服务器/客户端没有图形界面的极端情况下食用

[root@kvm ~]# virt-install --connect qemu:///system -n vm2 -r 512 --disk
path=/virhost/vmware/vm2.img,size=7 --os-type=linux --os-variant=rhel6 --
vcpus=1 --network bridge=br0 --location=http://127.0.0.1/rhel6u4 -x
console=ttyS0 --nographics

[root@kvm ~]#virt-install --connect qemu:///system -n vm3 -r 2048 --disk
path=/var/lib/libvirt/images/vm3.img,size=7 --os-type=linux --osvariant=centos7.0 --vcpus=1 --location=ftp://192.168.100.230/centos7u3 -x
console=ttyS0 --nographics 

注意:

  • ⽤这种⽅式安装的操作系统,⼤⼩写会胡乱变化,不影响远程操作
  • 内存必须2G以上

排错

安装过程中:
⼿动配置IP地址
到url位置找不到路径,要返回去⼿动选择url,重新配置url为ftp://192.168.100.230/rhel6u4,这⾥的ip不要写127.0.0.1⽽是br0的ip

给虚拟机指定的内存必须⼤于2048M,不然报错如下: dracut-initqueue[552]:/sbin/dmsquash-live-root: line 273: printf: write error: No space left on device

逃脱符:

Escape character is ^]

命令⾏模式安装

虚拟机的文件组成:

  • 配置⽂件 /etc/libvirt/qemu
  • 介质文件 /var/lib/libvirt/images/

根据配置⽂件创建虚拟机

1.复制磁盘镜像⽂件:
[root@kvm ~]# cp vm01.img vm02.img
2.复制配置⽂件
[root@kvm ~]# cp vm01.xml vm02.xml
3.修改配置⽂件内容
4.创建虚拟机:
[root@kvm ~]# virsh define /etc/libvirt/qemu/vm02.xml

模板镜像 + 配置⽂件⽅式安装

1.拷⻉模板镜像和配置⽂件

[root@kvm ~]# cp /var/lib/libvirt/images/vm01.img
/var/lib/libvirt/images/vm02.img
[root@kvm ~]# cp /etc/libvirt/qemu/vm01.xml
/etc/libvirt/qemu/vm02.xml

2.修改配置⽂件

[root@kvm ~]# vim /etc/libvirt/qemu/vm02.xml
<!--
WARNING: THIS IS AN AUTO-GENERATED FILE. CHANGES TO IT ARE LIKELY TO BE
OVERWRITTEN AND LOST. Changes to this xml configuration should be made using:
  virsh edit vm01
or other application using the libvirt API.
-->

<domain type='kvm'>
  <name>vm02</name>
  <uuid>ed57d2b2-fb47-4572-ae00-d1de5add208e</uuid>
  <memory unit='KiB'>2097152</memory>
  <currentMemory unit='KiB'>2097152</currentMemory>
  <vcpu placement='static'>1</vcpu>
  <os>
    <type arch='x86_64' machine='pc-i440fx-rhel7.0.0'>hvm</type>
    <boot dev='hd'/>
  </os>
  <features>
    <acpi/>
    <apic/>
  </features>
  <cpu mode='custom' match='exact' check='partial'>
    <model fallback='allow'>Haswell-noTSX-IBRS</model>
    <feature policy='require' name='spec-ctrl'/>
    <feature policy='require' name='ssbd'/>
  </cpu>
  <clock offset='utc'>
    <timer name='rtc' tickpolicy='catchup'/>
    <timer name='pit' tickpolicy='delay'/>
    <timer name='hpet' present='no'/>
  </clock>
  <on_poweroff>destroy</on_poweroff>
  <on_reboot>restart</on_reboot>
  <on_crash>destroy</on_crash>
  <pm>
    <suspend-to-mem enabled='no'/>
    <suspend-to-disk enabled='no'/>
  </pm>
  <devices>
    <emulator>/usr/libexec/qemu-kvm</emulator>
    <disk type='file' device='disk'>
      <driver name='qemu' type='qcow2'/>
      <source file='/var/lib/libvirt/images/vm02.qcow2'/>
      <target dev='vda' bus='virtio'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x07' function='0x0'/>
    </disk>
    <disk type='file' device='cdrom'>
      <driver name='qemu' type='raw'/>
      <target dev='hda' bus='ide'/>
      <readonly/>
      <address type='drive' controller='0' bus='0' target='0' unit='0'/>
    </disk>
    <controller type='usb' index='0' model='ich9-ehci1'>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x7'/>
    </controller>
    <controller type='usb' index='0' model='ich9-uhci1'>
      <master startport='0'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0' multifunction='on'/>
    </controller>
    <controller type='usb' index='0' model='ich9-uhci2'>
      <master startport='2'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x1'/>
    </controller>
    <controller type='usb' index='0' model='ich9-uhci3'>
      <master startport='4'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x2'/>
    </controller>
    <controller type='pci' index='0' model='pci-root'/>
    <controller type='ide' index='0'>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/>
    </controller>
    <controller type='virtio-serial' index='0'>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/>
    </controller>
    <interface type='network'>
      <mac address='52:54:00:74:12:43'/>
      <source network='default'/>
      <model type='virtio'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
    </interface>
    <serial type='pty'>
      <target type='isa-serial' port='0'>
        <model name='isa-serial'/>
      </target>
    </serial>
    <console type='pty'>
      <target type='serial' port='0'/>
    </console>
    <channel type='unix'>
      <target type='virtio' name='org.qemu.guest_agent.0'/>
      <address type='virtio-serial' controller='0' bus='0' port='1'/>
    </channel>
    <channel type='spicevmc'>
      <target type='virtio' name='com.redhat.spice.0'/>
      <address type='virtio-serial' controller='0' bus='0' port='2'/>
    </channel>
    <input type='tablet' bus='usb'>
      <address type='usb' bus='0' port='1'/>
    </input>
    <input type='mouse' bus='ps2'/>
    <input type='keyboard' bus='ps2'/>
    <graphics type='spice' autoport='yes'>
      <listen type='address'/>
      <image compression='off'/>
    </graphics>
    <sound model='ich6'>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
    </sound>
    <video>
      <model type='qxl' ram='65536' vram='65536' vgamem='16384' heads='1' primary='yes'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
    </video>
    <redirdev bus='usb' type='spicevmc'>
      <address type='usb' bus='0' port='2'/>
    </redirdev>
    <redirdev bus='usb' type='spicevmc'>
      <address type='usb' bus='0' port='3'/>
    </redirdev>
    <memballoon model='virtio'>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x08' function='0x0'/>
    </memballoon>
    <rng model='virtio'>
      <backend model='random'>/dev/urandom</backend>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x09' function='0x0'/>
    </rng>
  </devices>
</domain>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值