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

网络

相关推荐
小二李1 小时前
第11章 nestjs服务端开发:登录鉴权
运维·服务器
i建模2 小时前
如何在Arch Linux中重设忘记的root密码
linux·运维·服务器
chatexcel2 小时前
元空AI+Clawdbot:7×24 AI办公智能体新形态详解(长期上下文/自动化任务/工具粘合)
运维·人工智能·自动化
kida_yuan3 小时前
【Linux】运维实战笔记 — 我常用的方法与命令
linux·运维·笔记
@syh.3 小时前
【linux】进程控制
linux
何中应5 小时前
vmware的linux虚拟机如何设置以命令行方式启动
linux·运维·服务器
江畔何人初5 小时前
kubernet与docker的关系
linux·运维·云原生
bubuly5 小时前
软件开发全流程注意事项:从需求到运维的全方位指南
大数据·运维·数据库
百炼成神 LV@菜哥5 小时前
Kylin Linux V10 aarch64 安装启动 TigerVNC-Server
linux·服务器·kylin
佑白雪乐6 小时前
<Linux基础11集>电流+二极管+晶体管+存储器
linux