kvm安装Linux的centos7

简介: kvm安装Linux的centos7

书接上回,kvm安装Windows7旗舰版_zsk_john的博客-CSDN博客

kvm的相关介绍在此就省略了,同样的配方同样的味道,还是使用xml文件安装kvm虚拟机,但,Linux的安装和Windows的安装是有很大不同的。

本文中已经安装好的kvm镜像文件,安装用的ISO文件以及配置文件都放在网盘里了,下载地址:

链接:https://pan.baidu.com/s/1Lss524AqnKcPs3ZT-pgZ5g

提取码:kvms  

一,建立一个安装用的xml文件。主要的安装配置linux_mini.xml文件内容如下:

此文件我们定义了这个虚拟机的名字是linux_mini,挂载了一个硬盘,该硬盘的格式是qcow2,使用的驱动是virtio,挂载了一个光驱,光驱内装载系统安装文件,文件名称是CentOS-7-x86_64-Minimal-1708.iso,使用的驱动是ide。vnc的端口定义的是5992,使用的vnc模式是vga。

- <!-- 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 linux_mini
or other application using the libvirt API.
  --> 
- <domain type="kvm">
  <name>linux_mini</name> 
  <uuid>187ca777-a965-4777-8e95-c1f0cfe2a363</uuid> 
  <memory unit="KiB">548576</memory> 
  <currentMemory unit="KiB">548576</currentMemory> 
  <vcpu placement="static">2</vcpu> 
- <os>
  <type arch="x86_64" machine="pc-i440fx-rhel7.6.0">hvm</type> 
  <boot dev="hd" /> 
  </os>
- <features>
  <acpi /> 
  <apic /> 
  </features>
- <cpu mode="host-model" check="partial">
  <model fallback="allow" /> 
  </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="/opt/linux.img" /> 
  <target dev="vda" bus="virtio" /> 
  <address type="pci" domain="0x0000" bus="0x00" slot="0x06" function="0x0" /> 
  </disk>
- <disk type="file" device="cdrom">
  <driver name="qemu" type="raw" /> 
  <source file="/opt/CentOS-7-x86_64-Minimal-1708.iso" /> 
  <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="0x04" function="0x7" /> 
  </controller>
- <controller type="usb" index="0" model="ich9-uhci1">
  <master startport="0" /> 
  <address type="pci" domain="0x0000" bus="0x00" slot="0x04" function="0x0" multifunction="on" /> 
  </controller>
- <controller type="usb" index="0" model="ich9-uhci2">
  <master startport="2" /> 
  <address type="pci" domain="0x0000" bus="0x00" slot="0x04" function="0x1" /> 
  </controller>
- <controller type="usb" index="0" model="ich9-uhci3">
  <master startport="4" /> 
  <address type="pci" domain="0x0000" bus="0x00" slot="0x04" 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="0x05" function="0x0" /> 
  </controller>
- <interface type="network">
  <mac address="52:54:00:89:52:23" /> 
  <source network="default" /> 
  <model type="virtio" /> 
  <address type="pci" domain="0x0000" bus="0x00" slot="0x03" 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>
- <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="vnc" port="5992" autoport="no" listen="0.0.0.0">
  <listen type="address" address="0.0.0.0" /> 
  </graphics>
- <video>
  <model type="vga" vram="16384" heads="1" primary="yes" /> 
  <address type="pci" domain="0x0000" bus="0x00" slot="0x02" function="0x0" /> 
  </video>
- <memballoon model="virtio">
  <address type="pci" domain="0x0000" bus="0x00" slot="0x07" function="0x0" /> 
  </memballoon>
- <rng model="virtio">
  <backend model="random">/dev/urandom</backend> 
  <address type="pci" domain="0x0000" bus="0x00" slot="0x08" function="0x0" /> 
  </rng>
  </devices>
  </domain>
二,如前所述两个文件我们需要放置到xml定义的路径下,也就是opt目录下。

第一个文件,磁盘文件,该文件的生成命令为:

qemu-img create -f qcow2 linux.img 15G

第二个文件,也就是ISO文件,上传到opt目录下即可。

三,启动前,我们应该要检查一下xml里的boot配置,确保是cdrom,也就是这段是cdrom:

<os>
    <type arch='x86_64' machine='pc-i440fx-rhel7.6.0'>hvm</type>
    <boot dev='cdrom'/>
  </os>

四,直接使用xml文件启动虚拟机,开始安装,安装命令为:

