From 50f5962325510ac54f98c8afae0f22d140b53c36 Mon Sep 17 00:00:00 2001 From: Anurag Singh Date: Sun, 29 Nov 2026 13:19:41 +0530 Subject: [PATCH] Add hyperlight-check tool for hypervisor setup New users often hit NoHypervisorFound without an obvious cause. Add a small binary that reports the detected hypervisor, checks access to /dev/kvm and /dev/mshv on Linux, and prints the command that fixes a permission problem. It exits non-zero when no hypervisor is usable. Signed-off-by: Anurag Singh --- docs/getting-started.md | 10 +- .../src/bin/hyperlight-check.rs | 98 +++++++++++++++++++ 2 files changed, 107 insertions(+), 1 deletion(-) create mode 100644 src/hyperlight_host/src/bin/hyperlight-check.rs diff --git a/docs/getting-started.md b/docs/getting-started.md index 09c9e242a6..110e50ff89 100644 --- a/docs/getting-started.md +++ b/docs/getting-started.md @@ -129,7 +129,15 @@ count after restore = 1 ## Troubleshooting -If you get `Error: NoHypervisorFound`, check that your hypervisor device exists and is accessible: +If you get `Error: NoHypervisorFound`, check that your hypervisor device exists and is accessible. + +The `hyperlight-check` binary runs these checks for you and prints how to fix anything it finds: + +```sh +cargo run -p hyperlight-host --bin hyperlight-check +``` + +It exits with a non-zero status when no usable hypervisor is found. **Linux:** diff --git a/src/hyperlight_host/src/bin/hyperlight-check.rs b/src/hyperlight_host/src/bin/hyperlight-check.rs new file mode 100644 index 0000000000..c0a50c0656 --- /dev/null +++ b/src/hyperlight_host/src/bin/hyperlight-check.rs @@ -0,0 +1,98 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2025 The Hyperlight Authors. + +//! Check that this machine can run Hyperlight sandboxes. +//! +//! Prints the detected platform, whether Hyperlight can find a usable +//! hypervisor, and what to do when it cannot. + +use std::process::ExitCode; + +const GETTING_STARTED: &str = + "https://github.com/hyperlight-dev/hyperlight/blob/main/docs/getting-started.md"; + +fn main() -> ExitCode { + println!("hyperlight-check"); + println!( + "platform: {} {}", + std::env::consts::OS, + std::env::consts::ARCH + ); + + let available = platform_check(); + println!( + "hypervisor: {}", + if available { + "available" + } else { + "unavailable" + } + ); + + if !available { + println!(); + println!("See {GETTING_STARTED} for setup instructions."); + return ExitCode::FAILURE; + } + ExitCode::SUCCESS +} + +#[cfg(target_os = "linux")] +fn platform_check() -> bool { + let available = hyperlight_host::is_hypervisor_present(); + check_device("/dev/kvm", "kvm"); + check_device("/dev/mshv", "mshv"); + available +} + +#[cfg(target_os = "linux")] +fn check_device(path: &str, group: &str) { + let device = std::path::Path::new(path); + if !device.exists() { + println!("{path}: not present"); + return; + } + match std::fs::OpenOptions::new() + .read(true) + .write(true) + .open(device) + { + Ok(_) => println!("{path}: accessible"), + Err(err) => { + println!("{path}: not accessible ({err})"); + println!(" add your user to the {group} group, then log in again:"); + println!(" sudo usermod -aG {group} $USER"); + } + } +} + +#[cfg(target_os = "windows")] +fn platform_check() -> bool { + let available = hyperlight_host::is_hypervisor_present(); + if !available { + println!("Windows Hypervisor Platform is not available."); + println!("Enable Hyper-V and Windows Hypervisor Platform, then reboot."); + println!("Current feature state (Admin PowerShell):"); + println!( + " Get-WindowsOptionalFeature -Online | Where-Object {{$_.FeatureName -match 'Hyper-V|HypervisorPlatform|VirtualMachinePlatform'}}" + ); + } + available +} + +#[cfg(target_os = "macos")] +fn platform_check() -> bool { + let available = hyperlight_host::is_hypervisor_present(); + if !available { + println!("Hypervisor.framework is not available."); + println!("On Apple silicon this requires a recent macOS."); + println!("Nested virtualization is not available inside most VMs."); + } + available +} + +#[cfg(not(any(target_os = "linux", target_os = "windows", target_os = "macos")))] +fn platform_check() -> bool { + println!("Hyperlight is not supported on this platform."); + false +}