kickstart+virt-install安装虚拟机

时间:2020-01-06 20:16:13   收藏:0   阅读:123

本文提供的方法适用于在远程服务器的kvm+qemu环境中部署CentOS虚拟机。

#!/bin/bash
set -xe
diskimage=/var/lib/libvirt/images/centosvm.qcow2
echo "Creating qcow2 disk image.."
qemu-img create -f qcow2 -o preallocation=metadata $diskimage 40G
#fallocate -l `ls -al $diskimage | awk '{print $5}'` $diskimage
echo `ls -lash $diskimage`


# [2] Create a minimal kickstart file for Fedora

cat << EOF > fed.ks
install
text
reboot
lang en_US.UTF-8
keyboard us
network --bootproto dhcp
rootpw abc123
firewall --enabled --ssh
selinux --enforcing
network  --bootproto=static --ip=192.168.122.100 --netmask=255.255.255.0 --gateway=192.168.122.1 --nameserver=223.5.5.5,223.6.6.6 --device=eth0
timezone --utc Asia/Shanghai
bootloader --location=mbr --append="console=tty0 console=ttyS0,115200 rd_NO_PLYMOUTH"
zerombr
clearpart --all --initlabel
autopart

%packages
@core
net-tools
git
emacs
mtr
%end
EOF

# [3] Create the guest

virt-install --connect=qemu:///system     --network network=default     --initrd-inject=./fed.ks     --extra-args="ks=file:/fed.ks console=tty0 console=ttyS0,115200 serial rd_NO_PLYMOUTH"     --name=test     --disk path=$diskimage,format=qcow2,cache=none     --ram 512     --vcpus=2     --check-cpu     --accelerate     --os-type linux     --os-variant centos7.0     --cpuset auto     --hvm     --location=CentOS-7-x86_64-Minimal-1804.iso     --nographics

原文:https://www.cnblogs.com/powerrailgun/p/12158037.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!