乐趣区

自学成才系列一multipass-安装篇

multipass 官网

https://multipass.run/

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


安装完成,查看版本:

$ multipass version
multipass  1.3.0+mac
multipassd 1.3.0+mac

创建虚拟机

$ multipass launch -n vm01 -c 4 -m 4G -d 40G
Creating vm01
Starting vm01
Waiting for initialization to complete
Launched: 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.img
launch failed: http and file based images are not supported

小插曲

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

原文地址: https://github.com/canonical/…

# 停用 multipassd
$ sudo 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,保存。

# 启动 multipassd
$ sudo launchctl load /Library/LaunchDaemons/com.canonical.multipassd.plist
退出移动版