virsh create linxu_mini.xml

image.png

但是,很可惜,如果直接安装的话,会有软锁报错,因此,我们需要将内核升级成高版本的稳定内核。

相关问题说明见本人博客:关于kvm安装Linux时的CPU soft lockup报错解决方案_zsk_john的博客-CSDN博客

这个bug修复后,在进行安装就和普通的安装一样了,只是建议分区的时候只划一个根分区和一个非常小的swap分区即可。具体分区方法过于基础,再次不予讨论。

这样的一个镜像在安装完毕后并重启kvm虚拟机后悔固化到前面所建立的linux.img 文件内,该文件是比较小的,大概会只有1.3G。

kvm的强大之处在于你只需要拷贝前面建立所用的xml文件和linux.img 文件,在其它的有kvm的环境机器上就可以一键启动一个linux系统了,虽然这个kvm镜像没有经过定制化,比如,网络和一些基础软件没有配置和安装,但,基本是开箱即用啦。


目录
相关文章
|
4月前
|
存储 分布式计算 Linux
安装篇--CentOS 7 虚拟机安装
VMware 装 CentOS 7 不知道从哪下手?这篇超详细图文教程手把手教你在 VMware Workstation 中完成 CentOS 7 桌面系统的完整安装流程。从 ISO 镜像下载、虚拟机配置,到安装图形界面、设置用户密码,每一步都有截图讲解,适合零基础新手快速上手。装好之后无论你是要搭 Hadoop 集群,还是练 Linux ,这个环境都够你折腾一整天!
1652 2
|
3月前
|
安全 Linux iOS开发
Nessus Professional 10.10 Auto Installer for RHEL 10, AlmaLinux 10, Rocky Linux 10 - Nessus 自动化安装程序
Nessus Professional 10.10 Auto Installer for RHEL 10, AlmaLinux 10, Rocky Linux 10 - Nessus 自动化安装程序
223 6
Nessus Professional 10.10 Auto Installer for RHEL 10, AlmaLinux 10, Rocky Linux 10 - Nessus 自动化安装程序
|
4月前
|
安全 关系型数据库 MySQL
CentOS 7 yum 安装 MySQL教程
在CentOS 7上安装MySQL 8,其实流程很清晰。首先通过官方Yum仓库来安装服务,然后启动并设为开机自启。最重要的环节是首次安全设置:需要先从日志里找到临时密码来登录,再修改成你自己的密码,并为远程连接创建用户和授权。最后,也别忘了在服务器防火墙上放行3306端口,这样远程才能连上。
738 16
|
3月前
|
消息中间件 Kafka Linux
Linux下安装Kafka 3.9.1
本文介绍Kafka 3.9.1版本的安装与配置,包括通过ZooKeeper或KRaft模式启动Kafka。涵盖环境变量设置、日志路径修改、集群UUID生成、存储格式化及服务启停操作,适用于Linux环境下的部署实践。
379 0
|
5月前
|
网络协议 关系型数据库 Linux
【App Service Linux】在Linux App Service中安装 tcpdump 并抓取网络包
在App Service for Linux环境中,无法像Windows一样直接使用网络排查工具抓包。本文介绍了如何通过TCPDUMP在Linux环境下抓取网络包,包括SSH进入容器、安装tcpdump、执行抓包命令及下载分析文件的完整操作步骤。
259 5
|
NoSQL Java Linux
linux 安装 neo4j简介
Neo4j是高性能NoSQL图形数据库,利用图结构存储数据。推荐使用JDK 11配合Neo4j 3.x版本。下载3.5.9版,通过`curl`命令在Linux上获取tar.gz文件,然后解压。配置`neo4j.conf`,调整内存设置,开启远程访问。执行`./bin/neo4j start`启动,通过`http://服务器IP:7474`访问,默认凭据是username: neo4j, password: neo4j,登录后应更改密码。
1671 1
|
存储 缓存 Ubuntu
【嵌入式开发】 Linux Kernel 下载 配置 编译 安装 及 驱动简介(二)
【嵌入式开发】 Linux Kernel 下载 配置 编译 安装 及 驱动简介(二)
378 0
|
Ubuntu 安全 Unix
【嵌入式开发】 Linux Kernel 下载 配置 编译 安装 及 驱动简介(一)
【嵌入式开发】 Linux Kernel 下载 配置 编译 安装 及 驱动简介(一)
463 0