ImageManager handles fetching and caching VM images from remote sources. It provides atomic downloads with SHA-256 verification to ensure image integrity.
Constructor
ImageManager(cache_dir=None, registry=None)
Initialize the image manager.
Override the default cache directory. If not specified, images are cached in
~/.smolvm/images/.Override the built-in image registry. Useful for testing or adding custom images. If not specified, uses the built-in registry.
Methods
list_available()
List names of all registered images.
Sorted list of image names available in the registry.
is_cached(name)
Check if an image is fully cached locally.
Image name to check.
True if both kernel and rootfs files exist in the cache, False otherwise.ValueError- If image name is empty
ensure_image(name)
Ensure an image is available locally, downloading if necessary.
If the image is already cached and passes SHA-256 verification, it is returned immediately. Otherwise, it is downloaded from the registry.
Downloads are atomic: files are written to a temporary location, SHA-256 verified, then renamed into place. This ensures a partial download never corrupts the cache.
Image name from the registry.
LocalImage instance with paths to kernel and rootfs.ValueError- If image name is emptyImageError- If the image is not in the registry, download fails, or checksum verification fails
Built-in Image Registry
SmolVM includes a registry of pre-built images from Firecracker’s official sources:hello
Minimal “hello world” image for testing.
- Kernel:
hello-vmlinux.bin - Rootfs:
hello-rootfs.ext4 - Size: ~10MB total
- Use case: Quick tests, examples
quickstart-x86_64
Ubuntu Bionic (18.04) image for x86_64 architecture.
- Kernel:
vmlinux.bin - Rootfs:
bionic.rootfs.ext4 - Size: ~100MB total
- Use case: General purpose Linux environment
Custom Image Registry
You can define custom images by providing your own registry:Cache Behavior
The image manager implements smart caching:- Cache hit: If both kernel and rootfs exist and pass SHA-256 verification, they are used immediately
- Cache miss: If files don’t exist, they are downloaded
- Checksum mismatch: If cached files fail verification, they are re-downloaded
- Atomic writes: Downloads write to temporary files and rename on success, preventing corruption
Error Handling
Related
- ImageSource - Define downloadable image metadata
- LocalImage - Locally-cached image representation
- ImageBuilder - Build custom images with SSH