| Crates.io | guestctl |
| lib.rs | guestctl |
| version | 0.3.0 |
| created_at | 2026-01-24 21:54:20.884178+00 |
| updated_at | 2026-01-24 21:54:20.884178+00 |
| description | Guest VM toolkit for disk inspection and manipulation |
| homepage | |
| repository | https://github.com/ssahani/guestctl |
| max_upload_size | |
| id | 2067581 |
| size | 2,570,038 |
A pure Rust toolkit for VM disk inspection and manipulation with beautiful emoji-enhanced output. Inspect VM disks in seconds without booting them. Designed to work seamlessly with hyper2kvm.
๐จ New: Beautiful terminal output with emojis and color coding makes VM inspection actually enjoyable!
Python Package (Recommended):
pip install guestctl
From Source:
git clone https://github.com/ssahani/guestkit
cd guestkit
cargo build --release
Inspect a VM disk:
guestctl inspect vm.qcow2
Output:
๐พ Block Devices
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โช /dev/sda 8589934592 bytes (8.59 GB)
๐ฅ๏ธ Operating Systems
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
๐ง Type: linux
๐ฆ Distribution: ubuntu
๐ท๏ธ Product: Ubuntu 22.04 LTS
๐ Hostname: webserver-prod
โก Init system: systemd
๐ป Language Runtimes
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
๐ python3
๐ข Node.js
๐ณ Container Runtimes
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
๐ณ Docker
Interactive mode:
guestctl interactive vm.qcow2
Python API:
from guestctl import Guestfs
with Guestfs() as g:
g.add_drive("disk.qcow2")
g.launch()
roots = g.inspect_os()
for root in roots:
print(f"OS: {g.inspect_get_distro(root)}")
users = g.inspect_users(root)
for user in users:
print(f"User: {user.username}")
# Install system dependencies (Fedora/RHEL)
sudo dnf install qemu-img
# From source
git clone https://github.com/ssahani/guestctl
cd guestctl
cargo build --release
cargo install --path .
GuestCtl is a powerful command-line tool for inspecting and manipulating VM disk images without mounting them. Features beautiful emoji-enhanced output with color coding for better readability.
Example - Inspect a VMware Photon OS disk (5 seconds):
sudo guestctl inspect photon.vmdk
Output:
๐พ Block Devices
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โช /dev/sda 8589934592 bytes (8.59 GB)
โข Read-only: yes
๐ Partitions
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
๐ฆ /dev/sda3
โข Size: 8574189056 bytes (8.57 GB)
๐ Filesystems
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
๐ง /dev/sda3 ext4
โข UUID: 311182bd-f262-4081-8a2d-56624799dbad
๐ฅ๏ธ Operating Systems
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
๐ง Type: linux
๐ฆ Distribution: photon
๐ท๏ธ Product: VMware Photon OS/Linux 5.0
๐ Hostname: photon-2e2948360ed5
๐ด Packages: rpm
โก Init system: systemd
๐พ Disk usage: 15.1% (5.15 TB used / 34.14 TB total)
๐ง Kernel: vmlinuz-6.1.10-11.ph5
Key Features:
Basic Operations:
# Inspect with beautiful output
sudo guestctl inspect photon.vmdk
# JSON output for scripting
sudo guestctl inspect --json ubuntu.qcow2 | jq '.operating_systems[0].distro'
# List filesystems
sudo guestctl filesystems ubuntu.qcow2
# List installed packages
sudo guestctl packages ubuntu.qcow2
# Read a file
sudo guestctl cat ubuntu.qcow2 /etc/hostname
# List directory contents
sudo guestctl list ubuntu.qcow2 /etc
# Extract a file
sudo guestctl extract ubuntu.qcow2 /etc/passwd ./passwd
Advanced Features:
# Basic inspection
guestctl inspect vm.qcow2
# JSON output for automation
guestctl inspect vm.qcow2 --output json | jq '.os.hostname'
# Security audit profile
guestctl inspect vm.qcow2 --profile security
# Migration planning profile
guestctl inspect vm.qcow2 --profile migration --output json
# Performance tuning profile
guestctl inspect vm.qcow2 --profile performance
# Compare two VMs
guestctl diff vm-before.qcow2 vm-after.qcow2
# Compare multiple VMs against baseline
guestctl compare baseline.qcow2 vm1.qcow2 vm2.qcow2 vm3.qcow2
# Export HTML report
guestctl inspect vm.qcow2 --export html --export-output report.html
# Export Markdown inventory
guestctl inspect vm.qcow2 --export markdown --export-output inventory.md
# Use caching for faster repeated inspections
guestctl inspect vm.qcow2 --cache # First run: ~30s, subsequent: <0.5s
# Batch inspect multiple VMs in parallel
guestctl inspect-batch *.qcow2 --parallel 4 --cache
# Cache management
guestctl cache-stats
guestctl cache-clear
Available Commands:
inspect - Comprehensive VM inspection with profilesdiff - Compare two disk imagescompare - Compare multiple VMs against baselineinspect-batch - Parallel batch inspectionlist - List files in disk imageextract - Extract files from disk imageexecute - Execute commands in guestbackup - Create tar backup from guestconvert - Convert disk image formatscreate - Create new disk imagecheck - Filesystem checkusage - Disk usage statisticsdetect - Detect disk image formatinfo - Disk image informationcache-stats - View cache statisticscache-clear - Clear inspection cacheversion - Show version informationFull Documentation: docs/CLI_GUIDE.md
use guestctl::guestfs::Guestfs;
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Create handle
let mut g = Guestfs::new()?;
// Add disk image (read-only)
g.add_drive_ro("/path/to/disk.qcow2")?;
// Launch (analyzes disk)
g.launch()?;
// Inspect OS
let roots = g.inspect_os()?;
for root in roots {
println!("Found OS root: {}", root);
println!(" Type: {}", g.inspect_get_type(&root)?);
println!(" Distro: {}", g.inspect_get_distro(&root)?);
println!(" Version: {}.{}",
g.inspect_get_major_version(&root)?,
g.inspect_get_minor_version(&root)?);
println!(" Hostname: {}", g.inspect_get_hostname(&root)?);
}
// List partitions
let partitions = g.list_partitions()?;
for part in partitions {
println!("Partition: {}", part);
println!(" Filesystem: {}", g.vfs_type(&part)?);
println!(" Label: {}", g.vfs_label(&part).unwrap_or_default());
}
// Cleanup
g.shutdown()?;
Ok(())
}
GuestCtl provides modern Rust patterns for better type safety and ergonomics:
use guestctl::guestfs::{Guestfs, FilesystemType, OsType, Distro};
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Builder pattern for configuration
let mut g = Guestfs::builder()
.add_drive_ro("/path/to/disk.qcow2")
.verbose(true)
.build_and_launch()?;
// Type-safe filesystem creation
g.mkfs("/dev/sda1")
.ext4() // Type-safe enum, not string!
.label("rootfs")
.blocksize(4096)
.create()?;
// Type-safe OS detection with pattern matching
for root in g.inspect_os()? {
let os_type = OsType::from_str(&g.inspect_get_type(&root)?);
match os_type {
OsType::Linux => {
let distro = Distro::from_str(&g.inspect_get_distro(&root)?);
// Smart methods on enums
if let Some(pkg_mgr) = distro.package_manager() {
println!("Package manager: {}", pkg_mgr); // "deb", "rpm", "pacman", etc.
}
// Exhaustive pattern matching
match distro {
Distro::Ubuntu | Distro::Debian => println!("Debian-based"),
Distro::Fedora | Distro::Rhel => println!("RPM-based"),
Distro::Archlinux => println!("Arch Linux"),
_ => println!("Other Linux"),
}
}
OsType::Windows => println!("Windows detected"),
_ => println!("Other OS"),
}
}
g.shutdown()?;
Ok(())
}
See docs/ERGONOMIC_API.md and docs/MIGRATION_GUIDE.md for details.
GuestCtl provides native Python bindings via PyO3 for seamless integration with Python workflows.
Installation:
# Quick build (recommended)
./build_python.sh
# Or manual build
python3 -m venv .venv
source .venv/bin/activate
pip install maturin
PYO3_USE_ABI3_FORWARD_COMPATIBILITY=1 maturin develop --features python-bindings
# Verify installation
python3 -c "import guestctl; print(guestctl.__version__)"
Basic Example:
from guestctl import Guestfs
# Create handle and configure
g = Guestfs()
g.add_drive_ro("/path/to/disk.qcow2")
g.launch()
# Inspect operating system
roots = g.inspect_os()
for root in roots:
print(f"OS Type: {g.inspect_get_type(root)}")
print(f"Distro: {g.inspect_get_distro(root)}")
print(f"Version: {g.inspect_get_major_version(root)}.{g.inspect_get_minor_version(root)}")
print(f"Hostname: {g.inspect_get_hostname(root)}")
# Mount and read files
mountpoints = g.inspect_get_mountpoints(root)
for mount_path, device in sorted(mountpoints, key=lambda x: len(x[0])):
g.mount_ro(device, mount_path)
if g.is_file("/etc/hostname"):
content = g.read_file("/etc/hostname")
print(f"Hostname from file: {content.decode('utf-8').strip()}")
# List installed packages
apps = g.inspect_list_applications(root)
print(f"Total packages: {len(apps)}")
# Cleanup
g.umount_all()
g.shutdown()
More Examples:
examples/python/comprehensive_example.py - Complete example demonstrating all featuresexamples/python/extract_files.py - File extraction from disk imagesexamples/python/archive_example.py - Archive operations (tar, tar.gz)examples/python/basic_inspection.py - OS detection and inspectionexamples/python/list_filesystems.py - Enumerate devices and partitionsexamples/python/mount_and_explore.py - Mount and read filesexamples/python/package_inspection.py - List installed packagesexamples/python/create_disk.py - Create new disk imagesexamples/python/test_bindings.py - Comprehensive test suiteFull Documentation:
docs/guides/PYTHON_BINDINGS.md - Comprehensive Python guidedocs/api/PYTHON_API_REFERENCE.md - Complete API reference with 100+ methodsdocs/status/PYTHON_BINDINGS_STATUS.md - Implementation status and build instructionsPython API Coverage:
guestctl/
โโโ Cargo.toml
โโโ README.md
โโโ ARCHITECTURE.md # Architecture documentation
โโโ GUESTFS_IMPLEMENTATION_STATUS.md # Implementation status (578 functions)
โโโ src/
โ โโโ lib.rs # Library entry point
โ โโโ core/ # Core utilities
โ โ โโโ error.rs # Error types
โ โ โโโ retry.rs # Retry logic
โ โ โโโ types.rs # Common types
โ โโโ disk/ # Disk operations (Pure Rust)
โ โ โโโ reader.rs # Disk image reader (magic byte detection)
โ โ โโโ partition.rs # MBR/GPT parser
โ โ โโโ filesystem.rs # Filesystem detection (ext4, NTFS, etc.)
โ โโโ guestfs/ # GuestFS-compatible API (486 functions)
โ โ โโโ handle.rs # Main handle (new/launch/shutdown)
โ โ โโโ inspect.rs # OS inspection (12 functions)
โ โ โโโ device.rs # Device operations (9 functions)
โ โ โโโ partition.rs # Partition operations (6 functions)
โ โ โโโ mount.rs # Mount operations (11 functions)
โ โ โโโ file_ops.rs # File operations (35+ functions)
โ โ โโโ lvm.rs # LVM operations (9 functions)
โ โ โโโ command.rs # Command execution (4 functions)
โ โ โโโ archive.rs # Archive operations (7 functions)
โ โ โโโ luks.rs # LUKS encryption (6 functions)
โ โ โโโ checksum.rs # Checksums and file content (9 functions)
โ โ โโโ filesystem.rs # Filesystem operations (8 functions)
โ โ โโโ utils.rs # File utilities (11 functions)
โ โ โโโ network.rs # Network configuration (7 functions)
โ โ โโโ package.rs # Package management (5 functions)
โ โ โโโ system.rs # System configuration (13 functions)
โ โ โโโ security.rs # Security operations (10 functions)
โ โ โโโ boot.rs # Boot configuration (10 functions)
โ โ โโโ disk_ops.rs # Advanced disk operations (12 functions)
โ โ โโโ service.rs # Service management (8 functions)
โ โ โโโ ssh.rs # SSH operations (10 functions)
โ โ โโโ part_mgmt.rs # Partition management (9 functions)
โ โ โโโ augeas.rs # Configuration editing (11 functions)
โ โ โโโ resize.rs # Filesystem resize (7 functions)
โ โ โโโ windows.rs # Windows operations (12 functions)
โ โ โโโ btrfs.rs # Btrfs operations (12 functions)
โ โ โโโ metadata.rs # File metadata (17 functions)
โ โ โโโ misc.rs # Miscellaneous utilities (22 functions)
โ โ โโโ xfs.rs # XFS operations (4 functions)
โ โ โโโ iso.rs # ISO operations (4 functions)
โ โ โโโ transfer.rs # Advanced file transfer (8 functions)
โ โ โโโ disk_mgmt.rs # Disk image management (10 functions)
โ โ โโโ internal.rs # Internal operations (16 functions)
โ โ โโโ ntfs.rs # NTFS operations (5 functions)
โ โ โโโ ext_ops.rs # Extended filesystem ops (11 functions)
โ โ โโโ glob_ops.rs # Glob operations (7 functions)
โ โ โโโ node_ops.rs # Node operations (10 functions)
โ โ โโโ md_ops.rs # MD/RAID operations (5 functions)
โ โ โโโ selinux_ops.rs # SELinux extended (4 functions)
โ โ โโโ cap_ops.rs # Capabilities (4 functions)
โ โ โโโ acl_ops.rs # ACL operations (8 functions)
โ โ โโโ hivex_ops.rs # Hivex operations (16 functions)
โ โ โโโ rsync_ops.rs # Rsync operations (2 functions)
โ โ โโโ syslinux_ops.rs # Syslinux operations (2 functions)
โ โ โโโ journal_ops.rs # Journal operations (11 functions)
โ โ โโโ inotify_ops.rs # Inotify operations (6 functions)
โ โ โโโ squashfs_ops.rs # SquashFS operations (3 functions)
โ โ โโโ yara_ops.rs # YARA operations (4 functions)
โ โ โโโ tsk_ops.rs # TSK operations (4 functions)
โ โ โโโ zfs_ops.rs # ZFS operations (10 functions)
โ โ โโโ ldm_ops.rs # LDM operations (8 functions)
โ โ โโโ mpath_ops.rs # Multipath operations (5 functions)
โ โ โโโ grub_ops.rs # GRUB operations (7 functions)
โ โ โโโ f2fs_ops.rs # F2FS operations (4 functions)
โ โ โโโ bcache_ops.rs # Bcache operations (5 functions)
โ โ โโโ dosfs_ops.rs # DOSFS operations (5 functions)
โ โ โโโ cpio_ops.rs # CPIO operations (3 functions)
โ โ โโโ nilfs_ops.rs # NILFS operations (4 functions)
โ โ โโโ ufs_ops.rs # UFS operations (3 functions)
โ โ โโโ inspect_enhanced.rs # Enhanced inspection with profiles
โ โ โโโ windows_registry.rs # Windows registry parsing
โ โโโ python.rs # Python bindings (PyO3, 100+ methods)
โ โโโ converters/ # Disk format converters
โ โ โโโ disk_converter.rs # qemu-img wrapper
โ โโโ cli/ # CLI implementation
โ โโโ commands.rs # CLI commands
โ โโโ profiles/ # Inspection profiles
โ โโโ exporters/ # HTML/Markdown exporters
โ โโโ formatters.rs # Output formatters
โ โโโ templates/ # Askama templates
โ โโโ diff.rs # VM comparison
โ โโโ cache.rs # Result caching
โโโ examples/ # Example programs
โ โโโ rust/
โ โ โโโ inspect_disk.rs
โ โ โโโ list_partitions.rs
โ โโโ python/ # Python examples
โ โโโ test_bindings.py # Comprehensive test suite
โ โโโ comprehensive_example.py # Full-featured example
โ โโโ archive_example.py # Archive operations
โ โโโ extract_files.py # File extraction
โ โโโ README.md # Python examples guide
โโโ docs/ # Documentation (organized)
โ โโโ README.md # Documentation index
โ โโโ guides/ # User guides
โ โโโ api/ # API documentation
โ โโโ architecture/ # Architecture docs
โ โโโ development/ # Contributor docs
โ โโโ testing/ # Testing docs
โ โโโ status/ # Implementation status
โ โโโ archive/ # Historical docs
โโโ pyproject.toml # Python package config
โโโ build_python.sh # Python build script
โโโ tests/ # Integration tests
๐ Complete documentation is organized in docs/
Quick Links:
See docs/README.md for complete documentation index.
See docs/architecture/ARCHITECTURE.md for detailed architecture documentation.
guestfs - GuestFS-Compatible API (115 functions)disk - Pure Rust Disk Operationscore - Core Utilities| Category | Functions | Status |
|---|---|---|
| Total APIs | 115 | 35 working, 80 API-defined |
| Lifecycle | 8 | โ Fully working |
| Inspection | 12 | โ Fully working |
| Device Ops | 9 | โ Fully working |
| Partition Ops | 6 | โ Fully working |
| Mount Ops | 11 | โ ๏ธ API-only (needs NBD) |
| File Ops | 35+ | โ ๏ธ API-only (needs FS parser) |
| LVM | 5 | โ ๏ธ API-only |
| Commands | 4 | โ ๏ธ API-only |
| Archives | 8 | โ ๏ธ API-only |
See GUESTFS_IMPLEMENTATION_STATUS.md for complete function implementation status.
See the examples/ directory for complete examples:
Run examples with:
cargo run --example convert_disk
cargo run --example detect_format
| Metric | Count | Percentage |
|---|---|---|
| LibGuestFS functions | 733 | 100% |
| GuestCtl APIs defined | 364 | 49.7% |
| Fully working | 349 | 47.6% |
| API-only (needs impl) | 15 | 2.0% |
See LIBGUESTFS_COMPARISON.md for:
Current: Pure Rust implementation without C dependencies
Working:
Planned (Phase 1):
guestctl is designed to work seamlessly with hyper2kvm:
use guestctl::guestfs::Guestfs;
// Simple, intuitive API
let mut g = Guestfs::new()?;
g.add_drive_ro("/path/to/disk.qcow2")?;
g.launch()?;
// Inspect VM
let roots = g.inspect_os()?;
for root in &roots {
println!("OS: {}", g.inspect_get_distro(root)?);
println!("Version: {}.{}",
g.inspect_get_major_version(root)?,
g.inspect_get_minor_version(root)?);
}
Benefits for hyper2kvm:
# Fedora/RHEL
sudo dnf install qemu-img
# Ubuntu/Debian
sudo apt install qemu-utils
# Arch Linux
sudo pacman -S qemu
Note: guestctl is a pure Rust implementation with no C library dependencies!
See Cargo.toml for complete list:
# Debug build
cargo build
# Release build (optimized)
cargo build --release
# Run tests
cargo test
# Run with logging
RUST_LOG=debug cargo run -- convert --source test.vmdk --output test.qcow2
Rust Tests:
# Unit tests
cargo test
# Integration tests
cargo test --test '*'
# With coverage
cargo tarpaulin --out Html
Python Tests:
# Install pytest (if not already installed)
pip install pytest
# Run Python bindings tests
pytest tests/test_python_bindings.py -v
# Run with test disk image
export GUESTKIT_TEST_IMAGE=/path/to/test.qcow2
pytest tests/test_python_bindings.py -v
Comprehensive Testing:
# Run all tests (Rust + Python)
cargo test --all-features
pytest tests/test_python_bindings.py -v
# Example Python integration test
cd examples/python
sudo python3 test_bindings.py /path/to/disk.img
Note on Permissions: Some tests require root access for mounting disk images.
See docs/testing/TESTING.md for complete testing documentation.
# Format code
cargo fmt
# Lint
cargo clippy
# Check documentation
cargo doc --no-deps --open
guestctl uses Cargo features for optional functionality:
disk-ops (default) - Disk operation utilitiesguest-inspect (default) - Guest OS inspectionpython-bindings (optional) - PyO3 Python bindings[dependencies]
guestctl = { version = "0.1", features = ["guest-inspect"] }
# With Python bindings
guestctl = { version = "0.1", features = ["python-bindings"] }
Build with Python bindings:
cargo build --features python-bindings
See GUESTFS_IMPLEMENTATION_STATUS.md for detailed implementation status.
Implement for 90% hyper2kvm compatibility:
Total: 30+ critical functions
Contributions are welcome! Please:
See CONTRIBUTING.md for detailed guidelines.
This project is licensed under the GNU Lesser General Public License v3.0 (LGPL-3.0).
See LICENSE for full license text.
examples/ directoryMade with โค๏ธ for reliable VM operations