Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:**

Expand Down
98 changes: 98 additions & 0 deletions src/hyperlight_host/src/bin/hyperlight-check.rs
Original file line number Diff line number Diff line change
@@ -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
}