CentOS7系统通过virt-install自动启动虚拟机(全程无交互)

【原文链接】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)安装完成后,即进入登录界面,输入用户名密码即可登录

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

redrose2100

您的鼓励是我最大的创作动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值