0

libvirt: add 9.10.0

This commit is contained in:
eleksir
2024-05-23 16:17:22 +03:00
parent 82c380fee0
commit 4da8d8c3aa
8 changed files with 550 additions and 0 deletions

69
libvirt/README Normal file
View File

@@ -0,0 +1,69 @@
libvirt - The virtualization API
libvirt is a toolkit to interact with the virtualization
capabilities of recent versions of Linux (and other OSes).
Most optional dependencies are autodetected and having the required
libs in place will build the respective features automatically.
The user and group can be specified at build time like this:
VIRTUSER=someuser VIRTGROUP=someuser ./libvirt.SlackBuild
(default is VIRTUSER=root VIRTGROUP=users)
You'll want to keep this in sync with what qemu uses
(it also defaults to these)
If you want to start the libvirt daemon at boot, add this
to /etc/rc.d/rc.local
# Start libvirt:
if [ -x /etc/rc.d/rc.libvirt ]; then
/etc/rc.d/rc.libvirt start
fi
and if you want it to stop at shutdown add this to
/etc/rc.d/rc.local_shutdown
# Stop libvirt:
if [ -x /etc/rc.d/rc.libvirt ]; then
/etc/rc.d/rc.libvirt stop
fi
The enclosed rc.libvirt script will do a 'managedsave' on all running
and paused guests when issuing 'rc.libvirt stop'. Please note that
this saves the RAM of each guest to the host system's disk (by default
under /var/lib/libvirt/qemu/save) - so make sure enough space is
available. If you prefer to perform a full shutdown on all running
guests instead, issue a 'rc.libvirt guests_shutdown' followed by
'rc.libvirt shutdown'.
By default 'rc.libvirt stop' and 'rc.libvirt guests_shutdown' will
wait a maximum of 5 minutes for all guests to shutdown, after which
any guests still running will be destroyed. Adjust this to a suitable
value for your system, as destroying a running guest carries a high
risk of data loss!
There is also a 'guests_reboot' for rebooting all running guests.
Have a look at the commented part of rc.libvirt for some gotchas.
netcat-openbsd is an optional dependency (needed if you
want to connect from a remote host using virt-manager).
As of the 4.5.0 version, you may have to remove any previously
installed versions of libvirt before this will build.
Note also that sometimes, in consequence of a major-version upgrade,
you might discover that the libvirt configuration is in an inconsistent
state (machine networking broken and so on) and when this happens and a
simple reboot won't solve you might want to consider starting from a
clean state. To do this:
- backup the existing vms files and their configurations too (with
"virsh dumpxml $name > ${name}.xml", check all the *dumpxml commands
available with "virsh help")
- remove libvirt
- delete all system directories (/var/lib/libvirt, /var/log/libvirt,
/etc/libvirt)
- install the new libvirt package, logout and login again (might help)
and start the daemon
- recreate your configurations (network and so on)
- reimport the vms xml backups (with "virsh define ${name}.xml")

26
libvirt/doinst.sh Normal file
View File

@@ -0,0 +1,26 @@
config() {
NEW="$1"
OLD="$(dirname $NEW)/$(basename $NEW .new)"
# If there's no config file by that name, mv it over:
if [ ! -r $OLD ]; then
mv $NEW $OLD
elif [ "$(cat $OLD | md5sum)" = "$(cat $NEW | md5sum)" ]; then
# toss the redundant copy
rm $NEW
fi
# Otherwise, we leave the .new copy for the admin to consider...
}
preserve_perms() {
NEW="$1"
OLD="$(dirname $NEW)/$(basename $NEW .new)"
if [ -e $OLD ]; then
cp -a $OLD ${NEW}.incoming
cat $NEW > ${NEW}.incoming
mv ${NEW}.incoming $NEW
fi
config $NEW
}
preserve_perms etc/rc.d/rc.libvirt.new

154
libvirt/libvirt.SlackBuild Executable file
View File

