Install scripts (hooks) of which extend and enhance the functionality of Libvirt Virtual Machines (VMs). Hooks may run at either VM start or stop, and/or be VM-specific. Develop your own, too!
- 1. Why?
- 2. Related Projects
- 3. Documentation
- 4. Download
- 5. Usage
- 6. Current Features
- 7. Planned Features
- 8. Credits
- 9. Disclaimer
- 10. Contact
- 11. References
Libvirt is a tool which manages guests (VMs) and the platforms which run those VMs (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 useful scripts for VMs.
To view other relevant projects, visit Codeberg or GitHub.
-
Download the
.zipfile:- Viewing from the top of the repository's (current) webpage, click the
drop-down icon:
···on Codeberg.<> Codeon GitHub.
- Click
Download ZIPand save. - Open the
.zipfile, then extract its contents.
- Viewing from the top of the repository's (current) webpage, click the
drop-down icon:
-
Clone the repository:
- Open a Command Line Interface (CLI) or Terminal.
- Open a console emulator (for Debian systems: Konsole).
- Linux only: Open an existing console: press
CTRL+ALT+F2,F3,F4,F5, orF6.- To return to the desktop, press
CTRL+ALT+F7. F1is reserved for debug output of the Linux kernel.F7is reserved for video output of the desktop environment.F8and above are unused.
- To return to the desktop, press
- Change your directory to your home folder or anywhere safe:
cd ~
- Clone the repository:
git clone https://www.codeberg.org/portellam/libvirt-hooksgit clone https://www.github.com/portellam/libvirt-hooks
- Open a Command Line Interface (CLI) or Terminal.
-
Open the CLI (see Download).
-
Go to the directory of where the cloned/extracted repository folder is:
cd name_of_parent_folder/libvirt-hooks// -
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.
-
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/.
- The installer will place Libvirt Hooks in
- Set CPU thread priority in CPU scheduler.
- Source
- Allocate Host RAM to pages for Guest(s).
- Documentation
- Source
- Isolate CPU threads from Host, to allocate to Guest(s).
- Documentation
- Prevent Host sleep if Guest is running.
- Documentation
- Sleep Guest at Host sleep.
- Stops
nosleepservice.
- Switch active monitor input at VM start.
- Source
- Hibernate Guest at Host shutdown.
- Stops
nosleepservice.
- Hibernate Guest at Host sleep.
- Stops
nosleepservice.
- 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).
Some of what you see here is directly inspired by others' work, from either the Arch Wiki or the Reddit forum.
Use at your own risk. As stated in this article, avoid recursion in your Hooks. This can lead to at worst a deadlock of the Host (and all Guests) or at best the failure of a single Guest to start.
Do you need help? Please visit the Issues page.
Calling libvirt functions from within a hook script. Hooks for Specific System Management - libvirt. Accessed June 14, 2024.
https://libvirt.org/hooks.html#calling-libvirt-functions-from-within-a-hook-script.
CPU Pinning. PCI passthrough via OVMF - ArchWiki. Accessed June 14, 2024.
https://wiki.archlinux.org/title/PCI_passthrough_via_OVMF#CPU_pinning.
Hooks for Specific System Management. libvirt. Accessed June 14, 2024.
https://libvirt.org/hooks.html.
Host lockup if Guest is left running during sleep. PCI passthrough via OVMF ArchWiki. Accessed June 14, 2024.
Huge memory pages. PCI passthrough via OVMF - ArchWiki. Accessed June 14, 2024.
https://wiki.archlinux.org/title/PCI_passthrough_via_OVMF#Huge_memory_pages.
PassthroughPOST/VFIO-Tools: A Collection of Tools and Scripts That Aim to MakePCI Passthrough a Little Easier. GitHub. Accessed June 14, 2024.
https://github.com/PassthroughPOST/VFIO-Tools.
PCI passthrough via OVMF. ArchWiki. Accessed June 14, 2024.
https://wiki.archlinux.org/title/PCI_passthrough_via_OVMF.
r/VFIO. Accessed June 14, 2024.
https://www.reddit.com/r/VFIO/.
VFIO - ‘Virtual Function I/O’ - The Linux Kernel Documentation. The linux kernel. Accessed June 14, 2024.
https://www.kernel.org/doc/html/latest/driver-api/vfio.html.