Proxmox vm's use the QEMU guest agent. The official documentation from Proxmox can be found here: https://pve.proxmox.com/wiki/Qemu-guest-agent
If this option is set, a new virtual serial device is shown to the vm, which will be accessed by the agent which will be installed in the guest os.
To set this option via cli use the following command:
qm set VMID --agent 1
Per default the qemu-guest-agent doesn't allow command execution. You will see the following error message, if you try it:
root@mypve:~# qm guest exec 101 /bin/ls Agent error: The command guest-exec has been disabled for this instance
Open the config file.
vi /etc/sysconfig/qemu-ga
Search for the blacklist line.
BLACKLIST_RPC=guest-file-open,guest-file-close,guest-file-read,guest-file-write,guest-file-seek,guest-file-flush,guest-exec,guest-exec-status
Remove guest-exec (and guest-exec-status for async exec calls).
BLACKLIST_RPC=guest-file-open,guest-file-close,guest-file-read,guest-file-write,guest-file-seek,guest-file-flush
Restart the agent.
systemctl restart qemu-guest-agent
qm guest exec <vmid> <command> <arg1> <arg2> ...
root@mypve:~# qm guest exec 101 /bin/ls -- "-la" "/etc/hosts" { "exitcode" : 0, "exited" : 1, "out-data" : "-rw-r--r--. 1 root root 158 Sep 10 2018 /etc/hosts\n" }
For Debian/Ubuntu based systems:
apt install qemu-guest-agent
For RedHat based systems:
yum install qemu-guest-agent
Start the service:
systemctl start qemu-guest-agent
Starting the systemd unit file takes a long time and fails. You see the following errors in the journal:
Apr 10 18:14:39 pmg systemd[1]: dev-virtio\x2dports-org.qemu.guest_agent.0.device: Job dev-virtio\x2dports-org.qemu.guest_agent.0.device/start ti Apr 10 18:14:39 pmg systemd[1]: Timed out waiting for device /dev/virtio-ports/org.qemu.guest_agent.0.
You probably forgot to enable the QEMU Guest Agent setting in the vm settings.
If the QEMU Guest Agent service is startet but in the vm overview you see “QEMU Guest Agent not running” then you probably forgot to enable the QEMU Guest Agent setting in the vm settings.