这是用户在 2024-5-24 17:51 为 https://multipass.run/docs/configure-multipass-storage 保存的双语快照页面,由 沉浸式翻译 提供双语支持。了解如何保存?

Configure where Multipass stores external data
配置 Multipass 存储外部数据的位置

This document demonstrates how to configure the location where Multipass caches images, stores instances, and other user information. Configuring a new storage location can be useful, for example, if you need to free up storage space on your boot partition.
本文档演示如何配置 Multipass 缓存镜像、存储实例及其他用户信息的位置。若需释放启动分区的存储空间,配置新的存储位置将非常有用。

Contents: 内容:

Configuring a new storage location
配置新的存储位置

Caveats: 注意事项:

  • Multipass will not migrate your existing data, but this article explains how to do it manually. If you do not transfer the data, you will have to re-download any Ubuntu images and reinitialize any instances that you need.
    Multipass 不会迁移您的现有数据,但本文说明了如何手动操作。如果您不转移数据,则需要重新下载任何 Ubuntu 镜像并重新初始化所需的实例。
  • Subsequently, when uninstalling Multipass, the uninstaller will not remove data stored in custom locations, which must be deleted manually.
    随后,在卸载 Multipass 时,卸载程序不会移除存储在自定义位置的数据,这些数据必须手动删除。

Linux

First, stop the Multipass daemon:
首先,停止 Multipass 守护进程:

$ sudo snap stop multipass

Depending on where the new storage directory is located you will need to connect the respective interface to the Multipass snap. Because of snap confinement, this directory needs to located in either /home or one of the removable mounts points:
根据新存储目录的位置,您需要将相应的接口连接到 Multipass snap。由于 snap 的限制,此目录需要位于 /home 或其中一个可移动挂载点上:

$ sudo snap connect multipass:removable-media # for /mnt or /media
$ sudo snap connect multipass:all-home # for /home/*

Then, create the new directory in which Multipass will store its data:
然后,创建 Multipass 将用于存储其数据的新目录:

$ mkdir -p <path>
$ sudo chown root <path>

After that, create the override config file, replacing <path> with the absolute path of the directory created above.
之后,创建覆盖配置文件,将 <path> 替换为上述创建目录的绝对路径。

$ sudo mkdir /etc/systemd/system/snap.multipass.multipassd.service.d/
$ sudo tee /etc/systemd/system/snap.multipass.multipassd.service.d/override.conf <<EOF
[Service]
Environment=MULTIPASS_STORAGE=<path>
EOF
$ sudo systemctl daemon-reload

Now you can transfer the data from its original location to the new location:
现在您可以将数据从原始位置转移到新位置:

$ sudo cp -r /var/snap/multipass/common/data/multipassd <path>/data
$ sudo cp -r /var/snap/multipass/common/cache/multipassd <path>/cache

Finally, start the Multipass daemon:
最后,启动 Multipass 守护进程:

$ sudo snap start multipass

You can delete the original data at your discretion, to free up space:
您可自行决定删除原始数据,以腾出空间

$ sudo rm -rf /var/snap/multipass/common/data/multipassd
$ sudo rm -rf /var/snap/multipass/common/cache/multipassd

macOS

First, become root: 首先,成为 root

$ sudo su

Stop the Multipass daemon:
停止 Multipass 守护进程:

$ launchctl unload /Library/LaunchDaemons/com.canonical.multipassd.plist

Move your current data from its original location to <path>, replacing <path> with your custom location of choice:
将您当前的数据从原始位置迁移至 <path> ,将 <path> 替换为您选择的自定义位置:

$ mv /var/root/Library/Application\ Support/multipassd <path>

Make sure the multipassd directory is moved to <path>, not inside <path>.
确保将 multipassd 目录移动到 <path> ,而不是置于 <path> 内部。

Make a link from the original location to the absolute path of new location:
从原始位置创建链接到新位置的绝对路径:

$ ln -s <path> /var/root/Library/Application\ Support/multipassd

Finally, start the Multipass daemon:
最后,启动 Multipass 守护进程:

$ launchctl load /Library/LaunchDaemons/com.canonical.multipassd.plist

Windows

First, open an administrator privileged PowerShell prompt.
首先,打开一个具有管理员权限的 PowerShell 窗口。

Stop the Multipass daemon:
停止 Multipass 守护进程:

PS> Stop-Service Multipass