@@ -0,0 +1,154 @@
#!/bin/bash
# Copyright 2024 Sergei Fedosoff <s.fedosov@gmail.com>
#
# All rights reserved.
#
# Redistribution and use of this script, with or without modification, is
# permitted provided that the following conditions are met:
#
# 1. Redistributions of this script must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
# EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
cd $(dirname $0) ; CWD=$(pwd)
PRGNAM=libvirt
VERSION=${VERSION:-9.10.0}
BUILD=${BUILD:-1}
TAG=${TAG:-_EXs}
PKGTYPE=${PKGTYPE:-tgz}
if [ -z "$ARCH" ]; then
case "$( uname -m )" in
i?86) ARCH=i586 ;;
arm*) ARCH=arm ;;
*) ARCH=$( uname -m ) ;;
esac
fi
TMP=${TMP:-/tmp/EXs}
PKG=$TMP/package-$PRGNAM
OUTPUT=${OUTPUT:-/tmp}
if [ "$ARCH" = "i586" ]; then
SLKCFLAGS="-O2 -march=i586 -mtune=i686"
LIBDIRSUFFIX=""
elif [ "$ARCH" = "x86_64" ]; then
SLKCFLAGS="-O2 -fPIC"
LIBDIRSUFFIX="64"
else
SLKCFLAGS="-O2"
LIBDIRSUFFIX=""
fi
VIRTUSER=${VIRTUSER:-root}
VIRTGROUP=${VIRTGROUP:-users}
set -e
rm -rf $PKG
mkdir -p $TMP $PKG $OUTPUT
cd $TMP
rm -rf $PRGNAM-$VERSION
tar xf $CWD/$PRGNAM-$VERSION.tar.xz
cd $PRGNAM-$VERSION
chown -R root:root .
sed -i "s|prefix / 'lib' / 'sysctl.d'|sysconfdir / 'sysctl.d'|" src/remote/meson.build
patch -p1 -i $CWD/use-virtgroup-in-polkit-rules.diff
sed -i -e "s,@VIRTGROUP@,$VIRTGROUP,g" src/remote/libvirtd.rules
CFLAGS="$SLKCFLAGS" \
CXXFLAGS="$SLKCFLAGS" \
meson setup build \
--buildtype=release \
--infodir=/usr/info \
--libdir=/usr/lib${LIBDIRSUFFIX} \
--localstatedir=/var \
--mandir=/usr/man \
--prefix=/usr \
--sysconfdir=/etc \
-Dqemu_group=$VIRTGROUP \
-Dqemu_user=$VIRTUSER \
-Dbash_completion=enabled \
-Dbash_completion_dir=/usr/share/bash-completion/completions \
-Daudit=disabled \
-Dlibiscsi=disabled \
-Dopenwsman=disabled \
-Dapparmor=disabled \
-Dselinux=disabled \
-Dwireshark_dissector=disabled \
-Ddriver_bhyve=disabled \
-Ddriver_hyperv=disabled \
-Ddriver_libxl=disabled \
-Ddriver_vz=disabled \
-Dsecdriver_apparmor=disabled \
-Dsecdriver_selinux=disabled \
-Dstorage_vstorage=disabled \
-Ddtrace=disabled \
-Dstrip=true \
-Dinit_script=none
meson install -C build --destdir $PKG
rm -rf $PKG/usr/share/augeas
rm -Rf $PKG/var/run
# add an rc.libvirt to start/stop/restart the daemon
install -Dpm 0755 $CWD/rc.libvirt $PKG/etc/rc.d/rc.libvirt.new
sed -i \
-e "s|^\#unix_sock_group\ =\ \"libvirt\"|unix_sock_group = \"$VIRTGROUP\"|" \
-e "s|^\#unix_sock_rw_perms\ =\ \"0770\"|unix_sock_rw_perms = \"0770\"|" \
-e "s|^\#auth_unix_ro.*|auth_unix_ro = \"none\"|" \
-e "s|^\#auth_unix_rw.*|auth_unix_rw = \"none\"|" \
-e "s|^\#listen_tls|listen_tls|" \
$PKG/etc/libvirt/libvirtd.conf
sed -i -e "s|^\#group\ =\ \"root\"|group = \"$VIRTGROUP\"|" $PKG/etc/libvirt/qemu.conf
if [ -e $PKG/etc/libvirt/qemu.conf ]; then
sed -i "s|^\#seccomp_sandbox = 1|seccomp_sandbox = 0|" \
$PKG/etc/libvirt/qemu.conf
fi
gzip -9 $PKG/usr/man/man*/*
mkdir -p $PKG/usr/doc/$PRGNAM-$VERSION
mv $PKG/usr/share/doc/$PRGNAM/* $PKG/usr/doc/$PRGNAM-$VERSION/
rm -Rf $PKG/usr/share/doc
cp -a \
*.rst COPYING* examples/polkit/* \
$PKG/usr/doc/$PRGNAM-$VERSION
install -Dpm 0644 $CWD/$PRGNAM.SlackBuild $PKG/usr/doc/$PRGNAM-$VERSION/$PRGNAM.SlackBuild
install -Dpm 0644 $CWD/slack-desc $PKG/install/slack-desc
install -Dpm 0644 $CWD/slack-required $PKG/install/slack-required
install -Dpm 0644 $CWD/doinst.sh $PKG/install/doinst.sh
# Don't clobber existing configuration files
for i in etc/libvirt etc/libvirt/nwfilter etc/libvirt/qemu/networks etc/logrotate.d etc/sasl2 etc/sysctl.d; do
for j in $(ls -1 $PKG/$i); do
if [ ! -d $PKG/$i/$j ]; then
mv $PKG/$i/$j $PKG/$i/$j.new
echo "config $i/$j.new" >> $PKG/install/doinst.sh
fi
done
done
cd $PKG
/sbin/makepkg -l y -c n $OUTPUT/$PRGNAM-$VERSION-$ARCH-$BUILD$TAG.$PKGTYPE

10
libvirt/libvirt.info Normal file
View File

@@ -0,0 +1,10 @@
PRGNAM="libvirt"
VERSION="9.10.0"
HOMEPAGE="http://libvirt.org"
DOWNLOAD="https://libvirt.org/sources/libvirt-9.10.0.tar.xz"
MD5SUM="c546d8745508bd95147bc749dea82ff1"
DOWNLOAD_x86_64=""
MD5SUM_x86_64=""
REQUIRES="yajl"
MAINTAINER="Sergei Fedosoff"
EMAIL="eleksir@gmail.com"

256
libvirt/rc.libvirt Normal file
View File

@@ -0,0 +1,256 @@
#!/usr/bin/bash
# Init script for libvirtd on Slackware
# Written by Matteo Bernardini <ponce@slackbuilds.org>
#
# Note that a dnsmasq daemon is started by libvirtd itself to serve
# its virtual network, and possibly can conflict with a dnsmasq
# already running on the system, see
# http://wiki.libvirt.org/page/Libvirtd_and_dnsmasq
# Note also that the tun, vhost_net and kvm related modules are
# automatically loaded at start and removed at stop: edit the
# script if this behaviour conflicts with anything else running
# on your setup
VIRSH=/usr/bin/virsh
MODULES="tun vhost_net"
TIMEOUT=${TIMEOUT:-300}
LIBVIRTD_PIDFILE="/var/run/libvirt/libvirtd.pid"
LIBVIRTD_OPTS=${LIBVIRT_OPTS:-" -f /etc/libvirt/libvirtd.conf -p $LIBVIRTD_PIDFILE "}
VIRTLOGD_PIDFILE="/var/run/libvirt/virtlogd.pid"
VIRTLOGD_OPTS=${VIRTLOGD_OPTS:-" -f /etc/libvirt/virtlogd.conf -p $VIRTLOGD_PIDFILE "}
VIRTLOCKD_PIDFILE="/var/run/libvirt/virtlockd.pid"
VIRTLOCKD_OPTS=${VIRTLOCKD_OPTS:-" -f /etc/libvirt/virtlockd.conf -p $VIRTLOCKD_PIDFILE "}
guests_reboot() {
for machine in $($VIRSH list --name --state-running | grep -v ^$) ; do
$VIRSH reboot $machine
done
}
guests_shutdown() {
for machine in $($VIRSH list --name --state-running | grep -v ^$) ; do
$VIRSH shutdown $machine &
done
sleep 2
echo -n "Waiting for guests to finish shutting down..."
count=0
while [ $($VIRSH list --name --state-running | grep -v ^$ | wc -l) -gt "0" ]; do
if [ "$count" -ge "$TIMEOUT" ];then
break
fi
echo -n "."
count=$(expr $count + 1)
sleep 1
done
echo ""
if [ $($VIRSH list --name --state-running | grep -v ^$ | wc -l) -gt "0" ];then
echo -n "The following guests are still running after $TIMEOUT seconds; destroying them: "
for machine in $($VIRSH list --name --state-running | grep -v ^$) ; do
$VIRSH destroy $machine
echo -n "$machine "
done
sleep 2
else
# add back the seconds we waited before starting the count
count=$(expr $count + 2)
echo "Shutdown of guests took $count seconds..."
fi
}
guests_managedsave() {
# apply managedsave on running and paused machines (as we can't distinguish between
# the two states while managedsave is being applied, so won't know when to finish waiting)
for machine in $($VIRSH list --name | grep -v ^$) ; do
$VIRSH managedsave $machine &
done
sleep 2
echo -n "Waiting for managedsave to finish on all guests..."
count=0
while [ $($VIRSH list --name | grep -v ^$ | wc -l) -gt "0" ]; do
if [ "$count" -ge "$TIMEOUT" ];then
break
fi
echo -n "."
count=$(expr $count + 1)
sleep 1
done
echo ""
if [ $($VIRSH list --name | grep -v ^$ | wc -l) -gt "0" ];then
echo -n "Following guests are still running after $TIMEOUT seconds, destroying them: "
for machine in $($VIRSH list --name | grep -v ^$) ; do
$VIRSH destroy $machine
echo -n "$machine "
done
sleep 2
else
# add back the seconds we waited before starting the count
count=$(expr $count + 2)
echo "Guests managed save took $count seconds..."
fi
}
check_processor() {
egrep 'vmx' /proc/cpuinfo > /dev/null
if [ "$?" -eq "0" ];then
MODULES="$MODULES kvm_intel kvm"
fi
check=$?
egrep 'svm' /proc/cpuinfo > /dev/null
if [ "$?" -eq "0" ];then
MODULES="$MODULES kvm_amd kvm"
fi
check=$(expr $check + $?)
if [ $check -eq "2" ];then
echo "Your system does not support KVM!"
fi
}
start_libvirtd() {
if [ -f $LIBVIRTD_PIDFILE ];then
echo "libvirt is already running..."
exit 1
fi
echo "Starting libvirtd: /usr/sbin/libvirtd -d "
mkdir -p $(dirname $LIBVIRTD_PIDFILE) /run/libvirt/{lockd,lxc,network,qemu/swtpm}
check_processor
/sbin/modprobe -a $MODULES
/usr/sbin/libvirtd -d -l $LIBVIRTD_OPTS
}
stop_libvirtd() {
if [ ! -f $LIBVIRTD_PIDFILE ];then
echo "libvirt is not running..."
exit 2
fi
guests_managedsave
check_processor
echo "Stopping libvirtd..."
for network in $($VIRSH net-list --name); do
$VIRSH net-destroy "$network"
done
kill -TERM $(cat $LIBVIRTD_PIDFILE)
sleep 3
/sbin/modprobe -ra $MODULES 2>/dev/null
}
start_virtlogd() {
if [ -f $VIRTLOGD_PIDFILE ];then
echo "virtlogd is already running..."
exit 1
fi
echo "Starting virtlogd: /usr/sbin/virtlogd -d "
mkdir -p $(dirname $VIRTLOGD_PIDFILE)
/usr/sbin/virtlogd -d $VIRTLOGD_OPTS
}
stop_virtlogd() {
if [ ! -f $VIRTLOGD_PIDFILE ];then
echo "virtlogd is not running..."
exit 2
fi
echo "Stopping virtlogd..."
kill -TERM $(cat $VIRTLOGD_PIDFILE)
sleep 1
}
start_virtlockd() {
if [ -f $VIRTLOCKD_PIDFILE ];then
echo "virtlockd is already running..."
exit 1
fi
echo "Starting virtlockd: /usr/sbin/virtlockd -d "
mkdir -p $(dirname $VIRTLOCKD_PIDFILE)
/usr/sbin/virtlockd -d $VIRTLOCKD_OPTS
}
stop_virtlockd() {
if [ ! -f $VIRTLOCKD_PIDFILE ];then
echo "virtlockd is not running..."
exit 2
fi
echo "Stopping virtlockd..."
kill -TERM $(cat $VIRTLOCKD_PIDFILE)
sleep 1
}
soft_restart() {
echo "Soft-restarting libvirt..."
if [ ! -f $LIBVIRTD_PIDFILE ];then
echo "libvirt is not running..."
exit 2
fi
echo "Stopping libvirtd..."
kill -TERM $(cat $LIBVIRTD_PIDFILE)
sleep 3
stop_virtlogd
stop_virtlockd
sleep 1
start_virtlockd
start_virtlogd
start_libvirtd
}
case $1 in
start)
start_virtlockd
start_virtlogd
start_libvirtd
;;
stop)
stop_libvirtd
stop_virtlogd
stop_virtlockd
;;
restart)
stop_libvirtd
stop_virtlogd
stop_virtlockd
sleep 2
start_virtlockd
start_virtlogd
start_libvirtd
;;
soft_restart)
soft_restart
;;
guests_shutdown)
guests_shutdown
;;
guests_reboot)
guests_reboot
;;
*)
echo "Usage: $0 (start|stop|restart|soft_restart|guests_shutdown|guests_reboot)"
;;
esac

19
libvirt/slack-desc Normal file
View File

@@ -0,0 +1,19 @@
# HOW TO EDIT THIS FILE:
# The "handy ruler" below makes it easier to edit a package description.
# Line up the first '|' above the ':' following the base package name, and
# the '|' on the right side marks the last column you can put a character in.
# You must make exactly 11 lines for the formatting to be correct. It's also
# customary to leave one space after the ':' except on otherwise blank lines.
|-----handy-ruler------------------------------------------------------|
libvirt: libvirt (The virtualization API)
libvirt:
libvirt: libvirt is a toolkit to interact with the virtualization
libvirt: capabilities of recent versions of Linux (and other OSes).
libvirt:
libvirt: Homepage: http://libvirt.org
libvirt:
libvirt:
libvirt:
libvirt:
libvirt:

1
libvirt/slack-required Normal file
View File

@@ -0,0 +1 @@
yajl

View File

@@ -0,0 +1,15 @@
diff -Nur libvirt-4.6.0.orig/src/remote/libvirtd.rules libvirt-4.6.0/src/remote/libvirtd.rules
--- libvirt-4.6.0.orig/src/remote/libvirtd.rules 2018-02-26 03:02:18.496310271 -0600
+++ libvirt-4.6.0/src/remote/libvirtd.rules 2018-08-12 21:55:35.293691409 -0500
@@ -1,9 +1,9 @@
-// Allow any user in the 'libvirt' group to connect to system libvirtd
+// Allow any user in the '@VIRTGROUP@' group to connect to system libvirtd
// without entering a password.
polkit.addRule(function(action, subject) {
if (action.id == "org.libvirt.unix.manage" &&
- subject.isInGroup("libvirt")) {
+ subject.isInGroup("@VIRTGROUP@")) {
return polkit.Result.YES;
}
});