Multipass - 轻量级跨平台Ubuntu虚拟机
一、概述
Multipass可以在Windows、MacOS、Linux等多平台创建轻量级Ubuntu虚拟机,它在各个操作系统平台中基于下面虚拟机平台创建:
- Windows:Hyper-V、VirtualBox
- MacOS:QEMU、HyperKit
- Linux:LXD
二、安装
1. 系统要求
- 需要安装
snap
包管理器
2. 安装方式
bash
sudo snap install multipass
三、虚拟机实例
1. 创建实例
第一步:查找可用的Ubuntu镜像和模板列表,使用镜像的别名和模板的名称来创建实例。
bash
multipass find
输出
Image Aliases Version Description
20.04 focal 20240710 Ubuntu 20.04 LTS
22.04 jammy 20240701 Ubuntu 22.04 LTS
24.04 noble,lts 20240710 Ubuntu 24.04 LTS
Blueprint Aliases Version Description
anbox-cloud-appliance latest Anbox Cloud Appliance
charm-dev latest A development and testing environment for charmers
docker 0.4 A Docker environment with Portainer and related tools
jellyfin latest Jellyfin is a Free Software Media System that puts you in control of managing and streaming your media.
minikube latest minikube is local Kubernetes
ros-noetic 0.1 A development and testing environment for ROS Noetic.
ros2-humble 0.1 A development and testing environment for ROS 2 Humble.
第二步:创建虚拟机实例。
bash
# 创建Ubuntu 22.04 LTS发行版实例
multipass launch jammy --cpus 4 --disk 20G --memory 8G --name linux
multipass launch jammy -c 4 -d 20G -m 8G -n linux
# 基于支持Docker环境的模板创建实例
multipass launch docker -n linux
参数 | 缩写 | 描述 |
---|---|---|
--cpus | -c | 分配CPU内核数,默认值:1 |
--disk | -d | 分配磁盘空间大小,默认值:5G,最小值:512M |
--memory | -m | 分配内存大小,默认值:1G,最小值:128M |
--name | -n | 指定实例名称 |
第三步:查看虚拟机信息。
bash
# 查看所有实例
multipass info
# 查看指定实例
multipass info linux
输出
Name: linux
State: Running
Snapshots: 0
IPv4: 192.168.65.3
Release: Ubuntu 22.04.4 LTS
Image hash: 76423945c97f (Ubuntu 22.04 LTS)
CPU(s): 1
Load: 0.00 0.02 0.00
Disk usage: 2.8GiB out of 4.8GiB
Memory usage: 155.3MiB out of 962.2MiB
Mounts: --
2. 修改实例
修改虚拟机实例配置,支持修改实例的CPU内核数、磁盘空间大小以及内存分配空间等配置。
bash
# 停止运行的实例
multipass stop linux
# 修改实例配置
# multipass set local.<instance-name>.cpus=4
multipass set local.linux.cpus=4
multipass set local.linux.disk=60G
multipass set local.linux.memory=7G
3. 管理实例
支持对虚拟机实例的启动、停止、重启以及进行虚拟机内部Shell的操作。
bash
# 启动实例
multipass start linux
# 停止实例
multipass stop linux
# 重启实例
multipass restart linux
# 进入实例内部Shell
multipass shell linux