Create and set the new storage location, replacing <path> with the absolute path of your choice:
创建并设置新的存储位置,将 <path> 替换为您选择的绝对路径:

PS> New-Item -ItemType Directory -Path "<path>"
PS> Set-ItemProperty -Path "HKLM:System\CurrentControlSet\Control\Session Manager\Environment" -Name MULTIPASS_STORAGE -Value "<path>"

Now you can transfer the data from its original location to the new location:
现在您可以将数据从原始位置转移到新位置:

PS> Copy-Item -Path "C:\ProgramData\Multipass\*" -Destination "<path>" -Recurse

It is important to copy any existing data to the new location. This avoids unauthenticated client issues, permission issues, and in general, to have any previously created instances available.
将现有数据复制到新位置至关重要。这能避免未经授权的客户端问题、权限问题,并确保之前创建的所有实例可用。

Finally, start the Multipass daemon:
最后,启动 Multipass 守护进程:

PS> Start-Service Multipass

You can delete the original data at your discretion, to free up space:
您可自行决定删除原始数据,以腾出空间

PS> Remove-Item -Path "C:\ProgramData\Multipass\*" -Recurse

Reverting back to the default location
恢复到默认位置

Linux

Stop the Multipass daemon:
停止 Multipass 守护进程:

$ sudo snap stop multipass

Although not required, to make sure that Multipass does not have access to directories that it shouldn’t, disconnect the respective interface depending on where the custom storage location was set:
尽管非必需,为确保 Multipass 无法访问不应访问的目录,请根据自定义存储位置的设置,断开相应接口的连接:

$ sudo snap disconnect multipass:removable-media # for /mnt or /media
$ sudo snap disconnect multipass:all-home # for /home/*

Then, remove the override config file:
然后,移除覆盖配置文件:

$ sudo rm /etc/systemd/system/snap.multipass.multipassd.service.d/override.conf
$ sudo systemctl daemon-reload

Now you can transfer your data from the custom location back to its original location:
现在您可以将数据从自定义位置转移回其原始位置:

$ sudo cp -r <path>/data /var/snap/multipass/common/data/multipassd
$ sudo cp -r <path>/cache /var/snap/multipass/common/cache/multipassd

Finally, start the Multipass daemon:
最后,启动 Multipass 守护进程:

$ sudo snap start multipass

You can delete the data from the custom location at your discretion, to free up space:
您可根据需要从自定义位置删除数据,以腾出空间

$ sudo rm -rf <path>

macOS

First, become root: 首先,成为 root

$ sudo su

Stop the Multipass daemon:
停止 Multipass 守护进程:

$ launchctl unload /Library/LaunchDaemons/com.canonical.multipassd.plist

Remove the link pointing to your custom location:
移除指向您自定义位置的链接:

$ unlink /var/root/Library/Application\ Support/multipassd

Move the data from your custom location back to its original location:
将数据从您的自定义位置移回其原始位置:

$ mv <path> /var/root/Library/Application\ Support/multipassd

Finally, start the Multipass daemon:
最后,启动 Multipass 守护进程:

$ launchctl load /Library/LaunchDaemons/com.canonical.multipassd.plist

Windows

First, open an administrator privileged PowerShell prompt.
首先,打开一个具有管理员权限的 PowerShell 窗口。

Stop the Multipass daemon:
停止 Multipass 守护进程:

PS> Stop-Service Multipass

Remove the setting for the custom storage location:
移除自定义存储位置设置:

PS> Remove-ItemProperty -Path "HKLM:System\CurrentControlSet\Control\Session Manager\Environment" -Name MULTIPASS_STORAGE

Now you can transfer the data back to its original location:
现在您可以将数据传输回其原始位置:

PS> Copy-Item -Path "<path>\*" -Destination "C:\ProgramData\Multipass" -Recurse

Finally, start the Multipass daemon:
最后,启动 Multipass 守护进程:

PS> Start-Service Multipass

You can delete the data from the custom location at your discretion, to free up space:
您可根据需要从自定义位置删除数据,以腾出空间

PS> Remove-Item -Path "<path>" -Recurse

Let us know how this worked for you and what you’d like to see next!
告诉我们这对你效果如何,以及你接下来想看到什么内容!


Last updated 5 months ago.
最新更新于 5 个月前。

Help improve this document in the forum.
在论坛中帮助改进此文档。