A Python library to manage and test Raspberry Pi OS images with QEMU
Project description
PiVirt-Core
PiVirt-Core is a Python library and utility designed for managing and testing Raspberry Pi OS images using QEMU virtualization. It streamlines the process of working with Raspberry Pi environments in virtualized settings, making it ideal for CI/CD pipelines or local testing.
Why PiVirt-Core?
PiVirt-Core was created to address a significant limitation: it is impossible to pass all the necessary parameters to QEMU when using libvirt for Raspberry Pi emulation. This project solves that problem by offering a focused, customizable solution for managing Raspberry Pi OS virtual machines.
System Requirements
This implementation has been tested with 2023-05-03-raspios-bullseye-arm64-lite.
Required Packages
On Ubuntu 24.10 (Oracular), install the following packages:
sudo apt install python3.12-venv guestfish qemu-system-aarch64 qemu-utils
Installation
- Clone the Repository:
git clone https://github.com/federico-sauter/pivirt-core.git
cd pivirt-core
- Set Up a Virtual Environment:
python3 -m venv .venv
source .venv/bin/activate
- Install Dependencies:
pip install -r requirements.txt
- Install as Editable Package:
pip install -e .
Using PiVirt-Core
Preparing a Raspberry Pi OS Image with ssh acccess
Use the provided convenience script to download and prepare a Raspberry Pi OS image:
scripts/prepare_raspios_image.sh
This script:
- Downloads the specified version of Raspberry Pi OS.
- Configures it to re-enable the default username/password and enable SSH.
If you don't need ssh access, you can just download the RaspiOS image and use it as is.
VM Directory Structure
When a VM is created, a directory is set up under the specified --vm-dir. This directory contains all the metadata and resources needed to manage the VM:
- Disk Image: A copy of the provided image, resized to the next power of two in size.
- Metadata: A JSON file (vm_metadata.json) storing VM configuration (e.g., platform, paths).
- Logs:
- serial.log: Captures console output.
- error.log: Captures startup and runtime errors.
- Kernel and DTB Files: Extracted from the disk image using guestfish.
Example directory structure for a VM (test-vm):
{vm_dir}/
└── test-vm/
├── boot/
│ ├── kernel8.img # Kernel extracted from the disk image
│ └── bcm2711-rpi-4-b.dtb # Device tree blob
├── test-vm.img # Resized disk image
├── vm_metadata.json # Metadata file
├── serial.log # Serial output log
├── error.log # Error log
└── lockfile.lock # Lock file for concurrency control
Testing the Implementation
Follow these steps to test PiVirt-Core using the command-line utility scripts/test_vm_manager.py. Example Workflow
Register a New VM:
python scripts/test_vm_manager.py --vm-dir {vm_dir} \
--action register \
--vm-id test-vm \
--image-path {path_to_image} \
--platform rpi4
List Registered VMs:
python scripts/test_vm_manager.py --vm-dir {vm_dir} --action list
Start the VM:
python scripts/test_vm_manager.py --vm-dir {vm_dir} --action start --vm-id test-vm
Verify the VM is Running:
python scripts/test_vm_manager.py --vm-dir {vm_dir} --action list
Stop the VM:
python scripts/test_vm_manager.py --vm-dir {vm_dir} --action stop --vm-id test-vm
Clean Up:
python scripts/test_vm_manager.py --vm-dir {vm_dir} --action deregister --vm-id test-vm
Constraints and Notes
- Supported Platforms: Currently supports Raspberry Pi 3 and Raspberry Pi 4.
- QEMU Requirement: QEMU must be installed and available in your system PATH.
- Known Limitations:
- Works specifically with 2023-05-03-raspios-bullseye-arm64-lite and may not work with newer versions.
License
PiVirt-Core is dual-licensed under:
-
GNU Lesser General Public License v3.0 or later (LGPL-3.0-or-later) for open-source use. This allows you to use, modify, and distribute PiVirt-Core freely in open-source and proprietary software, provided that modifications to the library itself are shared under LGPL terms.
-
Commercial License for proprietary use. For users who wish to integrate PiVirt-Core into proprietary systems without adhering to LGPL terms (e.g., keeping modifications private), a commercial license is available.
Contact for Commercial Licensing
If you are interested in a commercial license, please contact: Email: pivirt@pm.me
Donations
If you find PiVirt-Core useful and would like to support its development, consider donating via PayPal. Every contribution helps us improve and maintain the project!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pivirt_core-1.0.0.tar.gz.
File metadata
- Download URL: pivirt_core-1.0.0.tar.gz
- Upload date:
- Size: 14.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
411b01ab3e17ba1819f4dc18b554de604df189e0234aaaccd637d026f80e1178
|
|
| MD5 |
92367b990242c96137e0986b32a4ab78
|
|
| BLAKE2b-256 |
e3e64a9149492b22e8dd2d699c9fcce8d58320fce828fe97b9abcd4ec1f666bd
|
File details
Details for the file pivirt_core-1.0.0-py3-none-any.whl.
File metadata
- Download URL: pivirt_core-1.0.0-py3-none-any.whl
- Upload date:
- Size: 15.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ebb5acbd9c97bbabf423372c840e2b85eea5ee51c385a97fc34bc8ca04eb17c8
|
|
| MD5 |
cc5c263752cb6c3e0612a837db561e56
|
|
| BLAKE2b-256 |
20fd60ff43930aa9fd0a7c2b8ddc4e9a22687d38291a3cb65ff09cb311793203
|