🌏 閱讀中文版本
Multipass: Complete Guide to Lightweight Virtual Machine Management Tool
In the modern world of software development and system administration, virtualization technology plays an indispensable role. From traditional virtual machines (VMs) to modern containerization technologies like Docker, each technology has its unique advantages and applicable scenarios. This article will explore Multipass in depth—a lightweight VM management tool developed by Canonical Ltd.—including its operating principles, practical operations, comparisons with other virtualization technologies, and best practices.
What is Multipass?
Multipass is an open-source tool developed by Canonical, the parent company of Ubuntu, specifically designed to quickly create, manage, and deploy Ubuntu virtual machines locally. Its design philosophy is “one command, one virtual machine,” enabling developers to launch a fresh Ubuntu environment in seconds.
Core Features of Multipass
- Rapid Deployment: Uses cloud images to start VMs in seconds
- Cross-Platform Support: Unified command interface across Windows, macOS, and Linux
- Native Virtualization: Leverages built-in virtualization technologies (Hyper-V, HyperKit, KVM)
- Cloud Integration: Supports cloud-init configuration, simulating cloud environments
- Resource Management: Customizable CPU, memory, and disk space
- User-Friendly: Intuitive command-line interface with gentle learning curve
How Multipass Works
Multipass leverages underlying native virtualization technologies to run complete Linux operating system environments:
- Linux: Uses KVM (Kernel-based Virtual Machine)
- Windows: Uses Hyper-V
- macOS: Uses HyperKit (based on Hypervisor.framework)
Multipass automates the creation, configuration, and management of virtual machines, providing a simple command-line interface to perform operations like creating, starting, stopping, and deleting VMs.
Architecture Diagram
┌─────────────────────────────────────┐
│ Multipass CLI (Command Line) │
├─────────────────────────────────────┤
│ Multipass Daemon (Background) │
├─────────────────────────────────────┤
│ Hypervisor (KVM/Hyper-V/HyperKit) │
├─────────────────────────────────────┤
│ Ubuntu Virtual Machines │
└─────────────────────────────────────┘
Installing Multipass
Windows Installation
# Using Chocolatey
choco install multipass
# Or download installer
# https://multipass.run/download/windows
Note: Requires Hyper-V feature enabled (Windows 10 Pro/Enterprise/Education)
macOS Installation
# Using Homebrew
brew install --cask multipass
# Or download .pkg installer
# https://multipass.run/download/macos
Linux Installation
# Ubuntu/Debian
sudo snap install multipass
# Verify installation
multipass version
Basic Operations Guide
1. Creating Virtual Machines
# Create default VM (1 CPU, 1GB RAM, 5GB disk)
multipass launch --name my-vm
# Create custom-spec VM
multipass launch --name dev-vm
--cpus 2
--memory 4G
--disk 20G
# Specify Ubuntu version
multipass launch 22.04 --name ubuntu22
multipass launch 20.04 --name ubuntu20
2. Managing Virtual Machines
# List all VMs
multipass list
# Start VM
multipass start my-vm
# Stop VM
multipass stop my-vm
# Restart VM
multipass restart my-vm
# Delete VM
multipass delete my-vm
multipass purge # Permanent deletion
3. Accessing Virtual Machines
# Enter via shell
multipass shell my-vm
# Execute single command
multipass exec my-vm -- ls -la
# Execute multi-line commands
multipass exec my-vm -- bash << 'EOF'
sudo apt update
sudo apt install -y nginx
sudo systemctl status nginx
EOF
4. File Transfer
# Copy from local to VM
multipass transfer ./local-file.txt my-vm:/home/ubuntu/
# Copy from VM to local
multipass transfer my-vm:/home/ubuntu/remote-file.txt ./
# Mount local directory to VM
multipass mount ~/projects my-vm:/home/ubuntu/projects
# Unmount
multipass umount my-vm:/home/ubuntu/projects
5. View Information
# View VM detailed information
multipass info my-vm
# View all VM statuses
multipass list
# View available images
multipass find
Multipass vs Traditional VMs vs Docker In-Depth Comparison
| Feature | Multipass | Traditional VMs (VirtualBox/VMware) | Docker |
|---|---|---|---|
| Virtualization Technology | Native virtualization (KVM, Hyper-V, HyperKit) | Hardware virtualization, emulates entire hardware system | Container technology, shares host OS kernel |
| Startup Speed | Fast (5-10 seconds) | Slow (30-60 seconds) | Very fast (1-2 seconds) |
| Resource Isolation | High (hardware-level isolation) | High (hardware-level isolation) | Medium (process-level isolation) |
| Resource Consumption | Medium (runs complete OS, but optimized) | High (runs complete OS + emulated hardware) | Low (shares host resources) |
| Security | High (complete kernel isolation) | High (complete kernel isolation) | Medium (shared kernel potential risks) |
| Ease of Use | Very high (one-line command launch) | Medium (manual configuration required) | High (Dockerfile automation) |
| OS Support | Ubuntu only | Any OS | Linux-based images |
| Network Configuration | Auto-configured NAT | Manual configuration required | Built-in bridge/host networking |
| Storage Persistence | Built-in (virtual disk) | Built-in (virtual disk) | Requires volume mounting |
| Use Cases | Fast Ubuntu testing environments, CI/CD, local development | Complete OS environment needed, cross-platform testing | Microservice deployment, application containerization |
Practical Application Scenarios
Scenario 1: Quick Testing Environment
# Create test environment
multipass launch --name test-env
# Install testing tools
multipass exec test-env -- bash << 'EOF'
sudo apt update
sudo apt install -y python3-pip nodejs npm
pip3 install pytest
EOF
# Run tests
multipass exec test-env -- pytest /path/to/tests
# Delete after testing
multipass delete test-env
multipass purge
Scenario 2: Multi-Version Ubuntu Testing
# Run multiple Ubuntu versions simultaneously
multipass launch 20.04 --name u20
multipass launch 22.04 --name u22
multipass launch 24.04 --name u24
# Execute same script on all versions
for vm in u20 u22 u24; do
multipass exec $vm -- bash -c "lsb_release -a"
done
Scenario 3: Local Kubernetes Development
# Create K8s nodes
multipass launch --name k8s-master --cpus 2 --memory 4G
multipass launch --name k8s-worker1 --cpus 2 --memory 4G
multipass launch --name k8s-worker2 --cpus 2 --memory 4G
# Install kubeadm
multipass exec k8s-master -- bash << 'EOF'
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
sudo apt-add-repository "deb http://apt.kubernetes.io/ kubernetes-xenial main"
sudo apt update
sudo apt install -y kubeadm kubectl kubelet
EOF
Advanced Techniques
Using cloud-init for Auto-Configuration
# cloud-config.yaml
#cloud-config
users:
- name: developer
sudo: ALL=(ALL) NOPASSWD:ALL
ssh_authorized_keys:
- ssh-rsa AAAAB3N...
packages:
- git
- docker.io
- nodejs
runcmd:
- systemctl enable docker
- systemctl start docker
- usermod -aG docker developer
# Launch with cloud-init
multipass launch --name dev-vm --cloud-init cloud-config.yaml
Snapshots and Backups
# Create snapshot (requires stopped VM)
multipass stop my-vm
multipass snapshot my-vm --name snapshot1
# List snapshots
multipass snapshot list my-vm
# Restore snapshot
multipass restore my-vm --snapshot snapshot1
# Delete snapshot
multipass snapshot delete my-vm --snapshot snapshot1
Best Practices
1. Resource Management
- Configure CPU and memory based on actual needs (avoid over-allocation)
- Regularly clean unused VMs (
multipass delete+purge) - Use
multipass stoprather thandeleteto preserve environments
2. Network Configuration
- Use
multipass infoto view VM IP addresses - Default NAT networking sufficient for most development needs
- Use cloud-init configuration for fixed IPs if needed
3. Security Considerations
- Regularly update software in VMs (
sudo apt update && upgrade) - Don’t store sensitive data in VMs
- Use SSH keys rather than passwords for login
4. Development Workflow
- Use
multipass mountto mount project directories (avoid repeated transfers) - Create standardized cloud-init files for different projects
- Integrate into CI/CD pipelines for automated testing
Common Problem Solutions
Issue 1: Cannot Start Virtual Machine
# Check Multipass service status
multipass version
# Restart Multipass daemon (Linux)
sudo snap restart multipass
# Windows: Restart Multipass service
Get-Service Multipass | Restart-Service
# macOS: Restart Multipass
sudo launchctl unload /Library/LaunchDaemons/com.canonical.multipassd.plist
sudo launchctl load /Library/LaunchDaemons/com.canonical.multipassd.plist
Issue 2: Network Connection Problems
# Check VM IP
multipass info my-vm
# Test connection
ping
# Check internal VM network
multipass exec my-vm -- ip addr
multipass exec my-vm -- ping 8.8.8.8
Issue 3: Insufficient Disk Space
# Check disk usage
multipass exec my-vm -- df -h
# Clean apt cache
multipass exec my-vm -- sudo apt clean
# Remove unused packages
multipass exec my-vm -- sudo apt autoremove
Conclusion
Multipass stands out as a lightweight virtual machine management tool with its ability to rapidly deploy and manage Ubuntu virtual machines. It achieves a balance between ease of use and resource consumption, making it ideal for development and testing scenarios requiring complete operating system environments.
Choose Multipass When:
- ✅ Need to quickly create Ubuntu testing environments
- ✅ Local development requires complete Linux environment
- ✅ CI/CD pipeline needs clean testing environments
- ✅ Multi-version Ubuntu compatibility testing
- ✅ Learning Linux system administration
Choose Traditional VMs When:
- ✅ Need to run non-Ubuntu systems
- ✅ Need graphical interface (GUI)
- ✅ Complex network configuration requirements
Choose Docker When:
- ✅ Microservice architecture applications
- ✅ Application containerized deployment
- ✅ Ultimate resource efficiency requirements
Choosing which virtualization technology should be based on specific use cases, resource constraints, and security requirements. Multipass provides the perfect balance between traditional virtual machines and containers, making it an indispensable member of the modern developer’s toolkit.
Related Articles
- Ubuntu Server Auto-Update Complete Guide: Enterprise Strategy, Risk Control & Failure Recovery
- Build RHEL / Rocky Linux Training Environment on Mac: Virtualization Options, Installation Process, and Training Focus
- Deploy .NET Applications on Ubuntu: Complete Guide (English)
- Blue-Green and Canary Deployments: Modern System Deployment Strategies
- Timezone Configuration in Cloud Services: From VMs to Containers (English)