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