On Debian systems, usually daemons are run automatically after their
installations; since we are upgrading the template, and installing
packages such as openssh, network-manager, etc, this may cause few
daemon to stay running during the virt-builder execution, causing it to
fail when shutting down (since e.g. /sysroot/dev would be in use).
As workaround, use a temporary policy-rc.d policy layer [1]: give an
error code so no daemon is ever started at any point of package upgrades
and installation. The script is removed at the very end of the
building, so the final image will spawn daemons just fine when booted.
[1]
https://people.debian.org/~hmh/invokerc.d-policyrc.d-specification.txt
---
p2v/virt-p2v-make-disk.in | 17 ++++++++++++++++-
1 file changed, 16 insertions(+), 1 deletion(-)
diff --git a/p2v/virt-p2v-make-disk.in b/p2v/virt-p2v-make-disk.in
index 6b82eaf..026d18b 100644
--- a/p2v/virt-p2v-make-disk.in
+++ b/p2v/virt-p2v-make-disk.in
@@ -189,6 +189,19 @@ EOF
;;
debian-*|ubuntu-*)
depsfile="$datadir/dependencies.debian"
+ cat > $tmpdir/policy-rc.d <<'EOF'
+#!/bin/sh
+# Avoid running daemons during the upgrade/installation
+exit 101
+EOF
+ chmod +x $tmpdir/policy-rc.d
+ # Double quotes because we want $tmpdir to be expanded:
+ preinstall_args="
+ --upload $tmpdir/policy-rc.d:/usr/sbin/policy-rc.d
+ "
+ final_args="
+ --delete /usr/sbin/policy-rc.d
+ "
;;
archlinux-*)
depsfile="$datadir/dependencies.archlinux"
@@ -229,6 +242,7 @@ virt-builder "$osversion"
\
$verbose_option \
--output "$output" \
$arch_option \
+ $preinstall_args \
--update \
--install "$install" \
--root-password password:p2v \
@@ -251,7 +265,8 @@ virt-builder "$osversion"
\
' \
$upload \
$extra_args \
- "${passthru[@]}"
+ "${passthru[@]}" \
+ $final_args
# We have to do this so the cleanup() handler runs.
exit $?
--
2.9.3