Ubuntu20安装KVM,创建cloud镜像虚拟机

安装kvm

apt update &&apt install qemu-kvm libvirt-daemon-system libvirt-clients bridge-utils cloud-utils virtinst -y

创建用户

sudo adduser `id -un` libvirt
sudo adduser `id -un` kvm

创建桥接网卡

nano /etc/netplan/50-cloud-init.yaml
network:
    version: 2
    ethernets:
        eth0:
            dhcp4: true
            dhcp6: true
            match:
                macaddress: c6:fb:0f:c3:59:6d
            set-name: eth0
    bridges:
      vmbr0:
        interfaces: [eth0]
        dhcp4: true
        dhcp6: true
~                                                                                                                       ~                             
#先测试是否可以
netplan try 
#输出成功,则应用配置
netplan apply

开启内核转发

echo "net.ipv4.ip_forward = 1" >>/etc/sysctl.conf
echo "net.bridge.bridge-nf-call-ip6tables = 1" >>/etc/sysctl.conf
echo "net.bridge.bridge-nf-call-iptables = 1" >>/etc/sysctl.conf
echo "net.bridge.bridge-nf-call-arptables = 1" >>/etc/sysctl.conf
sysctl -p 

 

创建KVM所需要的文件夹

创建iso仓库 
mkdir /var/kvm/iso -p 创建镜像仓库
mkdir /var/kvm/images
 

创建一个cloud-init USER-DATA配置文件

cat > /var/kvm/iso/cloud-init.cfg << EOF
#cloud-config
hostname: ubuntu
manage_etc_hosts: true 
user: root 
disable_root: False 
password: rootroot 
chpasswd: 
  expire: False 
packages: 
  - qemu-guest-agent 
EOF
  

生成cloud drive

cloud-localds  /var/kvm/iso/cloud.img /var/kvm/iso/cloud-init.cfg

下载ubuntu-cloud镜像到iso仓库,这里自己可以上传镜像。

wget -P /var/kvm/images/ http://10.13.14.22/bionic-server-cloudimg-amd64.img

创建虚拟机

virt-install \
--name ubuntu \
--os-type Linux --os-variant ubuntu18.04 \
--memory 1024 \
--vcpus 2 \
--network bridge=vmbr0,model=virtio \
--cdrom=/var/kvm/iso/cloud.img \
--disk /var/kvm/images/bionic-server-cloudimg-amd64.img,bus=virtio \
--graphics=none \
--noautoconsole 

查看虚拟机

root@kvm:/var/kvm/iso# virsh list
 Id   Name     State
------------------------
 4    ubuntu   running

利用virsh console命令进入虚拟机串口控制台

virsh console 4

 

版权声明:
作者:佛西
链接:https://foxi.buduanwang.vip/virtualization/610.html/
文章版权归作者所有,未经允许请勿转载
如需获得支持,请点击网页右上角
THE END
分享
二维码
海报
Ubuntu20安装KVM,创建cloud镜像虚拟机
安装kvm apt update &&apt install qemu-kvm libvirt-daemon-system libvirt-clients bridge-utils cloud-utils virtinst -y 创建用……
<<上一篇
下一篇>>