How to use the command qm stop (with examples)
The qm stop command is used to stop a virtual machine in Proxmox Virtual Environment. By stopping a virtual machine, you can gracefully shut it down or forcefully terminate its operation. This command is useful for managing virtual machines and ensuring they are stopped correctly.
Use case 1: Stop a virtual machine immediately
Code:
qm stop VM_ID
Motivation: This use case is useful when you want to quickly stop a virtual machine without any delay.
Explanation: The “qm stop” command followed by the VM_ID parameter is used to immediately stop a virtual machine.
Example output:
# qm stop 100
Virtual machine '100' stopped
Use case 2: Stop a virtual machine and wait for at most 10 seconds
Code:
qm stop --timeout 10 VM_ID
Motivation: Sometimes, a virtual machine may take longer to stop due to various reasons. In such cases, you can use the “–timeout” option to specify a maximum wait time before forcefully terminating it.
Explanation: The “–timeout” option followed by a value in seconds is used to specify the maximum wait time for stopping a virtual machine. If the virtual machine does not stop within the specified time, it will be forcefully terminated.
Example output:
# qm stop --timeout 10 100
Virtual machine '100' stopped
Use case 3: Stop a virtual machine and skip lock
Code:
qm stop --skiplock true VM_ID
Motivation: By skipping the lock, you can stop a virtual machine even if it is currently locked by another process or user. This can be useful when troubleshooting or in situations where you need to stop the virtual machine regardless of its lock status.
Explanation: The “–skiplock” option followed by the value “true” is used to skip the lock and forcibly stop a virtual machine. Only the root user has the necessary privileges to use this option.
Example output:
# qm stop --skiplock true 100
Virtual machine '100' stopped
Use case 4: Stop a virtual machine and don’t deactivate storage volumes
Code:
qm stop --keepActive true VM_ID
Motivation: When stopping a virtual machine, the storage volumes associated with it are typically deactivated. However, in certain scenarios, you may want to keep the storage volumes active even after stopping the virtual machine. This can be useful when performing maintenance tasks or when you want to keep the storage volumes ready for immediate use.
Explanation: The “–keepActive” option followed by the value “true” is used to prevent the deactivation of storage volumes associated with a virtual machine when it is stopped.
Example output:
# qm stop --keepActive true 100
Virtual machine '100' stopped
Conclusion:
In this article, we explored different use cases of the qm stop command in Proxmox Virtual Environment. By understanding these examples, you can effectively stop virtual machines and manage their shutdown process. Whether you need immediate stopping, controlled termination, or skipping locks, the qm stop command offers flexibility and control over virtual machine management.