Geek's Notes Universe :: Форумы :: OpenStack

HOWTO not use VNC on libvirt VMs

[ Истинный ДАО ]
Сообщений: 493
Suppose, you need access to your virtual machine after it has booted up, but has no networking access yet.

Typicaly we use VNC, and it is a litle bit annoying to forward TCP ports.
Here is how to setup and use serial console power.
Configure libvirt instance to use serial

By default libvirt enables serial console, to verify that, we call dumpxml


As we can see, our virtual machine listening two serial consoles.
First serial console attached to some log file on host machine.
Second one attached to /dev/pts/3 on host node, and this pty targets to serial1 (not serial0) note this.

I'm running generic cirros image. Inside cirros image i can see getty listening ttyS0, and no ttyS1
$ ps aux | grep tty
  302 root     /sbin/getty -L 115200 ttyS0 vt100
  303 root     /sbin/getty 115200 tty1
  309 root     grep tty

This is why we cannot connect right now to our VM via serial. That's bad. Now, inside cirros we run
sudo /sbin/getty -L 115200 ttyS1 vt100
Note, this is not permanent yet, and you have to configure your image to respawn console once it has closed.

As cirros now listening for serial1 at ttyS1, we are able to connect to it.

So, what if your grep returns nothing about serial, then you have to add it like this:

Create xml file
/path/to/console.xml Expand source

Configure your VM instance to use serial by running:
virsh attach-device vm-domain-name /path/to/console.xml

Configure virtual machine to respawn serial

Now we need to set up our virtual machine to respawn serial console.

Serial console may be spawned after OS booted up. And this is very easy to set up.
Ubuntu has pretty manual for serial console setup (https://help.ubuntu.com/community/SerialConsoleHowto)
Shortly, you can add file:
/etc/init/ttyS0.conf Expand source

and reboot. Older distros requires editing /etc/inittab by adding
T0:123:respawn:/sbin/getty -L ttyS0 115200 vt100

But, i'm pretty sure, we don't need this as we set up latest OS images. Who ever needed centos 5 or ubuntu 8.04 running on his virtual machines.
Some kiddies spawns their serial consoles by running systemd service. I've never used that method, but it has it's chance.

You may be interesting how to do this. Simply google it (I'm feeling lucky with http://0pointer.de/blog/projects/serial-console.html)

But, what if you want to be able to interrupt boot process via serial console. Then you have to set ub grub correctly

Edit /etc/default/grub
GRUB_CMDLINE_LINUX="console=tty0 console=ttyS0,115200n8"
GRUB_SERIAL_COMMAND="serial --speed=115200 --unit=0 --word=8 --parity=no --stop=1"

rebuild grub configuration
grub-mkconfig -o /boot/grub/grub.cfg

If you're an old distro lover and have grub v1 on the board, then simply add to /boot/grub/menu.lst:
serial --unit=0 --speed=115200 --word=8 --parity=no --stop=1
terminal serial

and modify kernel boot string cmd at /boot/grub/menu.lst
kernel /boot/vmlinuz-2.6.18 blah-blah-blah .... ro vga=normal .... console=tty0 console=ttyS0,115200n8

reboot now and feel happy.
Connect to your virtual machine console
virsh console vm-domain-name

Wow, that's easy, but has some limitations. Let's rock with screen or minicom (whatever you like):
root@U1404Lab-Nova:/home/stack# virsh dumpxml instance-00000002 | grep pty -A2
This instance running on /dev/pts/3 so i use screen to connect to it
screen /dev/pts/3 115200

Once you finish your session, terminate screen session by calling Ctrl+a,shift+k
Notice, if you are already inside screen, then contol command (Ctrl+a) must be passed that many times how many times you called screen inside screen. Example: screen inside screen reqires two (Ctrl+a) sequences before you call shift+k.


[ Редактирование Mon Dec 21 2015, 12:31PM ]

Модераторы: root, andrey, AndreikA, faerie.qveene, slavok

<< Предыдущая тема | Следующая тема >>

Перейти:     Наверх