Ubuntu如何安装KVM

环境:

联想E14笔记本

Ubuntu20.04

问题描述:

Ubuntu如何安装KVM

解决方案:

1.验证CPU是否支持硬件虚拟化

bash 复制代码
root@st-ThinkPad-E14:~# grep -Eoc '(vmx|svm)' /proc/cpuinfo
16

2.检查 VT 是否在 BIOS 中启用

安装 apt install cpu-checker

bash 复制代码
root@st-ThinkPad-E14:~# apt install cpu-checker
正在读取软件包列表... 完成
正在分析软件包的依赖关系树       
正在读取状态信息... 完成       
将会同时安装下列软件:
  msr-tools
下列【新】软件包将被安装:
  cpu-checker msr-tools

kvm-ok 查看

bash 复制代码
root@st-ThinkPad-E14:~# kvm-ok
INFO: /dev/kvm exists
KVM acceleration can be used

3.安装KVM

bash 复制代码
sudo apt install qemu-kvm libvirt-daemon-system libvirt-clients bridge-utils virt-manager

激活

bash 复制代码
systemctl is-active libvirtd

4.启用KVM模块:默认情况下,Ubuntu会自动加载KVM模块,但你可以检查一下以确保它已经加载。运行以下命令来验证

bash 复制代码
lsmod | grep kvm

root@st-ThinkPad-E14:~# lsmod | grep kvm
kvm_intel             376832  0
kvm                  1015808  1 kvm_intel

5.启动虚拟化和设置开机自启

bash 复制代码
# systemctl start libvirtd 
# systemctl enable libvirtd
# systemctl list-unit-files |grep libvirtd.service 

查看是否成功
root@st-ThinkPad-E14:~# systemctl list-unit-files |grep libvirtd.service
libvirtd.service                                                          enabled         enabled 

创建虚拟机命令

bash 复制代码
cd /var/lib/libvirt/images/hassos-vm
virt-install --import --name hassos \
--memory 4096 --vcpus 4 --cpu host \
--disk haos_ova-6.6.qcow2,format=qcow2,bus=virtio \
--network bridge=br0,model=virtio \
--osinfo detect=on,require=off \
--graphics none \
--noautoconsole \
--boot uefi


# virt-install --name=kvm-centos7 --ram=2048 --vcpus=2 --disk path=/root/kvmraw/centos7v1(虚拟机名称和位置).qcow2,size=10,format=qcow2 --accelerate --cdrom /root/isolib/CentOS-7-x86_64-DVD-1611.iso(你的镜像名称和位置) --vnc  --vnclisten=0.0.0.0 --network bridge=br0,model=virtio(执行完会创建虚拟机,并且弹出页面)

6.使用命令ifconfig查看自己的ip等

修改01-network-manager-all.yaml文件:

bash 复制代码
# nano /etc/netplan/01-network-manager-all.yaml

手动

bash 复制代码
network:
    version: 2
    ethernets:
        enp3s0:(改为你的网卡名字)
            dhcp4: false
            dhcp6: false
    bridges:
        br0:
            addresses: [192.168.1.2/24](你的ip)
            gateway4: 192.168.1.1 (你的网关)
            nameservers:
                addresses: [114.114.114.114, 8.8.8.8](这是DNS1,DNS2)
                search: [msnode]
            interfaces: [enp3s0(改为你的网卡名字)]


自动

network:
  version: 2
  renderer: networkd
  ethernets:
    wlp5s0:
      dhcp4: no

  bridges:
    macvtap0@wlp5s0:
      dhcp4: yes
      interfaces: [wlp5s0]
      

sudo netplan apply

nm-connection-editor

网络

相关推荐
lllsure8 小时前
Linux 实用指令
linux·物联网
努力的小T9 小时前
使用 Docker 部署 Apache Spark 集群教程
linux·运维·服务器·docker·容器·spark·云计算
Nerd Nirvana9 小时前
OpenSSL crt & key (生成一套用于TLS双向认证的证书密钥)
linux·ssl·shell·认证·加密·tls·oepnssl
letisgo510 小时前
记录一次部署PC端网址全过程
linux·阿里云·服务器运维
枫叶落雨22210 小时前
08-Elasticsearch
运维·jenkins
猫猫的小茶馆10 小时前
【网络编程】UDP协议
linux·服务器·网络·网络协议·ubuntu·udp
尚墨111110 小时前
linux 安装启动zookeeper全过程及遇到的坑
linux·zookeeper
鱼嘻10 小时前
Linux自学day23-进程和线程
linux·服务器·c语言·进程和线程
AuGuSt_8110 小时前
在windows下安装windows+Ubuntu16.04双系统(下)
linux·ubuntu·双系统
old_power11 小时前
Linux(Ubuntu24.04)源码编译安装OpenCV4.6.0
linux·opencv