diff --git a/debian/changelog b/debian/changelog
index 970fe0c95..8a5a9db68 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -10,6 +10,7 @@ linux (4.19~rc8-1~exp1) UNRELEASED; urgency=medium
* debian/rules: Checksum only the source name and version from
debian/changelog
* Move generation of CONFIG_BUILD_SALT to gencontrol.py
+ * [x86] hyperv-daemons: Make all services conditional on device existence
[ Karsten Merker ]
* [riscv64] Build a kernel image and udebs for riscv64 (Closes: #908161)
diff --git a/debian/hyperv-daemons.hv-fcopy-daemon.init b/debian/hyperv-daemons.hv-fcopy-daemon.init
index 7ecfc2a25..aa124bb78 100755
--- a/debian/hyperv-daemons.hv-fcopy-daemon.init
+++ b/debian/hyperv-daemons.hv-fcopy-daemon.init
@@ -18,8 +18,7 @@ SCRIPTNAME=/etc/init.d/hyperv-daemons.hv-fcopy-daemon
# Exit if the package is not installed
[ -x "$DAEMON" ] || exit 0
-# Exit if we are not running under Hyper-V or the kernel device does not exist
-/lib/hyperv-daemons/check-hyperv || exit 0
+# Exit if the kernel device does not exist
[ -e "/dev/vmbus/hv_fcopy" ] || exit 0
# Load the VERBOSE setting and other rcS variables
diff --git a/debian/hyperv-daemons.hv-fcopy-daemon.service b/debian/hyperv-daemons.hv-fcopy-daemon.service
index 6aec2b388..6306b1d71 100644
--- a/debian/hyperv-daemons.hv-fcopy-daemon.service
+++ b/debian/hyperv-daemons.hv-fcopy-daemon.service
@@ -1,6 +1,5 @@
[Unit]
Description=Hyper-V file copy service (FCOPY) daemon
-ConditionVirtualization=microsoft
ConditionPathExists=/dev/vmbus/hv_fcopy
[Service]
diff --git a/debian/hyperv-daemons.hv-kvp-daemon.init b/debian/hyperv-daemons.hv-kvp-daemon.init
index 20a8117af..a03b02f10 100755
--- a/debian/hyperv-daemons.hv-kvp-daemon.init
+++ b/debian/hyperv-daemons.hv-kvp-daemon.init
@@ -18,8 +18,8 @@ SCRIPTNAME=/etc/init.d/hyperv-daemons.hv-kvp-daemon
# Exit if the package is not installed
[ -x "$DAEMON" ] || exit 0
-# Exit if we are not running under Hyper-V
-/lib/hyperv-daemons/check-hyperv || exit 0
+# Exit if the kernel device does not exist
+[ -e "/dev/vmbus/hv_kvp" ] || exit 0
# Load the VERBOSE setting and other rcS variables
. /lib/init/vars.sh
diff --git a/debian/hyperv-daemons.hv-kvp-daemon.service b/debian/hyperv-daemons.hv-kvp-daemon.service
index f6f6f0d29..953226d7d 100644
--- a/debian/hyperv-daemons.hv-kvp-daemon.service
+++ b/debian/hyperv-daemons.hv-kvp-daemon.service
@@ -1,6 +1,6 @@
[Unit]
Description=Hyper-V key-value pair (KVP) daemon
-ConditionVirtualization=microsoft
+ConditionPathExists=/dev/vmbus/hv_kvp
[Service]
ExecStart=/usr/sbin/hv_kvp_daemon -n
diff --git a/debian/hyperv-daemons.hv-vss-daemon.init b/debian/hyperv-daemons.hv-vss-daemon.init
index ec2df0a18..aa899b132 100755
--- a/debian/hyperv-daemons.hv-vss-daemon.init
+++ b/debian/hyperv-daemons.hv-vss-daemon.init
@@ -18,8 +18,8 @@ SCRIPTNAME=/etc/init.d/hyperv-daemons.hv-vss-daemon
# Exit if the package is not installed
[ -x "$DAEMON" ] || exit 0
-# Exit if we are not running under Hyper-V
-/lib/hyperv-daemons/check-hyperv || exit 0
+# Exit if the kernel device does not exist
+[ -e "/dev/vmbus/hv_vss" ] || exit 0
# Load the VERBOSE setting and other rcS variables
. /lib/init/vars.sh
diff --git a/debian/hyperv-daemons.hv-vss-daemon.service b/debian/hyperv-daemons.hv-vss-daemon.service
index 3e6534d55..e92da97e4 100644
--- a/debian/hyperv-daemons.hv-vss-daemon.service
+++ b/debian/hyperv-daemons.hv-vss-daemon.service
@@ -1,6 +1,6 @@
[Unit]
Description=Hyper-V volume shadow copy service (VSS) daemon
-ConditionVirtualization=microsoft
+ConditionPathExists=/dev/vmbus/hv_vss
[Service]
ExecStart=/usr/sbin/hv_vss_daemon -n
diff --git a/debian/rules.d/tools/hv/Makefile b/debian/rules.d/tools/hv/Makefile
index 3393517f5..8c563673b 100644
--- a/debian/rules.d/tools/hv/Makefile
+++ b/debian/rules.d/tools/hv/Makefile
@@ -14,9 +14,4 @@ installdir = /usr/sbin
include $(top_rulesdir)/Makefile.inc
-# Handle check-hyperv separately since it's installed in a different directory
-all-local: check-hyperv
-install-local:
- install -D -m755 check-hyperv '$(DESTDIR)/lib/hyperv-daemons/check-hyperv'
-
endif
diff --git a/debian/rules.d/tools/hv/check-hyperv.c b/debian/rules.d/tools/hv/check-hyperv.c
deleted file mode 100644
index 4d2b6f515..000000000
--- a/debian/rules.d/tools/hv/check-hyperv.c
+++ /dev/null
@@ -1,103 +0,0 @@
-/*
- * This program is derived from systemd.
- *
- * Copyright 2011 Lennart Poettering
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation; either version 2.1 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; If not, see .
- */
-
-#include
-#include
-#include
-
-#define streq(a, b) (!strcmp(a, b))
-#define ELEMENTSOF(a) (sizeof(a) / sizeof((a)[0]))
-
-enum {
- VIRTUALIZATION_NONE,
- VIRTUALIZATION_VM_OTHER,
- VIRTUALIZATION_MICROSOFT,
-};
-
-static int detect_vm_cpuid(void) {
-
- static const struct {
- const char *cpuid;
- int id;
- } cpuid_vendor_table[] = {
- /* http://msdn.microsoft.com/en-us/library/ff542428.aspx */
- { "Microsoft Hv", VIRTUALIZATION_MICROSOFT },
- };
-
- uint32_t eax, ecx;
- bool hypervisor;
-
- /* http://lwn.net/Articles/301888/ */
-
-#if defined (__i386__)
-#define REG_a "eax"
-#define REG_b "ebx"
-#elif defined (__amd64__)
-#define REG_a "rax"
-#define REG_b "rbx"
-#endif
-
- /* First detect whether there is a hypervisor */
- eax = 1;
- __asm__ __volatile__ (
- /* ebx/rbx is being used for PIC! */
- " push %%"REG_b" \n\t"
- " cpuid \n\t"
- " pop %%"REG_b" \n\t"
-
- : "=a" (eax), "=c" (ecx)
- : "0" (eax)
- );
-
- hypervisor = !!(ecx & 0x80000000U);
-
- if (hypervisor) {
- union {
- uint32_t sig32[3];
- char text[13];
- } sig = {};
- unsigned j;
-
- /* There is a hypervisor, see what it is */
- eax = 0x40000000U;
- __asm__ __volatile__ (
- /* ebx/rbx is being used for PIC! */
- " push %%"REG_b" \n\t"
- " cpuid \n\t"
- " mov %%ebx, %1 \n\t"
- " pop %%"REG_b" \n\t"
-
- : "=a" (eax), "=r" (sig.sig32[0]), "=c" (sig.sig32[1]), "=d" (sig.sig32[2])
- : "0" (eax)
- );
-
- for (j = 0; j < ELEMENTSOF(cpuid_vendor_table); j ++)
- if (streq(sig.text, cpuid_vendor_table[j].cpuid))
- return cpuid_vendor_table[j].id;
-
- return VIRTUALIZATION_VM_OTHER;
- }
-
- return VIRTUALIZATION_NONE;
-}
-
-int main(void)
-{
- return detect_vm_cpuid() != VIRTUALIZATION_MICROSOFT;
-}