multipass官网

https://multipass.run/

官网下载安装包安装, 过程不表

安装完成,查看版本:

$ multipass versionmultipass  1.3.0+macmultipassd 1.3.0+mac

创建虚拟机

$ multipass launch -n vm01 -c 4 -m 4G -d 40GCreating vm01Starting vm01Waiting for initialization to completeLaunched: vm01
-n, --name: 名称
-c, --cpus: cpu核心数, 默认: 1
-m, --mem: 内存大小, 默认: 1G
-d, --disk: 硬盘大小, 默认: 5G

1、安装时会去在线下载ubuntu最新安装包, 地址: https://cloud-images.ubuntu.c... 国内访问速度较为感人, 建议走梯子
比如: https://cloud-images.ubuntu.c...

2、目前MacOS还不支持http/file安装方式, 想先下载img文件再安装暂不可行。
launching local images is only currently supported on Linux
详见: https://github.com/canonical/...

$ multipass launch -n vm02 -c 4 -m 4G -d 40G file:///Users/zfj/Downloads/ubuntu-18.04-server-cloudimg-amd64.imglaunch failed: http and file based images are not supported

小插曲

创建时忘记指定cpu个数,导致默认1核,运行颇慢,修改cpu数:

原文地址: https://github.com/canonical/...
# 停用multipassdsudo launchctl unload /Library/LaunchDaemons/com.canonical.multipassd.plist
# 修改配置文件sudo vi '/var/root/Library/Application Support/multipassd/multipassd-vm-instances.json'

配置文件示例:

{    "primary": {    ...    },    "vm01": {        "deleted": false,        "disk_space": "42949672960",        "mac_addr": "52:54:00:26:63:fb",        "mem_size": "4294967296",        "metadata": {        },        "mounts": [            {                "gid_mappings": [                    {                        "host_gid": 20,                        "instance_gid": -1                    }                ],                "source_path": "/zfj/vm",                "target_path": "/shared",                "uid_mappings": [                    {                        "host_uid": 501,                        "instance_uid": -1                    }                ]            }        ],        "num_cores": 1,        "ssh_username": "ubuntu",        "state": 4    }}

修改num_cores这一项,改为想要的cpu核心数,比如:4,保存。

# 启动multipassdsudo launchctl load /Library/LaunchDaemons/com.canonical.multipassd.plist