-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathactivate-zfs-in-qubes-vm
executable file
·117 lines (98 loc) · 3.75 KB
/
activate-zfs-in-qubes-vm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# #!/bin/bash
set -ex
[ "${FLOCKER}" == "" ] && {
flocker=~/.activate-zfs-in-qubes-vm
exec env FLOCKER=$flocker flock -x "$flocker" "$0" "$@"
} || :
function cleanup() {
if [ -d "$tmprpmdir" ] ; then
rm -rf -- "$tmprpmdir"
fi
if [ -f "/etc/yum.repos.d/zfs-temp.repo" ] ; then
rm -f "/etc/yum.repos.d/zfs-temp.repo"
fi
}
trap cleanup EXIT
function deployzfshere() {
local cmd
local opts
local release
local kernel
pathtorpms="$1"
kernel="$2"
arch="$3"
# FIXME: ultimately we must install the kernel-devel package using this mechanism because the kernel upgrade cycle happens outside the VM lifecycle, in the VM host to be exact. VMs themselves have no kernel within them.
command -v dnf && { cmd=dnf ; opts="--best --allowerasing" ; } || { cmd=yum ; opts= ; }
version=$(echo "$kernel" | awk -F - ' { print $1 } ')
release=$(echo "$kernel" | awk -F - ' { print $2 } ' | sed -r 's/[.]([a-z0-9_]+)$//' )
if uname -r | grep -q pvops.qubes
then
rpm -q kernel-devel-"$kernel" || {
url=https://yum.qubes-os.org/r3.2/current/dom0/fc23/rpm
$cmd install $opts -qy $url/kernel-devel-"$kernel".rpm
}
else
rpm -q kernel-"$kernel" kernel-devel-"$kernel" kernel-modules-"$kernel" || {
$cmd install $opts -y kernel-"$kernel" kernel-devel-"$kernel" kernel-modules-"$kernel" || {
url=https://kojipkgs.fedoraproject.org/packages/kernel/$version/$release/$arch
$cmd install $opts -y $url/kernel-"$kernel".rpm $url/kernel-devel-"$kernel".rpm $url/kernel-modules-"$kernel".rpm
}
}
fi
rpm -q createrepo_c || $cmd install $opts -y createrepo_c
rpm -q elfutils-devel || $cmd install $opts -y elfutils-devel
rpm -q rsync || $cmd install $opts -y rsync
release=`rpm -q fedora-release fedora-release-cloud grub2 --queryformat '%{version}\n' | grep -v ' is not installed' | tail -1`
if [ "$release" == "" ] ; then echo "No release detected, aborting" >&2 ; exit 8 ; fi
tmprpmdir=`mktemp -d`
rsync -av "$pathtorpms"/ "$tmprpmdir"/
pushd "$tmprpmdir"
find -type f | grep '[.]'fc"$release" | tee /dev/stderr > pkglist
createrepo_c -v -i pkglist .
popd
# Now we create the temporary yum / dnf repository.
cat > /etc/yum.repos.d/zfs-temp.repo << EOF
[zfs-temp]
name=ZFS temporary deployer
baseurl=file://$tmprpmdir
enabled=0
gpgcheck=0
metadata_expire=1
EOF
# Now we install the RPMs proper.
# FIXME: installation of arbitrary RPMs here really should not happen. The following RPMs are being supplied by Jenkins itself.
# This is dangerous for several reasons. What really ought to happen is a deploy using yum from a known, prekeyed, and signed
# yum repository, but I don't yet have a file server with trusted packages, and I am working on that.
$cmd $opts -y --enablerepo=zfs-temp install \
zfs \
zfs-dkms \
cleanup
dkms autoinstall
echo =============== DKMS BUILD LOGS ================= >&2
for a in /var/lib/dkms/zfs/*/build/make.log /var/lib/dkms/zfs/*/log/make.log ; do
test -f "$a" || continue
echo === "$a" === >&2
cat "$a" >&2
done
}
if [ "$1" == "" ] ; then
echo usage: sudo "$0" "<path to built (tools/DKMS) ZFS RPMs>" >&2
exit 64
fi
fullpathtorpms=$( realpath "$1" )
arch=`uname -m`
kernel=`uname -r`
if [ ! -f "/var/lib/dkms/zfs/kernel-$kernel-$arch/module/zfs.ko" -a ! -f "/var/lib/dkms/zfs/kernel-$kernel-$arch/module/zfs.ko.xz" ] ; then
deployzfshere "$fullpathtorpms" "$kernel" "$arch"
fi
lsmod | grep -q zlib || {
if find /lib/modules/"$kernel" -name 'zlib.ko*' | grep -q zlib ; then modprobe zlib ; fi
}
for x in `seq 20` ; do
if lsmod | grep zfs ; then break ; fi
for mod in /var/lib/dkms/zfs/kernel-$kernel-$arch/module/*.ko /var/lib/dkms/zfs/kernel-$kernel-$arch/module/*.ko.xz ; do
test -f "$mod" || continue
insmod $mod || true
done
done
lsmod | grep zfs