multipass 轻量级的ubuntu虚拟机

1.multipass简介

Multipass 是一个轻量虚拟机管理器,是由 Ubuntu 运营公司 Canonical 所推出的开源项目。运行环境支持 Linux、Windows、macOS。在不同的操作系统上,使用的是不同的虚拟化技术。在 Linux 上使用的是 KVM、Window 上使用 Hyper-V、macOS 中使用 HyperKit 以最小开销运行VM,支持在笔记本模拟小型云。

同时,Multipass 提供了一个命令行界面来启动和管理 Linux 实例。下载一个全新的镜像需要几秒钟的时间,并且在几分钟内就可以启动并运行 VM。

2.INSTALL

进去官网 https://multipass.run/install
下载安装对应操作系统的版本,对于Windows Home Edition,无法使用Hyper-v,需要安装virtual box配合使用

3.使用

3.1查看可以使用的镜像

multipass find

Image                       Aliases           Version          Description
core                        core16            20200818         Ubuntu Core 16
core18                                        20211124         Ubuntu Core 18
core20                                        20230119         Ubuntu Core 20
core22                                        20230119         Ubuntu Core 22
20.04                       focal             20230811         Ubuntu 20.04 LTS
22.04                       jammy,lts         20230815         Ubuntu 22.04 LTS
23.04                       lunar             20230810         Ubuntu 23.04
appliance:adguard-home                        20200812         Ubuntu AdGuard Home Appliance
appliance:mosquitto                           20200812         Ubuntu Mosquitto Appliance
appliance:nextcloud                           20200812         Ubuntu Nextcloud Appliance
appliance:openhab                             20200812         Ubuntu openHAB Home Appliance
appliance:plexmediaserver                     20200812         Ubuntu Plex Media Server Appliance

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.

3.2启动虚拟机实例

multipass launch -n ubuntu -c 2 -m 2G -d 10G
-n 指定实例名称
-c 指定CPU核数
-m 指定内存
-d 指定磁盘容量

3.3查看虚拟机列表

multipass list

Name                    State             IPv4             Image
ubuntu                  Running           N/A              Ubuntu 22.04 LTS

3.4查看虚拟机信息

multipass info ubuntu

Name:           ubuntu
State:          Running
IPv4:           N/A
Release:        Ubuntu 22.04.3 LTS
Image hash:     870bd58b5c1e (Ubuntu 22.04 LTS)
CPU(s):         2
Load:           0.03 0.03 0.04
Disk usage:     1.5GiB out of 9.6GiB
Memory usage:   172.5MiB out of 1.9GiB
Mounts:         --

3.5外部操作虚拟机

multipass exec ubuntu pwd
使用exec命令,后面跟上实例名称,紧跟着是bash命令

3.6进入虚拟机

multipass shell ubuntu

Welcome to Ubuntu 22.04.3 LTS (GNU/Linux 5.15.0-79-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

  System information as of Sun Aug 20 21:17:37 CST 2023

  System load:  0.0               Processes:               99
  Usage of /:   15.2% of 9.51GB   Users logged in:         0
  Memory usage: 10%               IPv4 address for enp0s3: 10.0.2.15
  Swap usage:   0%


Expanded Security Maintenance for Applications is not enabled.

0 updates can be applied immediately.

Enable ESM Apps to receive additional future security updates.
See https://ubuntu.com/esm or run: sudo pro status


Last login: Sun Aug 20 21:15:27 2023 from 10.0.2.2
To run a command as administrator (user "root"), use "sudo <command>".
See "man sudo_root" for details.

ubuntu@ubuntu:~$

接下来的操作就和在ubuntu系统里面一样了。

3.7退出虚拟机

exit
命令行输出logout

3.8启动、停止、删除、释放实例

# 启动实例
multipass start vm01
# 停止实例
multipass stop vm01
# 删除实例(删除后,还会存在)
multipass delete vm01
# 释放实例(彻底删除)
multipass purge vm01

3.9传输文件

multipass transfer 主机文件 容器名:容器目录
将宿主机的文件传输到虚拟机里面去。

4.启动实例遇到的问题

launch failed: Could not generate a new UUID: Process failed to start: The system cannot find the file specified.
启动时失败,参考https://stackoverflow.com/questions/59012338/unable-to-launch-ubuntu18-04-on-virtualbox-verr-nem-vm-create-failed 解决

修改步骤

Disable Hyper-V (if it is available on your machine)
Enable "Virtual Machine platform"
Enable "Windows Hypervisor platform"
Disable "Windows Sandbox" (if available on your machine)
Open Poweshell command prompt as admin and then run followng command

bcdedit /set hypervisorlaunchtype off

Restart machine

原因是multipass使用的virtual box和windows下开启的hyper-v冲突了。

5.更多命令

参考官网文档 https://multipass.run/docs。

6.list failed: cannot connect to the multipass socket

在Windows11下
当我重启电脑后,发现要再次进入multipass实例,提示cannot connect to the multipass socket

很明显,multipass的服务进程没有开启,开启失败了,并且右键的start和stop是灰色无法点击的。
我尝试使用命令行执行multipassd命令开启multipass daemon进程,结果报错:无法访问配置文件,需要使用管理员权限。

那么接下来,使用管理员权限打开CMD,并且运行multipassd,然后就可以访问multipass了。

posted @ 2023-08-20 21:26  莱纳你坐啊  阅读(1403)  评论(0)    收藏  举报