-
Notifications
You must be signed in to change notification settings - Fork 2
/
qemu.sh
146 lines (120 loc) · 4.82 KB
/
qemu.sh
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/bin/bash
set -e
install_deps_qemu() {
log_info "Installing QEMU dependencies"
lsb_dist="$( get_distribution )"
case "$lsb_dist" in
ubuntu)
sudo apt-get update
sudo apt-get install -y git make build-essential pkg-config meson zlib1g-dev zlib1g glib2.0 libtool \
libpixman-1-dev dh-autoreconf bridge-utils libpng-dev libjpeg-dev libsdl2-dev libgtk-3-dev \
libnfs-dev libseccomp-dev libiscsi-dev libzstd-dev libcurl4-openssl-dev libsdl2-image-dev \
libkeyutils-dev libfdt-dev libu2f-server-dev libu2f-host-dev libglusterfs-dev librados-dev \
libncursesw5-dev libspice-protocol-dev libspice-server-dev libusb-1.0-0-dev \
libusbredirparser-dev libcap-ng-dev libcap-dev libaio-dev python3-venv \
python3-tomli
;;
centos)
sudo dnf config-manager --set-enabled crb
sudo dnf makecache
sudo dnf install -y git gcc g++ make meson pkg-config zlib-devel glib2-devel pixman-devel libtool \
libpng-devel libjpeg-devel SDL2-devel gtk3-devel libaio-devel bzip2 \
nfs-utils libseccomp-devel libiscsi-devel libzstd-devel curl-devel keyutils-libs-devel \
libfdt-devel librados-devel libusb1-devel usbredir-devel libcap-ng-devel libattr-devel \
python3-tomli
;;
rhel)
sudo dnf makecache
sudo dnf install -y git gcc g++ make meson pkg-config zlib-devel glib2-devel pixman-devel libtool \
libpng-devel libjpeg-devel SDL2-devel gtk3-devel libaio-devel bzip2 \
nfs-utils libseccomp-devel libiscsi-devel libzstd-devel curl-devel keyutils-libs-devel \
libfdt-devel librados-devel libusb1-devel usbredir-devel libcap-ng-devel libattr-devel \
python3-tomli
;;
fedora)
case "$( get_distribution_variant )" in
silverblue)
rpm-ostree install -A --allow-inactive --idempotent git gcc g++ make meson pkg-config zlib-devel glib2-devel pixman-devel libtool \
dh-autoreconf bridge-utils libpng-devel libjpeg-devel SDL2-devel gtk3-devel libaio-devel \
libnfs-devel libseccomp-devel libiscsi-devel libzstd-devel curl-devel keyutils-libs-devel \
libfdt-devel libu2f-server-devel libu2f-host-devel libglusterfs-devel librados-devel \
spice-server-devel libusb1-devel usbredir-devel libcap-ng-devel libattr-devel \
python3-tomli
;;
*)
sudo dnf makecache
sudo dnf install -y git gcc g++ make meson pkg-config zlib-devel glib2-devel pixman-devel libtool \
dh-autoreconf bridge-utils libpng-devel libjpeg-devel SDL2-devel gtk3-devel libaio-devel \
libnfs-devel libseccomp-devel libiscsi-devel libzstd-devel curl-devel keyutils-libs-devel \
libfdt-devel libu2f-server-devel libu2f-host-devel libglusterfs-devel librados-devel \
spice-server-devel libusb1-devel usbredir-devel libcap-ng-devel libattr-devel \
python3-tomli
;;
esac
;;
*)
log_fatal "Distributive '$lsb_dist' is unsupported. Please compile QEMU manually."
;;
esac
}
compile_qemu() {
log_info "Compiling QEMU"
qemu_dir="$(realpath "${1}")"
(
cd "${qemu_dir}"
git clean -f -x
git clean -f -X
git clean -f -d
make distclean || :
rm -rf build
git submodule update --init
./configure --disable-docs --target-list=x86_64-softmmu --enable-virtfs --disable-werror
make -j "$(nproc)"
)
}
check_qemu() {
qemu_dir="$(realpath "${1}")"
qemu_args=(
-monitor stdio
-nographic
-serial none
)
if [ "${DISABLE_KVM_CHECK}" != "yes" ]; then
qemu_args+=(
-enable-kvm
-netdev tap,id=net0,vhost=on,script=no,downscript=no -device e1000,netdev=net0
)
fi
unshare --user --net --map-root-user \
"${qemu_dir}/build/qemu-system-x86_64" "${qemu_args[@]}" <<< q
[ -f "${qemu_dir}/build/qemu-img" ] || return 1
[ -f "${qemu_dir}/build/contrib/ivshmem-server/ivshmem-server" ] || return 1
if [ ! -f "${qemu_dir}/build/tools/virtiofsd/virtiofsd" ]; then
[ -f "${FS_DAEMON_BIN}" ] || return 1
fi
return 0
}
get_config_qemu() {
qemu_dir="$(realpath "${1}")"
echo "QEMU_BIN='${qemu_dir}/build/qemu-system-x86_64'"
echo "QEMU_IMG_BIN='${qemu_dir}/build/qemu-img'"
echo "IVSHMEM_SERVER_BIN='${qemu_dir}/build/contrib/ivshmem-server/ivshmem-server'"
[ -f "${FS_DAEMON_BIN}" ] || echo "FS_DAEMON_BIN='${qemu_dir}/build/tools/virtiofsd/virtiofsd'"
}
post_clone_QEMU() {
log_info "QEMU repository post clone"
qemu_dir="$(realpath "${1}")"
install_deps_qemu
compile_qemu "${qemu_dir}"
if check_qemu "${qemu_dir}"; then
log "QEMU binary compiled successfully"
else
log_fatal "Can't find QEMU binary"
fi
}
process_QEMU() {
log_info "QEMU repository custom processing"
qemu_dir="$(realpath "${1}")"
get_config_qemu "${qemu_dir}" >>"${bootstrap}"
echo >>"${bootstrap}"
}