8.3. Running commands in virtual machines without network connectivity

8.3. Running commands in virtual machines without network connectivity

If a VM cannot access a network for some reason, you can still run commands in it from the node the VM resides on. The VM in question must have the guest tools installed in it (refer to Managing guest tools).

You will need the VM ID that you can obtain with vinfra service compute server list. You can also use a virsh domain name that you can get using virsh list.

8.3.1. Running commands in Linux virtual machines

To run an arbitrary command inside a Linux VM and receive the output to your console, use the virsh x-exec command. For example:

# virsh x-exec 1d45a54b-0e20-4d5e-8f11-12c8b4f300db /usr/bin/bash -c 'lsblk'
NAME        MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
loop0         7:0    0 945.9M  1 loop
loop1         7:1    0     5G  1 loop
├─live-rw   253:0    0     5G  0 dm   /
└─live-base 253:1    0     5G  1 dm
loop2         7:2    0    32G  0 loop
└─live-rw   253:0    0     5G  0 dm   /
sda           8:0    0    64G  0 disk
sdc           8:32   0     1G  1 disk
sr0          11:0    1     2G  0 rom  /run/initramfs/live

To copy a file to a Linux VM, use the virsh x-exec and cat commands. For example:

# virsh x-exec 1d45a54b-0e20-4d5e-8f11-12c8b4f300db \
--shell 'cat > test.file' < /home/test.file

To get a file from a Linux VM, use the virsh x-exec and cat commands as well. For example:

# virsh x-exec 1d45a54b-0e20-4d5e-8f11-12c8b4f300db \
--shell 'cat /home/test.file' > test.file

8.3.2. Running commands in Windows virtual machines

To run an arbitrary command inside a Windows VM and receive the output to your console, use the virsh x-exec command. For example:

# virsh x-exec bbf4a6ec-865f-4e2c-ac21-8639d1bfb85c --shell dir c:\\
 Volume in drive C has no label.
 Volume Serial Number is D0BE-A8D1

 Directory of c:\

06/10/2009  01:42 PM                24 autoexec.bat
06/10/2009  01:42 PM                10 config.sys
07/13/2009  06:37 PM    <DIR>          PerfLogs
11/12/2018  07:45 AM    <DIR>          Program Files
11/12/2018  07:55 AM    <DIR>          test
11/12/2018  06:23 AM    <DIR>          Users
11/12/2018  07:53 AM    <DIR>          Windows
               2 File(s)             34 bytes
               5 Dir(s)  59,329,495,040 bytes free

To copy a file to a Windows VM, use the virsh x-exec and prl_cat commands. For example:

# virsh x-exec bbf4a6ec-865f-4e2c-ac21-8639d1bfb85c \
--shell '%programfiles%\\qemu-ga\\prl_cat' 'c:\test\test.file' < /home/test.file

To get a file from a Windows VM, use the virsh x-exec and type commands. For example:

# virsh x-exec bbf4a6ec-865f-4e2c-ac21-8639d1bfb85c \
--shell type 'c:\test\test.file' > test.file