Code Monkey home page Code Monkey logo

krun's Introduction

krun - run programs from your system in a microVM

krun allows you to run arbitrary programs from your system in a microVM. It's comprised of two small programs:

  • krun: links against libkrun to create the microVM.

  • krun-guest: acts as an entrypoint inside the microVM to set up the environment for running your program.

Using

Usage: krun [OPTIONS] COMMAND [COMMAND_ARGS...]
OPTIONS:
        -h    --help                Show help
              --net=NET_MODE        Set network mode
              --passt-socket=PATH   Instead of starting passt, connect to passt socket at PATHNET_MODE can be either TSI (default) or PASST

COMMAND:      the command you want to execute in the vm
COMMAND_ARGS: arguments of COMMAND

Running graphical applications

If sommelier is installed in your system, krun will use it to connect to the Wayland session on the hosts, allowing you to run graphical applications in the microVM.

GPU acceleration is also enabled on systems supporting DRM native context (freedreno, amdgpu, asahi).

Running x86/x86_64 on aarch64

If FEX-Emu is installed in your system, krun will configure binfmt_misc inside the microVM so x86/x86_64 programs can be run transparently on it.

Motivation

This tool is mainly intended to enable users to easily run programs designed for 4K-page systems on systems with a different page size, with Asahi Linux being the prime example of this use case.

Other potential use cases could be software isolation, accessing privileged kernel features (provided by the guest) or local testing.

krun's People

Contributors

slp avatar teohhanhui avatar asahilina avatar alyssarosenzweig avatar so5005 avatar

Stargazers

 avatar Chloe Pronovost avatar Yevhen Shymotiuk avatar Ben Wibking avatar Johan Hanses avatar jasites avatar Sergei Dolgov avatar Peter A. avatar  avatar baka-gourd avatar Elaina avatar Jesús Rubio avatar Cosmic avatar  avatar Song avatar Ahmed ElSamha' avatar Kingstom avatar Mickaël Malécot avatar Kainoa Kanter avatar Jezreel Maldonado avatar Neko Hz avatar  avatar Tsiry Sandratraina avatar Prajeethan avatar  avatar toni dy avatar  avatar Pau RE avatar Tuan Anh Tran avatar  avatar Luke Short avatar Slavianka Trump avatar  avatar Jiri Pospisil avatar Daenney avatar Kien Dang avatar Tristan Ross avatar Marcus Ramberg avatar Suraj avatar qb avatar Joe Maples  avatar ʞ-uɐʇsıɹʇ avatar Hongyu Shi avatar Alexey Orlenko avatar raizo avatar Yousaf Nabi avatar Eric Curtin avatar  avatar

Watchers

Hector Martin avatar  avatar  avatar Oto Petřík avatar

krun's Issues

CPU p-core detection should use capacity, not freq

Right now the code uses cpufreq/cpuinfo_max_freq. The correct way to identify different core types is the cpu_capacity file (/sys/devices/system/cpu/cpu3/cpu_capacity). This should be 1024 for p-cores, though it's probably safer to keep the current logic of taking the max number as the p-cores.

Locale not passed through

Outside the VM:

alyssa@blossom ~> locale
LANG=fr_CA.UTF-8
LC_CTYPE="fr_CA.UTF-8"
LC_NUMERIC=en_CA.UTF-8
LC_TIME=en_CA.UTF-8
LC_COLLATE="fr_CA.UTF-8"
LC_MONETARY=en_CA.UTF-8
LC_MESSAGES="fr_CA.UTF-8"
LC_PAPER=en_CA.UTF-8
LC_NAME="fr_CA.UTF-8"
LC_ADDRESS="fr_CA.UTF-8"
LC_TELEPHONE="fr_CA.UTF-8"
LC_MEASUREMENT=en_CA.UTF-8
LC_IDENTIFICATION="fr_CA.UTF-8"
LC_ALL=

Inside the VM:

alyssa@blossom ~ [1]> krun bash
...
alyssa@blossom:~$ locale
LANG=
LC_CTYPE="POSIX"
LC_NUMERIC="POSIX"
LC_TIME="POSIX"
LC_COLLATE="POSIX"
LC_MONETARY="POSIX"
LC_MESSAGES="POSIX"
LC_PAPER="POSIX"
LC_NAME="POSIX"
LC_ADDRESS="POSIX"
LC_TELEPHONE="POSIX"
LC_MEASUREMENT="POSIX"
LC_IDENTIFICATION="POSIX"
LC_ALL=

Incidentally this masked over FEX-Emu/FEX#4010 on Asahi, otherwise my French system would've hit that bug before the user did.

