How to stop a virtual machine using 'qm stop' (with examples)

How to stop a virtual machine using 'qm stop' (with examples)

The qm stop command is a powerful utility within the Proxmox Virtual Environment (PVE) system, designed to manage virtual machines effectively. This command is primarily used to stop a virtual machine (VM) from running. It provides various options that allow users to control how the stopping process should be carried out — whether it needs to be immediate or considerate of potential storage and locking issues. Below, we explore different use cases of the qm stop command, each tailored for specific scenarios.

Use case 1: Stop a virtual machine immediately

Code:

qm stop VM_ID

Motivation:

In the fast-paced environment of IT operations, there are instances when a virtual machine needs to be stopped immediately, without any delay or waiting for processes to complete gracefully. This might be necessary in situations where the system resources need to be reallocated quickly, or when there is an urgent need to halt a VM due to operational priorities or unexpected behavior.

Explanation:

  • qm: This is the command line tool used in Proxmox for managing virtual machines.
  • stop: This argument tells qm to stop the specified virtual machine.
  • VM_ID: This is the unique identifier of the virtual machine you wish to stop. It must be replaced with the actual ID of the VM you want to manage.

Example Output:

Stopping VM 105
VM 105 stopped successfully.

Use case 2: Stop a virtual machine and wait for at most 10 seconds

Code:

qm stop --timeout 10 VM_ID

Motivation:

There are situations where you might want to give the virtual machine a chance to stop gracefully, but with a strict upper limit on how long it should take. This is particularly useful in maintaining service levels, ensuring that the shutdown process does not hang indefinitely and impact the overall system operations. By setting a timeout, you can prevent prolonged shutdowns while still allowing for a safer stop.

Explanation:

  • --timeout 10: This option specifies that the command should wait up to 10 seconds for the VM to stop gracefully. If the VM does not stop within this timeframe, the stopping process is forced to terminate the VM immediately.

Example Output:

Attempting graceful shutdown of VM 105 with a 10-second timeout.
VM 105 stopped successfully after 7 seconds.

Use case 3: Stop a virtual machine and skip lock (only root can use this option)

Code:

qm stop --skiplock true VM_ID

Motivation:

In scenarios where system locks might prevent a VM from stopping, especially during maintenance or troubleshooting, the ability to bypass these locks can be crucial. Although this option should be used with caution, it is necessary when dealing with stuck processes where normal shutdown is hindered by locks, and only root users can execute this operation to prevent unauthorized and potentially unsafe actions.

Explanation:

  • --skiplock true: This option tells qm to ignore any existing locks on the VM that may prevent it from stopping. It’s important to note that only the root user can use this option due to its potential impact on the system’s stability and security.

Example Output:

Warning: Skipping locks, proceeding to stop VM 105.
VM 105 stopped successfully.

Use case 4: Stop a virtual machine and don’t deactivate storage volumes

Code:

qm stop --keepActive true VM_ID

Motivation:

In environments where storage volumes are shared among multiple virtual machines or services, it may be desirable to keep these storage volumes active even after a VM is stopped. This can be particularly beneficial in clustered setups where storage needs to remain prepared for re-deployment or access by other systems, thus ensuring minimal disruption in service availability.

Explanation:

  • --keepActive true: This option ensures that storage volumes associated with the VM remain active and are not deactivated when the VM is stopped. This is critical for maintaining data accessibility and integrity across shared storage configurations.

Example Output:

Stopping VM 105 without deactivating storage volumes.
VM 105 stopped successfully. Storage volumes remain active.

Conclusion:

The qm stop command is a versatile tool for managing virtual machine states within Proxmox. Whether you need an immediate halt, a controlled shutdown with a timeout, or specialized scenarios requiring lock-skipping or maintaining active storage volumes, understanding these commands enhances your ability to manage virtual environments effectively and responsively. By choosing the appropriate options, you can ensure system stability and service continuity tailored to your operational needs.

Related Posts

How to Use the Command 'st-info' (with Examples)

How to Use the Command 'st-info' (with Examples)

The st-info command is a utility from the STLink toolkit, particularly useful for developers and engineers working with STM32 microcontrollers.

Read More
Managing Neovim Versions with the 'bob' Command (with examples)

Managing Neovim Versions with the 'bob' Command (with examples)

The ‘bob’ command is a powerful tool designed for developers and programmers who work with Neovim, a modernized version of the classic vim text editor.

Read More
How to use the command 'trdsql' (with examples)

How to use the command 'trdsql' (with examples)

trdsql is a powerful command-line tool that allows users to execute SQL queries on structured data files like CSV, LTSV, JSON, YAML, and TBLN.

Read More