Troubleshooting Guide
This guide helps you diagnose and resolve common issues with guestkit.
Table of Contents
- Installation Issues
- Runtime Errors
- Performance Issues
- Integration Issues
- Common Error Messages
- Debugging Tips
- Getting Help
Installation Issues
Compilation Fails with Missing Dependencies
Symptoms:
error: linking with `cc` failed
could not find qemu-img
Solution: Install system dependencies:
# Fedora/RHEL
sudo dnf install qemu-img cryptsetup lvm2
# Ubuntu/Debian
sudo apt-get install qemu-utils cryptsetup2 lvm2
# macOS (Homebrew)
brew install qemu
Cargo Build Fails with Disk Quota Error
Symptoms:
error: failed to write: Disk quota exceeded (os error 122)
Solution: Clean up target directory:
cargo clean
rm -rf target/
# Free up disk space, then rebuild
cargo build
Rust Version Too Old
Symptoms:
error: package requires rustc 1.70 or newer
Solution: Update Rust:
rustup update stable
rustc --version # Should be 1.70+
Runtime Errors
"Failed to launch" or "Not ready" Errors
Symptoms:
Error: NotReady("Must call launch() first")
Solution:
Ensure you call launch() after adding drives:
let mut g = Guestfs::new()?;
g.add_drive_ro("/path/to/disk.img")?;
g.launch()?; // ← Required before operations
Loop Device Issues
Symptoms:
Error: losetup failed: permission denied
Error: No free loop devices
Solutions:
-
Permission denied - Run with sudo:
sudo guestkit inspect disk.raw -
No free loop devices - Check and clean up:
# Check current loop deviceslosetup -a# Disconnect all unusedsudo losetup -D# Or increase max loop devicessudo modprobe loop max_loop=16 -
losetup not found - Install util-linux:
# Fedora/RHELsudo dnf install util-linux# Ubuntu/Debiansudo apt-get install util-linux
Note: Loop devices are used by default for RAW/IMG/ISO files. They're built into the Linux kernel and should always be available.
NBD Mount Fails
Symptoms:
Error: Failed to mount NBD device
Error: No available NBD devices found
Solution:
guestkit automatically loads the NBD module, but if that fails:
# Manual module load
sudo modprobe nbd max_part=16
# Make it persistent
echo "nbd" | sudo tee /etc/modules-load.d/nbd.conf
# Verify
lsmod | grep nbd
Clean up stuck NBD devices:
# Disconnect all NBD devices
for i in {0..15}; do
sudo qemu-nbd --disconnect /dev/nbd$i 2>/dev/null
done
# If still stuck, reboot
sudo reboot
Install qemu-nbd if missing:
# Fedora/RHEL
sudo dnf install qemu-img
# Ubuntu/Debian
sudo apt-get install qemu-utils
Note: NBD is only used for QCOW2/VMDK/VDI/VHD formats. Use RAW format for simpler setup.
Permission Denied Errors
Symptoms:
Error: Permission denied (os error 13)
Error: Operation not permitted
Solutions:
-
For NBD operations - Run with appropriate privileges:
sudo guestkit inspect disk.img -
For LUKS operations - Requires root or appropriate capabilities:
sudo guestkit ...# OR use capabilitiessudo setcap cap_sys_admin+ep target/release/guestkit -
For disk image access - Check file permissions:
chmod 644 disk.img# Or make readable by your usersudo chown $USER:$USER disk.img
LUKS Operations Fail
Symptoms:
Error: cryptsetup command failed
Error: LUKS device not found
Solutions:
-
Ensure cryptsetup is installed:
which cryptsetupsudo dnf install cryptsetup # or apt-get -
Verify LUKS header:
sudo cryptsetup luksDump /dev/sda1 -
Check device mapper:
ls -la /dev/mapper/
LVM Operations Fail
Symptoms:
Error: Volume group not found
Error: Logical volume not found
Solutions:
-
Scan for volume groups:
g.vgscan()?;g.vg_activate_all(true)?; -
Check LVM tools are installed:
which vgscan lvscan pvssudo dnf install lvm2 -
Verify volume groups:
sudo vgscansudo vgssudo lvs
File Not Found in Guest
Symptoms:
Error: exists: No such file or directory
Solutions:
-
Verify filesystem is mounted:
let mounts = g.mounts()?;println!("Mounted: {:?}", mounts); -
List available files:
let files = g.ls("/")?;println!("Available: {:?}", files); -
Check path is absolute:
// Goodg.cat("/etc/passwd")?;// Badg.cat("etc/passwd")?; // Missing leading /
Performance Issues
Slow Launch Time
Symptoms:
launch()takes many seconds- Startup is slower than expected
Solutions:
-
Reduce disk image size - Large images take longer to analyze:
# Use qcow2 instead of raw for better performanceguestkit convert disk.raw --output disk.qcow2 --format qcow2 -
Use read-only mode when possible:
g.add_drive_ro(path)?; // Faster than read-write -
Disable verbose logging in production:
g.set_verbose(false); // Default
Slow File Operations
Symptoms:
- File reads/writes are slow
- Archive operations take too long
Solutions:
-
Use bulk operations instead of many small operations:
// Good - one tar operationg.tar_out("/data", "/backup.tar")?;// Bad - many individual file copiesfor file in files {g.cp(&file, &dest)?; // Slow!} -
Minimize mount/unmount cycles:
// Good - mount once, do all operationsg.mount("/dev/sda1", "/")?;g.cat("/file1")?;g.cat("/file2")?;g.umount("/")?;// Bad - mount/unmount for each operationg.mount(...)?; g.cat("/file1")?; g.umount(...)?;g.mount(...)?; g.cat("/file2")?; g.umount(...)?; -
Use compressed formats for archives:
g.tar_out_opts("/data", "/backup.tar.gz", Some("gzip"))?;
High Memory Usage
Symptoms:
- Process uses excessive memory
- Out of memory errors
Solutions:
-
Process files in chunks instead of reading entirely:
// For large files, use streaming or downloadg.download("/large-file", "/tmp/output")?; -
Clean up between operations:
g.umount_all()?;g.shutdown()?;// Start fresh for next imagelet mut g = Guestfs::new()?; -
Limit concurrent operations in loops:
for disk in disks.chunks(5) { // Process 5 at a time// Process batch}
Integration Issues
Works Standalone but Fails in Production
Checklist:
- Are all system dependencies installed on production?
- Is NBD kernel module loaded?
- Are there sufficient permissions?
- Is there enough disk space for temporary files?
- Are ulimits appropriate (open files, processes)?
Verify environment:
# Check dependencies
which qemu-img cryptsetup
lsmod | grep nbd
# Check disk space
df -h /tmp
# Check limits
ulimit -a
Integration with Docker/Podman
Issue: NBD doesn't work in containers
Solution: Run with privileged mode and device access:
podman run --privileged \
--device /dev/nbd0 \
-v /path/to/images:/images:ro \
guestkit inspect /images/vm.qcow2
Better: Use container with pre-loaded NBD module:
FROM fedora:latest
RUN dnf install -y qemu-img
# Load NBD module on host before running container
COPY guestkit /usr/local/bin/
Integration with Kubernetes
Issue: Pods don't have NBD access
Solution: Use privileged pods or node-level NBD:
apiVersion: v1
kind: Pod
spec:
containers:
- name: guestkit
securityContext:
privileged: true
volumeMounts:
- name: dev-nbd
mountPath: /dev/nbd0
volumes:
- name: dev-nbd
hostPath:
path: /dev/nbd0
Common Error Messages
"Command failed: qemu-img"
Cause: qemu-img not installed or not in PATH
Solution:
# Install qemu-img
sudo dnf install qemu-img
# Verify
which qemu-img
qemu-img --version
"Device or resource busy"
Cause: NBD device still in use
Solution:
# Disconnect NBD devices
sudo qemu-nbd --disconnect /dev/nbd0
sudo qemu-nbd --disconnect /dev/nbd1
# Verify
cat /proc/partitions | grep nbd
"Invalid argument"
Cause: Incorrect parameters or corrupted disk image
Solutions:
-
Verify disk image is valid:
qemu-img check disk.qcow2qemu-img info disk.qcow2 -
Check parameter types:
// Ensure paths are strings, not PathBufg.add_drive_ro(path.to_str().unwrap())?;
"Filesystem check failed"
Cause: Filesystem errors on disk image
Solution:
# Manual fsck
sudo qemu-nbd -c /dev/nbd0 disk.qcow2
sudo fsck /dev/nbd0p1
sudo qemu-nbd -d /dev/nbd0
Debugging Tips
Enable Verbose Logging
let mut g = Guestfs::new()?;
g.set_verbose(true);
g.set_trace(true);
# Environment variable
export RUST_LOG=debug
guestkit inspect disk.img
Check What's Happening
// List all mounts
let mounts = g.mounts()?;
eprintln!("Currently mounted: {:?}", mounts);
// List all devices
let devices = g.list_devices()?;
eprintln!("Available devices: {:?}", devices);
// Get detailed stats
let stat = g.stat("/etc/passwd")?;
eprintln!("File stat: {:?}", stat);
Trace System Calls
# Use strace to see system calls
strace -e trace=open,stat,mount guestkit inspect disk.img 2>&1 | grep -v ENOENT
# Monitor qemu-nbd activity
ps aux | grep qemu-nbd
sudo lsof | grep nbd
Check Disk Image Integrity
# Check qcow2 image
qemu-img check -r all disk.qcow2
# Get detailed info
qemu-img info --backing-chain disk.qcow2
# Check for corruption
qemu-img dd if=disk.qcow2 of=/dev/null bs=1M
Test in Isolation
Create a minimal test case:
use guestkit::Guestfs;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut g = Guestfs::new()?;
// Minimal test disk
g.disk_create("/tmp/test.img", "raw", 100 * 1024 * 1024)?;
g.add_drive_ro("/tmp/test.img")?;
g.launch()?;
println!("Launch successful!");
g.shutdown()?;
Ok(())
}
Getting Help
Before Asking for Help
Gather this information:
-
Environment:
- OS and version:
uname -a - Rust version:
rustc --version - guestkit version:
guestkit version
- OS and version:
-
Error details:
- Full error message
- Stack trace if available
- Minimal reproduction case
-
System state:
- Loaded modules:
lsmod | grep nbd - Available devices:
ls -la /dev/nbd* - Disk image info:
qemu-img info disk.img
- Loaded modules:
Where to Get Help
-
GitHub Issues: https://github.com/zyvorai/guestkit/issues
- Search existing issues first
- Include environment info and error messages
- Provide minimal reproduction case
-
GitHub Discussions: For questions and troubleshooting
-
Documentation:
Reporting Bugs
Use this template:
**Environment:**
- OS: Fedora 39
- Rust: 1.75.0
- guestkit: 0.2.0
**Description:**
Brief description of the issue
**Steps to Reproduce:**
1. Command or code that triggers the issue
2. Expected behavior
3. Actual behavior
**Error Message:**
Full error message here
**Additional Context:**
Any other relevant information
Frequently Asked Questions
Q: Do I need root/sudo to use guestkit?
A: It depends:
- Read-only inspection: Usually no, unless NBD requires it
- NBD mounting: Often yes, or use capabilities
- LUKS operations: Yes, requires root
- LVM operations: Yes, requires root
Q: Can I use guestkit in Docker/containers?
A: Yes, but requires privileged mode or device access for NBD operations.
Q: Does guestkit work on Windows/macOS?
A: Currently Linux-only. Windows/macOS support is planned for future phases.
Q: How do I process multiple disk images efficiently?
A: Process in batches and reuse the Guestfs handle when possible:
for disk in disks.chunks(10) {
for d in disk {
process_disk(d)?;
}
// Brief pause between batches
std::thread::sleep(Duration::from_millis(100));
}
Q: What's the difference between guestkit and ?
A: guestkit is a pure Rust implementation inspired by :
- Pros: Memory safe, no C dependencies, better integration with Rust projects
- Cons: Not 100% API compatible, some features still in development
- Coverage: 76.8% of APIs implemented