[pbs-devel] [PATCH proxmox-backup-restore-image 2/5] build custom ZFS tools without udev requirement
Stefan Reiter
s.reiter at proxmox.com
Wed Jun 16 12:55:49 CEST 2021
We already include the required sources with the zfsonlinux submodule,
so apply a patch to disable linking against libudev (as I couldn't find
a working configure flag for it?) and build the user space part as well.
Includes dependencies as well as 'strace' for the debug initramfs, which
proved quite useful for debugging.
The init-shim automatically creates the necessary /dev/zfs device node,
and additionally /dev/null to make rust's std::process::Command happy.
Signed-off-by: Stefan Reiter <s.reiter at proxmox.com>
---
src/Makefile | 21 +++++++-
src/build_initramfs.sh | 19 ++++++-
src/init-shim-rs/src/main.rs | 10 ++++
.../0001-remove-reference-to-libudev.patch | 52 +++++++++++++++++++
4 files changed, 100 insertions(+), 2 deletions(-)
create mode 100644 src/patches/zfs/0001-remove-reference-to-libudev.patch
diff --git a/src/Makefile b/src/Makefile
index a398ea1..053be5f 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -11,6 +11,8 @@ KERNEL_IMG=${BUILDDIR}/bzImage
INITRAMFS_IMG=${INITRAMFS_BUILDDIR}/initramfs.img
INITRAMFS_IMG_DBG=${INITRAMFS_BUILDDIR}/initramfs-debug.img
+ZFS_TOOLS=${BUILDDIR}/zfstools
+
CONFIG=config-base
RUST_SRC=$(wildcard ${SHIM_DIR}/**/*.rs) ${SHIM_DIR}/Cargo.toml
@@ -35,6 +37,10 @@ kernel.prepared: ${BUILDDIR}.prepared
touch $@
zfs.prepared: kernel.prepared
+ cd ${BUILDDIR}/${ZFSONLINUX_SUBMODULE}; \
+ for p in ../../patches/zfs/*.patch; do \
+ patch -Np1 < $$p; \
+ done
cd ${BUILDDIR}/${ZFSONLINUX_SUBMODULE}; \
sh autogen.sh && \
./configure \
@@ -51,7 +57,20 @@ ${KERNEL_IMG}: zfs.prepared
cd ${BUILDDIR}/${KERNEL_SUBMODULE}; $(MAKE)
mv ${BUILDDIR}/${KERNEL_SUBMODULE}/arch/x86/boot/bzImage ${KERNEL_IMG}
-${INITRAMFS_IMG}: ${BUILDDIR}.prepared ${RUST_SRC} build_initramfs.sh
+${ZFS_TOOLS}: zfs.prepared
+ cd ${BUILDDIR}/${ZFSONLINUX_SUBMODULE}; \
+ ./configure \
+ --bindir=/usr/bin \
+ --sbindir=/sbin \
+ --libdir=/lib/"$(DEB_HOST_MULTIARCH)" \
+ --with-zfsexecdir=/usr/lib/zfs-linux \
+ --disable-systemd \
+ --disable-pyzfs \
+ --with-config=user
+ # absolute path required for 'make install'
+ $(MAKE) -C ${BUILDDIR}/${ZFSONLINUX_SUBMODULE} install DESTDIR=${PWD}/${ZFS_TOOLS}
+
+${INITRAMFS_IMG}: ${BUILDDIR}.prepared ${RUST_SRC} build_initramfs.sh ${ZFS_TOOLS}
cd ${SHIM_DIR}; cargo build --release
sh build_initramfs.sh
diff --git a/src/build_initramfs.sh b/src/build_initramfs.sh
index c4ee95c..29eeedb 100755
--- a/src/build_initramfs.sh
+++ b/src/build_initramfs.sh
@@ -19,9 +19,10 @@ add_pkgs() {
LOCAL_DEPS=$(apt-rdepends -f Depends -s Depends "$pkg" | grep -v '^ ')
DEPS="$DEPS $LOCAL_DEPS"
done
- # debconf and gcc are unnecessary
+ # debconf and gcc are unnecessary, libboost-regex doesn't install on bullseye
DEPS=$(echo "$DEPS" |\
sed -E 's/debconf(-2\.0)?//' |\
+ sed -E 's/libboost-regex//' |\
sed -E 's/gcc-.{1,2}-base//')
apt-get download $DEPS
for deb in ./*.deb; do
@@ -47,8 +48,23 @@ add_pkgs "
libstdc++6:amd64 \
libssl1.1:amd64 \
libacl1:amd64 \
+ libblkid1:amd64 \
+ libuuid1:amd64 \
+ zlib1g:amd64 \
"
+
+# install custom ZFS tools (built without libudev)
+mkdir -p "$ROOT/sbin"
+cp -a ../zfstools/sbin/* "$ROOT/sbin/"
+cp -a ../zfstools/etc/* "$ROOT/etc/"
+cp -a ../zfstools/lib/* "$ROOT/lib/"
+cp -a ../zfstools/usr/* "$ROOT/usr/"
+
rm -rf ${ROOT:?}/usr/share # contains only docs and debian stuff
+rm -rf ${ROOT:?}/usr/local/include # header files
+rm -rf ${ROOT:?}/usr/local/share # mostly ZFS tests
+rm -f ${ROOT:?}/lib/x86_64-linux-gnu/*.a # static libraries
+
make_cpio "initramfs.img"
# add debug helpers for debug initramfs, packages from above are included too
@@ -56,6 +72,7 @@ add_pkgs "
util-linux:amd64 \
busybox-static:amd64 \
gdb:amd64 \
+ strace:amd64 \
"
# leave /usr/share here, it contains necessary stuff for gdb
make_cpio "initramfs-debug.img"
diff --git a/src/init-shim-rs/src/main.rs b/src/init-shim-rs/src/main.rs
index 641218f..62d7e99 100644
--- a/src/init-shim-rs/src/main.rs
+++ b/src/init-shim-rs/src/main.rs
@@ -6,6 +6,10 @@ use std::process::Command;
const URANDOM_MAJ: u64 = 1;
const URANDOM_MIN: u64 = 9;
+const ZFS_MAJ: u64 = 10;
+const ZFS_MIN: u64 = 249;
+const NULL_MAJ: u64 = 1;
+const NULL_MIN: u64 = 3;
/// Set up a somewhat normal linux userspace environment before starting the restore daemon, and
/// provide error messages to the user if doing so fails.
@@ -22,6 +26,12 @@ fn main() {
wrap_err("mknod /dev/urandom", || {
do_mknod("/dev/urandom", URANDOM_MAJ, URANDOM_MIN)
});
+ wrap_err("mknod /dev/zfs", || {
+ do_mknod("/dev/zfs", ZFS_MAJ, ZFS_MIN)
+ });
+ wrap_err("mknod /dev/null", || {
+ do_mknod("/dev/null", NULL_MAJ, NULL_MIN)
+ });
if let Err(err) = run_agetty() {
// not fatal
diff --git a/src/patches/zfs/0001-remove-reference-to-libudev.patch b/src/patches/zfs/0001-remove-reference-to-libudev.patch
new file mode 100644
index 0000000..467d9b5
--- /dev/null
+++ b/src/patches/zfs/0001-remove-reference-to-libudev.patch
@@ -0,0 +1,52 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: Stefan Reiter <s.reiter at proxmox.com>
+Date: Thu, 10 Jun 2021 10:50:22 +0200
+Subject: [PATCH] remove reference to libudev
+
+since there's no command line flag I can see...
+
+Signed-off-by: Stefan Reiter <s.reiter at proxmox.com>
+---
+ config/user-libudev.m4 | 17 -----------------
+ config/user.m4 | 1 -
+ 2 files changed, 18 deletions(-)
+ delete mode 100644 config/user-libudev.m4
+
+diff --git a/config/user-libudev.m4 b/config/user-libudev.m4
+deleted file mode 100644
+index 8c3c1d7e0..000000000
+--- a/config/user-libudev.m4
++++ /dev/null
+@@ -1,17 +0,0 @@
+-dnl #
+-dnl # Check for libudev - needed for vdev auto-online and auto-replace
+-dnl #
+-AC_DEFUN([ZFS_AC_CONFIG_USER_LIBUDEV], [
+- ZFS_AC_FIND_SYSTEM_LIBRARY(LIBUDEV, [libudev], [libudev.h], [], [udev], [], [user_libudev=yes], [user_libudev=no])
+-
+- AS_IF([test "x$user_libudev" = xyes], [
+- AX_SAVE_FLAGS
+-
+- CFLAGS="$CFLAGS $LIBUDEV_CFLAGS"
+- LIBS="$LIBUDEV_LIBS $LIBS"
+-
+- AC_CHECK_FUNCS([udev_device_get_is_initialized])
+-
+- AX_RESTORE_FLAGS
+- ])
+-])
+diff --git a/config/user.m4 b/config/user.m4
+index c22067551..1b6d3a24e 100644
+--- a/config/user.m4
++++ b/config/user.m4
+@@ -18,7 +18,6 @@ AC_DEFUN([ZFS_AC_CONFIG_USER], [
+ ZFS_AC_CONFIG_USER_LIBBLKID
+ ])
+ ZFS_AC_CONFIG_USER_LIBTIRPC
+- ZFS_AC_CONFIG_USER_LIBUDEV
+ ZFS_AC_CONFIG_USER_LIBCRYPTO
+ ZFS_AC_CONFIG_USER_LIBAIO
+ ZFS_AC_CONFIG_USER_CLOCK_GETTIME
+--
+2.30.2
+
--
2.30.2
More information about the pbs-devel
mailing list