确认环境
egrep -c '(vmx|svm)' /proc/cpuinfo
输出结果需要大于0,否则主机需要开启cpu虚拟化功能。
设置桥接网卡
# 网卡配置示例
cat <<'EOF' | sudo tee /etc/netplan/00-installer-config.yaml > /dev/null
# This is the network config written by 'subiquity'
network:
ethernets:
ens33:
dhcp4: false
dhcp6: false
bridges:
br0:
interfaces: [ens33]
dhcp4: false
addresses:
- 192.168.32.132/24
routes:
- to: default
via: 192.168.32.2
nameservers:
addresses:
- 114.114.114.114
- 223.5.5.5
parameters:
stp: false
dhcp6: false
version: 2
EOF
# 重启网卡
sudo netplan apply
更新apt源
不同系统配置文件不一致
sudo cp /etc/apt/sources.list /etc/apt/sources.list.backup
$ cat <<'EOF' | sudo tee /etc/apt/sources.list >> /dev/null
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-backports main restricted universe multiverse
deb http://security.ubuntu.com/ubuntu/ jammy-security main restricted universe multiverse
# deb-src http://security.ubuntu.com/ubuntu/ jammy-security main restricted universe multiverse
# 预发布软件源,不建议启用
# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-proposed main restricted universe multiverse
# # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-proposed main restricted universe multiverse
EOF
sudo apt update
安装kvm包
sudo apt install qemu-kvm libvirt-daemon-system libvirt-clients virtinst -y
将用户添加到kvm和libvirt组
sudo usermod -aG kvm $USER
sudo usermod -aG libvirt $USER
启动和设置开机自启动
sudo systemctl enable --now libvirtd
sudo systemctl status libvirtd
创建虚拟硬盘
sudo qemu-img create -f qcow2 /var/lib/libvirt/images/CentOS7.qcow2 64G
安装kvm虚拟机
sudo virt-install --virt-type kvm --name CentOS7 --vcpus 1 --ram 2048 --cdrom=/var/lib/libvirt/CentOS-7-x86_64-Minimal-1810.iso --disk path=/var/lib/libvirt/images/CentOS7.qcow2 --network bridge=br0 --graphics vnc,listen=0.0.0.0 --noautoconsole
--cdrom
参数是指定ISO文件路径,请自行上传到主机目录上
--disk
参数是指定虚拟硬盘路径
标签:jammy,universe,--,安装,Ubuntu22.04,kvm,ubuntu,main,multiverse From: https://www.cnblogs.com/jiaxzeng/p/17921526.html说明:启动没有报错的话,主机上会生成
5900
端口(默认),通过vpc客户端连接即可