How to use the command 'qm sendkey' (with examples)
The qm sendkey
command is utilized within the Proxmox Virtual Environment to send specific keystroke events directly to a running virtual machine (VM). This function is particularly useful when there is a need to interact with the VM’s graphical console, such as sending special keyboard shortcuts or when input through other means is impractical. It enables administrators to automate tasks or troubleshoot VMs without requiring direct access to the machine’s console.
Use case 1: Send the specified key event to a specific virtual machine
Code:
qm sendkey 101 ctrl-alt-delete
Motivation:
Imagine an administrator needs to restart a virtual machine that has become unresponsive to typical commands issued through the hypervisor interface. By simulating the “Ctrl-Alt-Delete” key combination directly to the VM, the administrator can attempt to reboot or trigger other mechanisms within the VM to regain control. This method can save time and resources by potentially avoiding the need for a more forceful reboot.
Explanation:
qm
: This is the command-line tool used to interact with QEMU VMs in Proxmox.sendkey
: This action specification indicates the desire to send a key event to a VM.101
: This represents the unique identifier for the VM to which the key event will be sent. Each VM in Proxmox has a distinct ID to designate specific machines within the environment.ctrl-alt-delete
: The actual keystroke sequence to emulate within the VM. This sequence is often used for various purposes such as initiating a soft reset or bringing up the Task Manager in Windows environments.
Example output:
Executing the command may not produce visible output in the terminal. Instead, the VM specified by ID “101” should respond as though “Ctrl-Alt-Delete” was pressed on a physical keyboard connected to it. The VM console may show signs of rebooting, logging out users, or bringing up a relevant system dialog, depending on its configuration.
Use case 2: Allow root user to send key event and ignore locks
Code:
qm sendkey --skiplock true 102 ctrl-esc
Motivation:
In certain situations, there could be VM operations or transactions that create a lock, preventing typical commands from being executed directly. Using --skiplock
, an administrator with root access can bypass these locks to perform essential operations, such as unlocking a VM in stuck states or accessing critical functions that a lock is holding up. This can be crucial in minimizing downtime or data loss scenarios.
Explanation:
qm
: Again, this is the tool for handling virtual machines via the command line in Proxmox.sendkey
: Indicates the purpose of this command is to deliver a key sequence to a VM.--skiplock true
: This flag option tells the system to bypass any existing locks on the VM, allowing the command to execute regardless of current lock states. It is a powerful option usually reserved for root-level interventions.102
: This is the VM ID for the target machine where the key press event will occur. Each VM is assigned a unique numeric identifier for management purposes.ctrl-esc
: The keystroke signal to be sent. In many systems, “Ctrl-Esc” opens the Start menu or brings certain UI elements into focus for quick access.
Example output:
Similar to the previous use case, executing this command may not yield a direct output in the terminal. However, VM ID “102” should react as though “Ctrl-Esc” was pressed, providing visual confirmation on the console by opening a menu or similar effect depending on the operating system and the current setup of the VM.
Conclusion:
The qm sendkey
command is a versatile tool for interacting with virtual machines in the Proxmox environment. By allowing administrators to send keystroke events directly to VMs, it facilitates operations ranging from routine task automation to urgent interventions in cases of system unresponsiveness. Whether employed in bypassing locks or performing standard commands, understanding and utilizing qm sendkey
effectively can significantly enhance the management and troubleshooting capacity within a virtualized setup.