Affichage des articles dont le libellé est virtualbox. Afficher tous les articles
Affichage des articles dont le libellé est virtualbox. Afficher tous les articles

29 nov. 2012

Virtualbox and Centos: Frozen network, Detected Tx Unit Hang

Since few days I had a really annoying issue with one of my virtual machine:

I run a python script using urllib2 to collect some data from various online APIs. Everything seems to run smoothly when sudenly the script starts to hang and becomes unresponsive (CTRL+C does not have any effect). I open a new shell to see what's going on and I notice that any application that triggers a network activity starts to hang (yum, pip...). I open my TTY console and I notice that some error messages are popping : "eth0: Detected Tx Unit Hang", "eth0 Reset Adapter" and something about kernel hang timeout... A lot of signs that something really bad is happening on this machine. The only way to recover from it consists in performing a hardware reset of the Guest machine, but the problem arises again shortly after.


Screenshot of the situation

The issue had nothing to do with my script or my VM setup, but was in the configuration of the VirtualBox instance. I have a Intel i7-2600 CPU with 4 cores on my Host, so I though it was a good idea to assign multiple cores to my VM to improve performances and to have something closer to my production server. Turns out that by doing this I caused the problem: assigning more than 1 cpu to my VM results in the network interface to hang and freeze the kernel after a certain amount of data is transmited. I'm using the last version of Virtualbox to date (4.2.4) with Centos (6.3). Hopefully this will be fix in the next release.

TL;DR: If your VM is hanging and shows some network errors, check how many CPU you assigned to it, and if this is more than one, reduce it.

I posted this fix in English because I ran into this annoying situation and I wanted it to be available to more than my usual French audience, considering I didn't find that much info about it except this old entry in Virtualbox bugtracker.

22 déc. 2010

Centos utilise 100% du CPU sous VirtualBox

Comme beaucoup de développeurs, j'utilise très souvent une machine virtuelle pour tester mes développements en local. J'ai une préférence particulière pour Centos, qui reste très proche des serveurs Red Hat sur lesquels j'interviens, et pour VirtualBox comme solution de virtualisation (de part sa gratuité et sa simplicité d'utilisation). Malgré mon aisance grandissante avec les systèmes Unix, je n'ai toujours pas migré ma station de travail sur un OS comme Fedora ou Ubuntu, et je continue à utiliser une version vieillissante d'XP (pour des raisons professionnelles surtout...). Après l’installation de Centos 5.5 (et même sur les versions précédentes) sur une nouvelle machine virtuelle, j'ai souvent constaté que l'utilisation du processeur faite par virtualbox.exe était en permanence de 50% (j'ai un processeur double coeur), et ce même quand la machine est au repos sans aucun processus actif (idle). D'après ce que j'ai pu lire, et sans être en grand spécialiste sur le sujet, il s'agirait d'un problème avec le Kernel de Centos qui fonctionnerait à une fréquence supérieure à celle du virtualiseur, comme mes connaissances sont assez limitées je ne m'étendrais pas sur le sujet et je vais me contenter de vous donner la solution que j'utilise pour contourner le problème.

Certains préconise de recompiler le Kernel avec les options adéquates afin de prendre en compte la bonne fréquence, d'autres propose d'utiliser un Kernel maison bidouillé pour fonctionner correctement avec VirtualBox... Personnellement je ne me sent pas très à l'aise avec l'idée de recompiler le Kernel, et pour ce qui est d'une version non-officielle, je préfère éviter dans un cadre professionnel (support oblige...). Je vous propose donc une troisième solution, qui ne requerra qu'un redémarrage de votre VM :

1) Ouvrez le fichier /etc/grub.conf avec votre éditeur favoris.

2) Repérez les lignes concernant le kernel, et ajoutez divider=10 à la fin de celles-ci.

Voici mon fichier grub.conf à titre d'exemple
default=0
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title CentOS (2.6.18-194.26.1.el5)
        root (hd0,0)
        kernel /vmlinuz-2.6.18-194.26.1.el5 ro root=/dev/VolGroup00/LogVol00 divider=10
        initrd /initrd-2.6.18-194.26.1.el5.img

title CentOS (2.6.18-194.el5)
        root (hd0,0)
        kernel /vmlinuz-2.6.18-194.el5 ro root=/dev/VolGroup00/LogVol00 divider=10
        initrd /initrd-2.6.18-194.el5.img
3) Sauvez le fichier

4) Redémarrez votre VM.

5) ...

6) Profit !

Et voilà, maintenant profitez de votre machine virtuelle sous Centos sans compromettre la longévité de votre CPU sur le long terme.