【原文链接】CentOS7系统通过virt-install启动虚拟机
(1)在centos7系统下载centos7的操作系统iso文件
mkdir -p /opt/os
cd /opt/os
yum install -y wget
wget http://mirrors.ustc.edu.cn/centos/7.9.2009/isos/x86_64/CentOS-7-x86_64-DVD-2009.iso
(2)参照 CentOS系统利用kickstart自动生成工具通过图形化配置的方式生成ks.cfg文件 生成ks.cfg文件,如下
#platform=x86, AMD64, 或 Intel EM64T
#version=DEVEL
# Install OS instead of upgrade
install
# Keyboard layouts
keyboard 'us'
# Root password
rootpw --iscrypted $1$x7isxN9d$2uzzR6TWc.UyXds2hYxlr0
# System language
lang zh_CN
# System authorization information
auth --useshadow --passalgo=sha512
# Use CDROM installation media
cdrom
# Use text mode install
text
# SELinux configuration
selinux --disabled
# Do not configure the X Window System
skipx
# Firewall configuration
firewall --disabled
# Network information
network --bootproto=dhcp --device=ens3
# Reboot after installation
reboot
# System timezone
timezone Asia/Shanghai
# System bootloader configuration
bootloader --location=mbr
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all --initlabel
# Disk partitioning information
part /boot --fstype="xfs" --size=1024
part / --fstype="xfs" --grow --size=1
%packages
@base
%end
(3)创建虚拟机的存储卷
创建命令瑞安,其中-f指定卷的格式,卷的名称自定义,比如这里 centos7.qcow2,大小这里设置为30G
qemu-img create -f qcow2 /var/lib/libvirt/images/test.qcow2 30G
(4)通过virt-install命令启动虚拟机
virt-install \
--name test \
--memory=1024 \
--vcpus=1 \
--os-type linux \
--location /opt/os/CentOS-7-x86_64-DVD-2009.iso \
--disk path=/var/lib/libvirt/images/test.qcow2,size=30,format=qcow2 \
--network bridge=br0 \
--graphics=none \
--console pty,target_type=serial \
--initrd-inject ks.cfg --extra-args "inst.ks=file:/ks.cfg console=tty0 console=ttyS0,115200n8"
(5)安装完成后,即进入登录界面,输入用户名密码即可登录