portellam / libvirt-hooks

Install scripts (hooks) of which extend and enhance the functionality of Libvirt Virtual Machines (VMs). Hooks may be per VM, run at VM start or stop. Develop your own!

Home Page:https://old.reddit.com/r/vfio

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Libvirt Hooks

v1.0.0

Install scripts (hooks) of which extend and enhance the functionality of Libvirt Virtual Machines (VM). Hooks may run at either VM start or stop, and be VM-specific. Develop your own!

Latest release | View develop branch...

Related Projects:

Auto X.Org | Deploy VFIO | Generate Evdev | Guest Machine Guide | Power State Virtual Machine Manager

Table of Contents

Contents

Why?

Libvirt is a tool which manages VMs (Guests) and the platforms which run those Guests (example: QEMU, KVM). Libvirt includes logic to watch for specific events on the Host OS (ex: Linux) to allow for script execution.

Scripts are not available out-of-the-box in Libvirt, but are possible if you understand Linux, systemd, and a scripting language (ex: Bash, Python). This is not acceptable, should we as a community wish to attract newcomers to VMs, VFIO, and Linux as a whole.

To assist beginners (and others), included are some incredibly necessary scripts for Guests.

Download

  • To download this script, you may:

    • Download the ZIP file:

      1. Viewing from the top of the repository's (current) webpage, click the green <> Code drop-down icon.
      2. Click Download ZIP. Save this file.
      3. Open the .zip file, then extract its contents.
    • Clone the repository:

      1. Open a Command Line Interface (CLI).
      • Open a console emulator (for Debian systems: Konsole).
      • Open a existing console: press CTRL + ALT + F2, F3, F4, F5, or F6.
        • To return to the desktop, press CTRL + ALT + F7.
        • F1 is reserved for debug output of the Linux kernel.
        • F7 is reserved for video output of the desktop environment.
        • F8 and above are unused.
      1. Change your directory to your home folder or anywhere safe: cd ~
      2. Clone the repository: git clone https://www.github.com/portellam/libvirt-hooks
  • To make this script executable, you must:

    1. Open the CLI (see above).
    2. Go to the directory of where the cloned/extracted repository folder is: cd name_of_parent_folder/libvirt-hooks/
    3. Make the installer script file executable: chmod +x installer.bash
    • Do not make any other script files executable. The installer will perform this action.
    • Do not make any non-script file executable. This is not necessary and potentially dangerous.

Usage

installer.bash

  • From within project folder, execute: sudo bash installer.bash

    -h, --help               Print this help and exit.
    -i, --install            Install Libvirt Hooks to system.
    -u, --uninstall          Uninstall Libvirt Hooks from system.
    • The installer will place Libvirt Hooks in /etc/libvirt/hooks/.
    • The installer will place all project script files in /usr/local/bin/.

Current Features

References are either links to technical documentation or original sources.

1. cfscpu

  • Set CPU thread priority in CPU scheduler.6

2. hugepages

  • Allocate Host RAM to pages for Guest(s).2 6

3. isolcpu

  • Isolate CPU threads from Host, to allocate to Guest(s).3 6

4. nosleep

  • Prevent Host sleep if Guest is running.4

5. dosleep

  • Sleep Guest at Host sleep.4
  • Stops nosleep service.

Planned Features

References are either links to technical documentation or original sources.

1. ddcutil

  • Switch active monitor input at VM start.6

2. beforeoff-dohibernate

  • Hibernate Guest at Host shutdown.
  • Stops nosleep service.

3. dohibernate

  • Hibernate Guest at Host sleep.
  • Stops nosleep service.

4. virtual-nas

  • Share designated Host directory storage to Guest, on a file server over a Libvirt virtual network.
  • Helpful for circumstances where a given Guest cannot be trusted with direct access to storage.
    • For Read-Write permissions: ensure file system integrity.
    • For Read-only permissions: preventing malware transmission.
    • Virtualizing an untrusted or legacy OS (example: Windows XP).

References

Hook

Hooks article (Libvirt.org)

Hugepages

Arch Wiki article

isolcpu

Arch Wiki article

nosleep

libvirt-nosleep (Arch Wiki article)

VFIO

VFIO article (Linux kernel documentation)

VFIO-Tools

VFIO-Tools source (GitHub)

Credits

Some of what you see here is directly inspired by others' work, from either the Arch Wiki or the Reddit forum.

Disclaimer

Use at your own risk. As stated in this article, avoid recursion in your Hooks. This can lead to at worst a deadlock of all Guests or at best the failure of a single Guest to start.

Contact

Did you encounter a bug? Do you need help? Notice any dead links? Please contact by raising an issue with the project itself.

About

Install scripts (hooks) of which extend and enhance the functionality of Libvirt Virtual Machines (VMs). Hooks may be per VM, run at VM start or stop. Develop your own!

https://old.reddit.com/r/vfio

License:GNU General Public License v3.0


Languages

Language:Shell 100.0%