I have a VM which I can start with virsh
. According to virsh dumpxml VM1
, this is the allocated pty:
<serial type='pty'>
<source path='/dev/pts/6'/>
<target port='0'/>
<alias name='serial0'/>
</serial>
<console type='pty' tty='/dev/pts/6'>
<source path='/dev/pts/6'/>
<target type='serial' port='0'/>
<alias name='serial0'/>
</console>
The VM is running:
# virsh list
Id Name State
----------------------------------
7 VM1 running
Inside the VM, this is the grub configuration:
kernel /boot/vmlinuz-2.6.24-28-virtual root=UUID=7a1685b9-ecc8-4b70-932c-459a6faac07d ro quiet splash console=tty0 console=ttyS0,9600n8
And this is the command line launched by virsh to start the VM:
/usr/bin/kvm -S -M pc-0.12 -enable-kvm -m 256 -smp 1,sockets=1,cores=1,threads=1 -name VM1 -uuid 47ff6ec2-a748-4738-16b9-2ffe5780e456 -nodefaults -chardev socket,id=monitor,path=/var/lib/libvirt/qemu/VM1.monitor,server,nowait -mon chardev=monitor,mode=readline -rtc base=utc -boot c -drive file=/var/VMs/VM1.qcow2,if=none,id=drive-ide0-0-0,boot=on,format=raw -device ide-drive,bus=ide.0,unit=0,drive=drive-ide0-0-0,id=ide0-0-0 -device virtio-net-pci,vlan=0,id=net0,mac=52:54:00:12:34:50,bus=pci.0,addr=0x3 -net tap,fd=64,vlan=0,name=hostnet0 -chardev pty,id=serial0 -device isa-serial,chardev=serial0 -usb -vnc 127.0.0.1:0 -k de -vga cirrus -device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x4
But if I connect with virsh console VM1
, or I do cat /dev/pts/6
, nothing is shown in the VM console.
Is there something else that I must consider?
UPDATE
I have two VMs, one started directly with kvm
, the other via virsh
. The one started directly has a working console. I have verified the open files in both cases:
root@host1:~# lsof | grep 25093 | grep dev
kvm 25093 root DEL REG 0,4 3758780 /dev/zero
kvm 25093 root DEL REG 0,4 3758779 /dev/zero
kvm 25093 root DEL REG 0,4 3758777 /dev/zero
kvm 25093 root 0u CHR 136,3 0t0 6 /dev/pts/3
kvm 25093 root 1u CHR 136,3 0t0 6 /dev/pts/3
kvm 25093 root 2u CHR 136,3 0t0 6 /dev/pts/3
kvm 25093 root 3u CHR 10,232 0t0 8025 /dev/kvm
kvm 25093 root 7u CHR 10,200 0t0 4983 /dev/net/tun
root@host1:~# lsof | grep 8341 | grep dev
kvm 8341 libvirt-qemu DEL REG 0,4 9743486 /dev/zero
kvm 8341 libvirt-qemu DEL REG 0,4 9743485 /dev/zero
kvm 8341 libvirt-qemu DEL REG 0,4 9743483 /dev/zero
kvm 8341 libvirt-qemu 0r CHR 1,3 0t0 4640 /dev/null
kvm 8341 libvirt-qemu 4u CHR 5,2 0t0 4897 /dev/ptmx
kvm 8341 libvirt-qemu 5u CHR 10,232 0t0 8025 /dev/kvm
kvm 8341 libvirt-qemu 64u CHR 10,200 0t0 4983 /dev/net/tun
As you can see, in one of the VMs (the wrong one), there are no file descriptors 1 & 2, and file descriptor 0 is redirected to /dev/null. That is the problem I guess.
The question is, how do I tell virsh not to do that?
Working example of using Debian jessie as host and guest operating system.
create a VM using virt-install or virt-manager In any case you will get serial console statements added to VM.xml file
in guest VM run the following
in guest VM in
/etc/default/grub
replaceby
in guest VM run the following
the VM console for running VM can be get by
or start the VM with console attached
Sources:
This is what I normally add to the VMs definition, using
virsh edit
Thenconsole=ttyS0
appended in the VM's kernel line in grub.confNever failed me so far
I've found the most applicable answer here:
Suppose your virtual domain is
myGuest
, your preferred editor isvi
, and your guest is installed withgrub2
and usessystemd
. If the last assumption is not true, you might have a look at Working with the Serial Console.First, install
libguestfs-tools
on the host:sudo apt install libguestfs-tools
. You will need this when working with headless guests.Second, shut down your guest:
virsh shutdown myGuest
.Next, mount the virtual disk:
guestmount -d myGuest -i /mnt
(or use any other existing directory as mountpoint). Now in/mnt
you should be able to see the filesystem of the guest.With
grub2
andsystemd
, you only have to modify the grub configuration:vi /mnt/etc/default/grub
, and modify likeAs you will have to run
update-grub
on the guest, for the first start you have to also modify/mnt/boot/grub/grub.cfg
. Find the default boot menu item and append the console information to thelinux
entry to look similar toMaybe you need root privileges to mount and edit the files.
Now restart the guest and start the virtual console:
You should see the kernel log and then a login prompt. After logging in, don't forget to run
sudo update-grub
.has been sufficient for an Ubuntu guest (20.04), VM been initialized with virt-manager.
No need to change GRUB configuration entries, nor adding
serial
/console
to the virsh XML file.