Saturday, June 30, 2012

Virsh console - Issue and solution

I faced several issue when I tried to use "virsh console " in KVM. It simply hangs in following line: 

"Escape character is ^]" 

 After trying several things here is how I solved the problem:

Step 1: If the VM is running destroy it (virsh destroy
Step 2: Mount the image (following instructions are for raw disk image for Ubuntu host)

kpartx -av /location-to-disk-image 
mount /dev/mapper/loop0p2 /path-to-mount

[Note: kpartx list out several mappers and you need to pick the correct one, just play around it you will find the correct one to map. Correct one is one with grub directories] 

vi /path-to-mount/grub2/grub.cfg (in your case it might be grub) 

add "console=ttyS0" as shown below: 

kernel /vmlinuz ro a-set-of-values console=ttyS0 
umount /path-to-mount 
kpartx -dv /location-to-disk-image 

Step 3: Now start the VM "virsh start
Step 4: Console to the VM "virsh console "


Zydoon said...

Thank you buddy for this article.
Just want to add that this works on LVM based VMs

And, on RHEL, afeter kpartx -av /dev/vg_name_lv_name
[root@host ~]# kpartx -av /dev/vg_vm/lv_lifeVM
add map vg_vm-lv_lifeVM1 (253:8): 0 1024000 linear /dev/vg_vm/lv_lifeVM 2048
add map vg_vm-lv_lifeVM2 (253:9): 0 61888512 linear /dev/vg_vm/lv_lifeVM 1026048

so when mount, just type
mount /dev/mapper/vg_vm-lv_lifeVM1 /mnt/
and you'll get grub.conf under /mnt/grub.

Thank you again.

Anonymous said...

is easier do this change over ssh, and then restart

Hazhir Hajian said...

You can do this over SSH and on top of that I had to add file /etc/init/ttyS0.conf with following content

start on stopped rc RUNLEVEL=[2345]
stop on runlevel [!2345]

exec /sbin/getty -L 38400 ttyS0 vt102 # This is your term type vt102

And then a server reboot and things work just fine.