ARTICLE DETAIL

资讯详情

深耕郑州网站建设与运营推广的一线实战洞察。

Multipass 实例使用指南:从 shell 交互到生命周期管理

Multipass 实例使用指南:从 shell 交互到生命周期管理 虚拟化开发工具云原生【免费下载链接】multipassMultipass orchestrates virtual Ubuntu instances项目地址https://gitcode.com/gh_mirrors/mu/multipass点击查看免费下载导读本指南围绕 Multipass 的实例使用展开覆盖日常使用实例的两类核心操作进入实例内部交互打开 shell 会话、执行单条命令以及管理实例生命周期启动、挂起、停止与强制停止。你将掌握multipass shell、multipass exec、multipass start、multipass suspend、multipass stop等命令的完整用法包括多实例批量操作、--all选项、超时控制与工作目录映射等进阶细节并理解实例状态机Running / Stopped / Suspended 等与命令之间的对应关系。关联阅读Instance实例概念、Instance states实例状态、Command-line interfaceCLI 总览一、打开实例内部的 shell 会话在指定实例上打开 shell在已有的实例例如loving-duck上打开 shell 提示符运行multipass shell loving-duck输出类似于Welcome to Ubuntu 26.04 LTS (GNU/Linux 7.0.0-15-generic x86_64) * Documentation: https://docs.ubuntu.com * Management: https://landscape.canonical.com * Support: https://ubuntu.com/pro System information as of Tue Jun 9 15:54:32 UTC 2026 System load: 0.4 Processes: 123 Usage of /: 67.7% of 3.70GB Users logged in: 0 Memory usage: 29% IPv4 address for eth0: 10.97.0.49 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 ubuntuloving-duck:~$进入 shell 后即可在实例内部像使用普通 Ubuntu 主机一样运行任意命令。要结束会话使用logout、exit或快捷键Ctrl-D。shell 命令的关键行为自动启动如果实例loving-duck当前处于Stopped或Suspended状态shell命令会自动将其启动参见 shell 命令参考 中对 name 参数的说明If the instance is not running, an attempt is made to start it。默认目标为 primary 实例不给shell传任何参数时Multipass 会在 primary 实例上打开 shell如果 primary 实例尚不存在则会自动创建它。关于 primary 实例的机制详见 InstancePrimary instance 一节 与 Use the primary instance 指南。超时控制shell支持--timeout timeout选项单位为秒用于限定命令等待的最长时间。默认情况下实例启动与初始化阶段各被限制为 5 分钟详见 shell 命令参考。完整选项一览multipass help shell输出的完整选项Usage: multipass shell [options] [name] Open a shell prompt on the instance. Options: -h, --help Displays help on commandline options -v, --verbose Increase logging verbosity. Repeat the v in the short option for more detail. Maximum verbosity is obtained with 4 (or more) vs, i.e. -vvvv. --timeout timeout Maximum time, in seconds, to wait for the command to complete. Note that some background operations may continue beyond that. By default, instance startup and initialisation is limited to 5 minutes each. Arguments: name Name of the instance to open a shell on. If omitted, primary (the configured primary instance name) will be assumed. If the instance is not running, an attempt is made to start it (see start for more info).提示该能力在 Multipass GUI 中同样可用。二、在实例内部运行单条命令exec打开 shell 适合持续交互如果只需在实例内执行一条命令可以直接在宿主机上用multipass exec完成无需进入 shell。例如multipass exec loving-duck -- pwd返回/home/ubuntu其中/home/ubuntu就是pwd在loving-duck实例上执行的结果。--用于把multipass自身的选项与要执行的命令分隔开如果命令本身带有选项则必须放在--之后例如multipass exec primary -- uname -r输出示例4.15.0-48-generic标准输入输出与管道exec支持在宿主机与实例之间进行标准输入/输出的重定向与管道。例如把宿主机当前目录内容写入实例中的文件ls -la | multipass exec -n rich-zorilla -- bash -c cat save反过来把实例内 home 目录内容保存到宿主机文件multipass exec -n rich-zorilla -- bash -c ls -la | cat save更多关于命令解析、引号处理与重定向的细节参见 Multipass exec and shells 说明文档。指定命令的工作目录exec提供了三种方式决定命令在实例中的哪个目录执行显式指定目录使用--working-directory dir让命令在实例内的指定目录运行multipass exec arriving-pipefish --working-directory /home -- ls -a输出来自/home目录. .. ubuntu自动映射宿主目录默认行为Multipass 会先检查宿主机上当前所在目录是否被挂载到了实例中如果是命令就在实例中对应的挂载路径下执行。若当前目录未挂载则回退到实例默认目录。这是默认行为无需额外参数。强制使用实例默认目录使用--no-map-working-directory明确关闭目录映射命令直接在实例默认目录通常为/home/ubuntu中执行。完整选项一览multipass help exec输出的完整选项Usage: multipass exec [options] name [--] command Run a command on an instance Options: -h, --help Displays help on commandline options -v, --verbose Increase logging verbosity. Repeat the v in the short option for more detail. Maximum verbosity is obtained with 4 (or more) vs, i.e. -vvvv. -d, --working-directory dir Change to dir before execution -n, --no-map-working-directory Do not map the host execution path to a mounted path Arguments: name Name of instance to execute the command on command Command to execute on the instance三、启动实例start处于Stopped或Suspended状态的实例可以用multipass start启动multipass start loving-duck批量与全量启动一次启动多个实例只需在命令行中列出多个名字multipass start loving-duck devoted-lionfish sensible-shark使用--all选项一次性启动所有已有实例multipass start --all默认目标与自动创建不带任何选项时multipass start启动 primary 实例若 primary 实例不存在则会自动创建其行为等价于隐式执行launch参见 start 命令参考。例如无参执行multipass start会产生类似输出Configuring primary \ Launching primary | ...完整选项一览Usage: multipass start [options] [name ...] Start the named instances. Exits with return code 0 when the instances start, or with an error code if any fail to start. Options: -h, --help Displays help on commandline options -v, --verbose Increase logging verbosity. Repeat the v in the short option for more detail. Maximum verbosity is obtained with 4 (or more) vs, i.e. -vvvv. --all Start all instances --timeout timeout Maximum time, in seconds, to wait for the command to complete. Note that some background operations may continue beyond that. By default, instance startup and initialisation is limited to 5 minutes each. Arguments: name Names of instances to start. If omitted, and without the --all option, primary (the configured primary instance name) will be assumed. If primary does not exist but is included in a successful start command either implicitly or explicitly), it is launched automatically (see launch for more info).提示该操作在 Multipass GUI 中同样可用。四、挂起实例suspend挂起suspend会保存实例的内存与运行状态使其可以被快速恢复。挂起单个实例multipass suspend loving-duck一次挂起多个实例multipass suspend loving-duck devoted-lionfish sensible-shark使用--all挂起所有正在运行的实例multipass suspend --all注意只有处于Running状态的实例才能被挂起参见 suspend 命令参考 与 Instance states 文档。不带任何参数时suspend作用于 primary 实例——前提是它存在且正在运行。挂起后可用multipass list查看状态Name State IPv4 Image boisterous-tortoise Suspended -- Ubuntu 26.04 LTS之后可通过multipass start boisterous-tortoise从挂起状态恢复运行。完整选项一览Usage: multipass suspend [options] [name ...] Suspend the named instances, if running. Exits with return code 0 if successful. Options: -h, --help Display this help -v, --verbose Increase logging verbosity. Repeat the v in the short option for more detail. Maximum verbosity is obtained with 4 (or more) vs, i.e. -vvvv. --all Suspend all instances Arguments: name Names of instances to suspend. If omitted, and without the --all option, primary will be assumed.五、停止实例stop停止stop会让处于Running且非挂起状态的实例关机multipass stop loving-duck一次停止多个实例multipass stop loving-duck devoted-lionfish sensible-shark使用--all停止所有正在运行的实例multipass stop --all注意只有处于Running状态的实例才能被停止。不带任何参数时stop作用于 primary 实例——前提是它存在且正在运行。停止后的实例可以用multipass start重新启动。延迟关机与取消stop还支持延迟关机功能使用-t, --time time指定从现在起多少分钟后关闭实例让正在进行的进程有时间完成收尾使用-c, --cancel取消一个已排定的延迟关机。对应地Instance states 文档 中也有一个Delayed shutdown状态实例收到关机信号后会在指定延迟后停止。强制停止stop --force当multipass stop无法正常工作时可以加--force参数立即强制关机这在虚拟机处于无响应、未知或挂起suspended状态时尤其有用multipass stop --force--force也可以与--all组合使用强制停止所有实例该选项自 Multipass 1.14 起可用参见 stop 命令参考。stop --force 相当于直接拔掉物理机的电源线——它会立即终止所有计算活动。某些场景下这可能是必要的但存在导致数据丢失或损坏的风险请谨慎使用。提示该命令在 Multipass GUI 中同样可用。完整选项一览Usage: multipass stop [options] [name ...] Stop the named instances. Exits with return code 0 if successful. Options: -h, --help Displays help on commandline options -v, --verbose Increase logging verbosity. Repeat the v in the short option for more detail. Maximum verbosity is obtained with 4 (or more) vs, i.e. -vvvv. --all Stop all instances -t, --time time Time from now, in minutes, to delay shutdown of the instance -c, --cancel Cancel a pending delayed shutdown --force Force the instance to shut down immediately. Warning: This could potentially corrupt a running instance, so use with caution. Arguments: name Names of instances to stop. If omitted, and without the --all option, primary will be assumed.六、实例状态与命令的对应关系理解实例状态是正确使用上述命令的前提。Multipass 实例可能处于以下状态完整定义见 Instance states 文档状态说明可接受的典型操作Running实例正在运行可随时使用stop、suspend、restart、shell、execStopped已主动停止不占用资源可按需启动startStarting正在启动与初始化完成后转入Running—Restarting正在重启先停止再启动—Delayed shutdown已收到关机信号将在指定延迟后停止stop -c取消延迟Suspending正在挂起状态与内存将被保存—Suspended已挂起状态与内存已保存可从此状态恢复start、shell自动启动Deleted已标记删除可恢复或清除见删除/恢复相关命令Unknown状态无法确定或获取可能因意外错误导致stop --force由此可以归纳出几条实用规则start可将实例从Stopped或Suspended恢复到Runningshell也会在被调用时自动完成这一启动过程。stop与suspend仅对Running状态有效区别在于stop是彻底关机释放资源suspend则保存状态以便快速恢复。当实例处于Unknown或挂起等异常状态而无法正常关闭时stop --force是最后的强制手段。七、补充primary 实例与生命周期联动本指南中的多条命令都以 primary 实例为默认目标详见 Instance 文档的 Primary instance 一节不带参数的shell、start会打开/启动 primary 实例且若其不存在会自动创建不带参数的stop、suspend会停止/挂起 primary 实例若其存在且正在运行primary 实例的名称可通过设置项client.primary-name修改甚至可以借此将任意已有实例指定为 primary。一个典型的日常使用流程是multipass start # 启动必要时自动创建primary 实例 multipass shell # 在 primary 实例中打开交互 shell multipass exec primary -- ls -la # 或在实例内直接执行命令 multipass suspend # 暂时挂起保留现场 multipass start # 稍后恢复 multipass stop --all # 下班前统一关机这样便形成了「启动 → 交互/执行 → 挂起/恢复 → 停止」的完整实例使用闭环。延伸阅读Instance 概念与 primary 实例Instance states实例状态参考Instance name format实例命名规则shell 命令参考 / exec 命令参考start 命令参考 / stop 命令参考 / suspend 命令参考 / restart 命令参考Multipass exec 与 shell 的命令解析说明Manage instances 指南索引赞分享虚拟化开发工具云原生【免费下载链接】multipassMultipass orchestrates virtual Ubuntu instances项目地址https://gitcode.com/gh_mirrors/mu/multipass点击查看免费下载相关推荐从零到生产LibreChat 自托管部署避坑指南从零到生产LibreChat 自托管部署避坑指南 一台 2核4G 的机器加一条 docker compose 命令就能拥有完全自主可控的 AI 聊天入口。人工智能大模型AI 应用交互助手PojavLauncher终极性能优化指南移动设备运行Minecraft Java版帧率提升实战PojavLauncher终极性能优化指南移动设备运行Minecraft Java版帧率提升实战 PojavLauncher是一款基于Boardwalk技术的移动开发游戏开发Discord SDK实例生命周期管理Discord SDK实例生命周期管理 引言 在构建Discord嵌入式应用Embedded App时正确管理SDK实例的生命周期至关重要。一个Disco上一篇PsychEngine完整指南3步创建你的周五夜放克节奏游戏下一篇LOL Dataset数据集详解500对低光照/正常光照图像的结构与使用指南创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考
返回列表