krun does not reap zombie processes

Zombie processes inside the VM never get reaped, I guess because init.krun doesn't do this. Although we obviously don't need a full-blown init system, it should at least do this.

VM crashes after suspend

If I open Steam and idle long enough for Plasma to autosuspend the machine (or at least turn off my monitor), when I unsuspend & turn the screen back on & unlock Plasma, the VM has crashed with

12sommelier: ../sommelier.cc:956: void sl_registry_remover(void*, wl_registry*, uint32_t): Assertion `0' failed.
(EE) failed to write to Xwayland fd: Broken pipe

Hopefully that's fixable..?
this is on a Mac Studio, not sure if reproducible on the laptops

krun ls fails due to operation not supported

$ RUST_LOG=debug krun ls /
[2024-05-30T01:48:38Z DEBUG krun::net] passing fd to passt fd=5
Error: Failed to configure net mode

Caused by:
    Operation not supported (os error 95)
No IPv4 nameserver available for DHCP
No IPv6 nameserver available for NDP/DHCPv6

Application window not visible

When launching a GUI application, the window fails to appear on the screen, though it does show up in the application bar. However, the application executes as expected, and the desired output is visible in the command line output:

Screencast_20240511_104554.webm

The issue persists regardless of what application and whether the application is launched directly or through FEXBash.

Interestingly, this problem is not present when compiling and running the legacy C version of krun.

DNS resolver woes

In the VM, my /etc/resolv.conf looks like this:

; generated by /usr/sbin/dhclient-script
nameserver 192.168.0.1

Which is bad, because that's my router's IP address... (And not what's sent as DNS servers via DHCP.)

Others have reported no Internet access in the VM, probably related to this.

If I understand correctly, I think that's why krunvm set nameserver 1.1.1.1 as the default:
https://github.com/containers/krunvm/blob/5494d84a66bee3b802a0392cf8d662158ac7287d/src/main.rs#L51

But that's also not a good solution as it'd break local domains and search domains among other things...

Cannot build with nix, libkrun.h not found

libkrun.h is not found, krun has this problem but not krunvm.

error: failed to run custom build command for `krun-sys v1.8.1 (/build/source/crates/krun-sys)`

Caused by:
  process didn't exit successfully: `/build/source/target/release/build/krun-sys-c928935194fd9ad3/build-script-build` (exit status: 101)
  --- stdout
  cargo::rerun-if-changed=wrapper.h
  cargo::rustc-link-lib=krun

  --- stderr
  wrapper.h:1:10: fatal error: 'libkrun.h' file not found
  thread 'main' panicked at crates/krun-sys/build.rs:11:10:
  Unable to generate bindings: ClangDiagnostic("wrapper.h:1:10: fatal error: 'libkrun.h' file not found\n")
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Derivation:

pkgs.rustPlatform.buildRustPackage rec {
  pname = "krun";
  version = "git+${src.rev}";

  src = pkgs.fetchFromGitHub {
    owner = "slp";
    repo = "krun";
    rev = "5a8542a5066bd1a4d8bad99236f05ea3ac687ef7";
    hash = "sha256-3w1JHqzpkF11+3yHN3yPu2dKdi4qXdO8HY+7ICugAZA=";
  };

  cargoHash = "sha256-dtj3TiszBBsMtlJaaIyTmCNAGZy/zuSGSK8OOTb5Xmg=";

  buildInputs = [
    libkrun
  ];

  cargoLock.lockFile = "${src}/Cargo.lock";
  env.LIBCLANG_PATH = "${pkgs.llvmPackages_latest.clang-unwrapped.lib}/lib/libclang.so";
}

sound sequencer is missing inside fexbash

Followed this guide and managed to install ableton live

After successful install I'm trying to run ableton, splash screen shows, init starts and then it fails due to error:

info:    Image count:  4
info:    Exclusive FS: 2
00e0:err:alsa:get_device_name_from_guid No devices found in registry?
00e0:err:alsa:get_device_name_from_guid No devices found in registry?
00e0:err:alsa:get_device_name_from_guid No devices found in registry?
ALSA lib pulse.c:242:(pulse_connect) PulseAudio: Unable to connect: Connection refused
ALSA lib pulse.c:242:(pulse_connect) PulseAudio: Unable to connect: Connection refused
ALSA lib seq_hw.c:528:(snd_seq_hw_open) open /dev/snd/seq failed: No such file or directory
00e0:err:winediag:MIDIMAP_drvOpen No software synthesizer midi port found, Midi sound output probably won't work.

I see that if I run aplaymidi -l inside vm I get

 Port    Client name                      Port name
 14:0    Midi Through                     Midi Through Port-0

But if I run it inside FEXBash I get same error when ableton fails

ALSA lib seq_hw.c:528:(snd_seq_hw_open) open /dev/snd/seq failed: No such file or directory
Cannot open sequencer - No such file or directory

krun ls fails due to system event

$ RUST_LOG=debug krun --net=TSI ls / 
[2024-05-30T01:48:08Z DEBUG krun] env vars env=["LD_LIBRARY_PATH=/nix/store/86zx04zbngd4skkrxfd5ndhx8f6ap24v-pipewire-1.0.6-jack/lib", "MESA_LOADER_DRIVER_OVERRIDE=asahi", "PATH=/run/wrappers/bin:/home/ross/.local/share/flatpak/exports/bin:/var/lib/flatpak/exports/bin:/home/ross/.nix-profile/bin:/nix/profile/bin:/home/ross/.local/state/nix/profile/bin:/etc/profiles/per-user/ross/bin:/nix/var/nix/profiles/default/bin:/run/current-system/sw/bin:/nix/store/5mal6aa0s9fxnqibmybkz19bxh8scig2-gcc-wrapper-13.2.0/bin:/nix/store/5pfllkhmmdrwi5z1da1009lx128kfbbq-binutils-wrapper-2.41/bin:/nix/store/xyg13851ggmvasxadqxk6l3cyqgaff2n-pciutils-3.12.0/bin:/nix/store/nppl7x028hckyrmba7q8w8pn0b7rf1kr-pkgconf-wrapper-2.1.1/bin", "RUST_LOG=debug"]
[2024-05-30T01:48:08Z INFO  vmm::linux::vstate] Guest memory starts at 0xfffe03c30000
[2024-05-30T01:48:08Z INFO  vmm::linux::vstate] Guest memory starts at 0xfffc03c30000
[2024-05-30T01:48:08Z DEBUG devices::virtio::gpu::device] virtio_gpu: set_shm_region
[2024-05-30T01:48:09Z ERROR vmm::linux::vstate] Unexpected exit reason on vcpu run: SystemEvent(2, [0])
[2024-05-30T01:48:09Z INFO  vmm] Vmm is stopping.

Issues with `/run` on NixOS

On NixOS, we use /run for many runtime things such as symlinking the current system state to /run/current-system. This means the system "installed" packages will not be accessible unless /run/current-system is available. We also have the OpenGL drivers symlinked to /run/opengl-driver. Without that symlink being available, GPU related access via Mesa is not possible. Since /run isn't shared to krun, this means system packages and OpenGL are both not available.

Possible solution is to check if NIXOS_SYSTEM is an env var set and to mount the value of it to /run/current-system. A similar solution could be done for OpenGL.

Change prompt to clarify the difference between contexts

Starting an interactive shell with krun can be confusing as it's not clear when you're still in the VM or you've exited to the host. To improve the UX, we should change the prompt (PS1) so users can easily differentiate between contexts.

Copy/paste in the VM seems broken

Not 100% sure if/how this is supposed to work. Noticed in Steam. Not a big deal (low priority versus #56) but definitely a paper cut worth writing down before I forget.

Setup documentation / `/dev/fuse: Permission denied`

How would one go about setting this up?

Obviously you need the devel packages for all the components, but where do you go from there?

I am currently trying to run an appimage inside krun but it lacks permission to access the fuse device/interface.

I'd be glad for any pointers.

Infinite loop on steam ran thru boxwine

When using box64 and the new wow64 version steam gets very close to letting you login but then crashes and retries it used to just show a black screen but using the env variable krun -e WINEDLLOVERRIDES=libglesv2.dll=d lets you see the steam logo

Create binfmt support files

After #23 gets merged, krun will be capable of acting as a binfmt interpreter for x86_64 binaries on aarch64 machines. We should create the binfmt support files, just qemu-user-static does, to package managers can install them on the host.

krun-server should outlive first command

(Continuing from #23 (comment))

With some real-world testing, it's entirely jarring behaviour from a user perspective.

Steps for reproduction:

  1. Launch krun FEXBash
  2. Launch krun FEXInterpreter steam
  3. exit from FEXBash

Expected result:
Steam should continue running.

Actual / observed behaviour:
Steam is killed abruptly.

Error: Connection reset by peer (os error 104)

I'm getting this error if I try to run krun a second time, i.e. trying to launch a command through an existing krun-server.

Do you have any clues what might be wrong? I haven't been able to get any useful output / logs.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.