ubuntu22.04 编译安装libvirt 10.x

发布于:2025-02-10 ⋅ 阅读:(52) ⋅ 点赞:(0)

环境安装

sudo apt-get update -y
sudo apt-get install qemu-system-x86  bridge-utils  libyajl-dev libtirpc-dev  -y
sudo apt-get install build-essential autoconf automake libtool -y
sudo apt-get install libxml2-dev libxslt1-dev libgnutls28-dev libpciaccess-dev libnl-3-dev libnl-route-3-dev -y
sudo apt-get install pkg-config python3-dev ruby-dev gettext libparted-dev libyaml-dev libssh2-1-dev -y 
sudo apt-get install meson ninja-build -y
sudo apt-get  install libxml2-utils -y
sudo apt install -y xsltproc -y
sudo apt install libmount-devel -y
sudo apt-get install libglib2.0-dev pkg-config -y
sudo apt-get install python3-docutils -y
sudo apt install virt-manager -y

libvirt下载

git clone https://gitee.com/openeuler/libvirt.git

编译安装

cd libvirt
meson setup build -Dbuildtype=debug -Dsystem=true -Ddriver_qemu=enabled
cd build && meson compile && meson install

libivrt服务状态查看

sudo systemctl status libvirtd

编译安装libivrtd配置文件的位置

8.x

/usr/local/etc/libvirt/libvirtd.conf
10.x
/etc/libvirt/libvirtd.conf 

安装qemu-kvm,输入命令无反应

sudo ln -s /usr/bin/qemu-system-x86_64 /usr/bin/qemu-kvm

自动化安装编译的脚本

#!/bin/bash

# 更新包列表
echo "Updating package list..."
sudo apt-get update -y

# 安装必要的依赖
echo "Installing necessary packages..."
sudo apt-get install qemu-system-x86 bridge-utils libyajl-dev -y
sudo apt-get install build-essential autoconf automake libtool -y
sudo apt-get install libxml2-dev libxslt1-dev libgnutls28-dev libpciaccess-dev libnl-3-dev libnl-route-3-dev -y
sudo apt-get install pkg-config python3-dev ruby-dev gettext libparted-dev libyaml-dev libssh2-1-dev -y
sudo apt-get install meson ninja-build -y
sudo apt-get install libxml2-utils -y
sudo apt-get install xsltproc -y
sudo apt-get install libmount-dev -y
sudo apt-get install libglib2.0-dev pkg-config -y
sudo apt-get install python3-docutils -y
sudo apt-get install virt-manager -y

# 克隆 libvirt 源代码
echo "Cloning libvirt repository..."
git clone https://gitee.com/openeuler/libvirt.git

# 进入 libvirt 目录
cd libvirt || { echo "Failed to enter libvirt directory"; exit 1; }

# 设置构建目录
echo "Setting up build directory..."
meson setup build -Dbuildtype=debug -Dsystem=true -Ddriver_qemu=enabled

# 进入构建目录
cd build || { echo "Failed to enter build directory"; exit 1; }

# 编译和安装
echo "Compiling and installing libvirt..."
meson compile
sudo meson install

# 检查 libvirtd 服务状态
echo "Checking libvirtd service status..."
sudo systemctl status libvirtd

echo "Installation completed."