Loading

ArchLinux 使用KVM和virt-manager

安装

yay -S qemu virt-manager

网络相关依赖包

没有下列软件包初始化NAT网络可能会出现异常 libvirt:Failed to initialize a valid firewall backend

yay -S ebtables iptables dnsmasq

配置

  1. 配置 libvirtd 用户组
sudo vim /etc/libvirt/libvirtd.conf

取消注释并修改以下两行

# 用户组
unix_sock_group = "wheel"

# unix_sock_rw_perms = "0770"
  1. 添加当前用户到用户组中
    PS:如果用户已配置用户组则不需要进行此步骤
sudo usermod -a -G wheel $(whoami)
  1. 设置 libvirtd 开机自启
sudo systemctl start libvirtd
sudo systemctl enable libvirtd

可以通过命令行 (virsh) 或通过 virt-manager 图形界面管理 libvirt 系统
image

建议在Home目录下创建一个文件系统目录,在此目录手动创建硬盘。自动创建可能会出现不可预知的权限问题

image

网卡配置

启动网卡

  1. 首先建立default网卡文件
sudo cat /etc/libvirt/qemu/networks/default.xml                                                                                                1 ✘  19:22:18  

<!--
WARNING: THIS IS AN AUTO-GENERATED FILE. CHANGES TO IT ARE LIKELY TO BE
OVERWRITTEN AND LOST. Changes to this xml configuration should be made using:
  virsh net-edit default
or other application using the libvirt API.
-->

<network>
  <name>default</name>
  <uuid>7ef2500e-b19a-4e8a-9322-467bb7e50f43</uuid>
  <forward mode='nat'/>
  <bridge name='virbr0' stp='on' delay='0'/>
  <mac address='52:54:00:a4:29:99'/>
  <ip address='192.168.122.1' netmask='255.255.255.0'>
    <dhcp>
      <range start='192.168.122.2' end='192.168.122.254'/>
    </dhcp>
  </ip>
</network>
  1. 定义网卡
sudo virsh net-define /etc/libvirt/qemu/networks/default.xml
  1. 启动网卡
virsh net-start default

4、查看网卡

ip a

关闭DHCP服务器

如果有这个需求可按以下方式关闭

  1. 停止dnsmasq DHCP和DNS服务器
sudo systemctl stop dnsmasq
sudo systemctl enable dnsmasq

2.查看网卡

sudo virsh net-list    

  1. 已经分配的dhcp租约条目
sudo virsh net-dhcp-leases default                                             
 Expiry Time   MAC 地址   Protocol   IP address   Hostname   Client ID or DUID
2021-12-13 16:09:57  52:54:00:c6:51:45  ipv4      192.168.122.23/24         registry        01:52:54:00:c6:51:45
  1. 直接删除dhcp租约条目
sudo rm -rf /var/lib/libvirt/dnsmasq/virbr0.*
sudo virsh net-dhcp-leases default

posted @ 2021-12-10 14:12  白日醒梦  阅读(1196)  评论(0编辑  收藏  举报