lost and found ( for me ? )

KVM : how to connect to Fedora VMs which are using grub2 as a boot loader via virsh console or minicom

Here's an explanation of how to connect to VMs which are using grub2 via virsh console or minicom.
KVM host : Fedora 16
VM : Fedora 16 ( boot loader is grub2 not grub )

[ add a serial port to the VM ]

assume that the Fedora VM has a serial port.
you can check whether or not your VM has a serial port as below:

- on the KVM host

# virsh ttyconsole f16-vm1
/dev/pts/2

or


# virsh dumpxml f16-vm1 | grep serial
   <controller type='virtio-serial' index='0'>
     <alias name='virtio-serial0'/>
   <serial type='pty'>
     <alias name='serial0'/>
   </serial>
     <target type='serial' port='0'/>
     <alias name='serial0'/>
     <address type='virtio-serial' controller='0' bus='0' port='1'/>

[ configure a serial port on the VM ( not the KVM host ) ]

- on the VM

add the red lines
[root@localhost ~]# cat /etc/default/grub
GRUB_CMDLINE_LINUX="quiet rhgb biosdevname=0"
GRUB_CMDLINE_LINUX_DEFAULT="console=tty0 console=ttyS0,9600n8"
GRUB_TERMINAL=serial
GRUB_SERIAL_COMMAND="serial --speed=9600 --unit=0 --word=8 --parity=no --stop=1"

add the following line in /etc/inittab
[root@localhost ~]# tail -1 /etc/inittab
S0:12345:respawn:/sbin/agetty ttyS0 115200

add the following line in /etc/securetty file.
[root@localhost ~]# echo "ttyS0" >> /etc/securetty

update grub.cfg
[root@localhost ~]# grub2-mkconfig -o /boot/grub2/grub.cfg
Generating grub.cfg ...
Found linux image: /boot/vmlinuz-3.3.5-2.fc16.x86_64
Found initrd image: /boot/initramfs-3.3.5-2.fc16.x86_64.img
done


[root@localhost ~]# egrep -v ^# /boot/grub2/grub.cfg

if [ -s $prefix/grubenv ]; then
 load_env
fi
set default="0"
if [ "${prev_saved_entry}" ]; then
 set saved_entry="${prev_saved_entry}"
 save_env saved_entry
 set prev_saved_entry=
 save_env prev_saved_entry
 set boot_once=true
fi

function savedefault {
 if [ -z "${boot_once}" ]; then
   saved_entry="${chosen}"
   save_env saved_entry
 fi
}

function load_video {
 insmod vbe
 insmod vga
 insmod video_bochs
 insmod video_cirrus
}

serial --speed=9600 --unit=0 --word=8 --parity=no --stop=1
terminal_input serial
terminal_output serial
set timeout=5

menuentry 'Linux, with Linux 3.3.5-2.fc16.x86_64' --class gnu-linux --class gnu --class os {
load_video
set gfxpayload=keep
insmod gzio
insmod part_gpt
insmod ext2
set root='(/dev/vda,gpt2)'
search --no-floppy --fs-uuid --set=root ecdb7a66-7b00-49b9-b507-82e346d4c549
echo 'Loading Linux 3.3.5-2.fc16.x86_64 ...'
linux /boot/vmlinuz-3.3.5-2.fc16.x86_64 root=UUID=ecdb7a66-7b00-49b9-b507-82e346d4c549 ro quiet rhgb biosdevname=0 console=tty0 console=ttyS0,9600n8
echo 'Loading initial ramdisk ...'
initrd /boot/initramfs-3.3.5-2.fc16.x86_64.img
}


reboot the VM

[ connect to the VM from KVM host with virsh console ]

on the KVM host
[root@fc16 ~]# virsh list --all
Id Name                 State
----------------------------------
 1 f16-vm1              running

[root@fc16 ~]# virsh console f16-vm1
Connected to domain f16-vm1
Escape character is ^]

Password:

Login incorrect

login: root
Password:
Last login: Wed May 16 12:02:07 from 192.168.122.1

Appliance: jeos-f16 appliance 1.0
Hostname: localhost
IP Address: 192.168.122.124

[root@localhost ~]#

[ connect to the VM from the KVM host with minicom ]

You can also connect to the VM with minicom.

on the KVM hsot

install minicom
[root@fc16 ~]# yum install -y minicom

check a serial port number of the VM to which you want to connect.
[root@fc16 ~]# virsh ttyconsole f16-vm1
/dev/pts/2

connect to the VM with minicom
[root@fc16 ~]# minicom -op /dev/pts/2


Welcome to minicom 2.5

OPTIONS: I18n
Compiled on Apr  6 2011, 07:59:07.
Port /dev/modem

Press CTRL-A Z for help on special keys


Fedora release 16 (Verne)
Kernel 3.3.5-2.fc16.x86_64 on an x86_64 (ttyS0)

login: root
Password:
Last login: Wed May 16 12:34:59 on ttyS0

Appliance:      jeos-f16 appliance 1.0
Hostname:       localhost                                                       
IP Address:     192.168.122.124                                                 
                                                                               
[root@localhost ~]#


when exiting the VM , press Ctrl A and then press x

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.