diff --git a/src/commands/create/domain.rs b/src/commands/create/domain.rs index fbe2887..06d9bf8 100644 --- a/src/commands/create/domain.rs +++ b/src/commands/create/domain.rs @@ -35,10 +35,19 @@ fn generate( .perform_indent(true) .create_writer(File::create(path.as_ref())?); - s(&mut w, "domain", &[("type", "kvm")], |w| { + let has_kvm = Utf8Path::new("/dev/kvm").exists(); + let domain_type = if has_kvm { "kvm" } else { "qemu" }; + + s(&mut w, "domain", &[("type", domain_type)], |w| { st(w, "name", &[], "domain")?; - se(w, "cpu", &[("mode", "host-passthrough")])?; + let cpu_mode = if has_kvm { + "host-passthrough" + } else { + "host-model" + }; + se(w, "cpu", &[("mode", cpu_mode)])?; + let vcpus = get_vcpu_count(spec).to_string(); if let Some(cpu_set) = get_cpu_set(spec) { st(w, "vcpu", &[("cpuset", cpu_set.as_str())], vcpus.as_str())?; diff --git a/src/commands/create/mod.rs b/src/commands/create/mod.rs index 50f605a..0a1bb31 100644 --- a/src/commands/create/mod.rs +++ b/src/commands/create/mod.rs @@ -526,8 +526,10 @@ fn set_up_extra_container_mounts_and_devices(spec: &mut oci_spec::runtime::Spec) .unwrap(), ); - add_bind_mount(spec, "/dev/kvm"); - add_char_dev(spec, "/dev/kvm")?; + if Utf8Path::new("/dev/kvm").exists() { + add_bind_mount(spec, "/dev/kvm"); + add_char_dev(spec, "/dev/kvm")?; + } // in case user sets up VFIO passthrough by overriding the libvirt XML for entry in fs::read_dir("/dev/vfio")? {