Sunday 10 October 2010

xenconsole-ng

Hi there, long time I haven't used this blog!!

I'll explain how to create an Ubuntu 10.04 installation on a XenServer without using XenConsole at all!!

First of all, I'll assume you already have XenServer 5.6.0 or newer installed, and also the linux tools templates.

Then, we will create the template for the network install of our Ubuntu 10.04. Thanks to Anthony Francis for his post and his script makeubuntu.sh

Basically what this script does is to create a new template using xe commands based on the Debian Lenny template already existent.

Once done, we can create our own installation by issuing the following commands:


VM_NAME="TheVMNameIWant"
VM_UUID=$(xe vm-install new-name-label=$VM_NAME template="Ubuntu 10.04 (32-bit)")
PIF_UUID=$(xe network-list bridge=xenbr0 --minimal)
VIF_UUID=$(xe vif-create network-uuid=PIF_UUID vm-uuid=$VM_UUID device=0)
xe vm-param-set uuid=$VM_UUID other-config:disable_pv_vnc=1 #To disable automatic XenCenter console. Be careful as if we do not do this, we will experience insane behaviors when connecting through SSH


Now you already have your new fresh vm installation, but waiting to be started and controlled so everything gets installed. To do so you can issue these commands or better, use my scripts at the bottom of this post ;)


#so now start the new VM
xe vm-start uuid=$VM_UUID
#search for the new domain id
DOM_ID=$(xe vm-list params=dom-id uuid=$VM_UUID --minimal)
#and connect to it
/usr/lib/xen/bin/xenconsole $DOM_ID


Scripts section:

cat << EOF >/root/bin/xenconsole-ng
#!/bin/bash

RUNNING_VM_NAMES=$(xe vm-list power-state=running is-control-domain=false params=name-label --minimal)

echo "List of running virtual machines to attach to:"
i=0
for vmn in $RUNNING_VM_NAMES
do
echo "$i - $vmn"
i=$(expr $i + 1)
done
i=$(expr $i - 1)
echo -n "Select a number (0-$i): "
read s

i=0
for vmn in $RUNNING_VM_NAMES
do
if [[ $i -eq $s ]] ;
then
echo -n "Searching vm $i ($vmn) ... "
VM_UUID=$(xe vm-list name-label=$vmn params=uuid --minimal)
DOM_ID=$(xe vm-list name-label=$vmn params=dom-id --minimal)
if [[ -z "$DOM_ID" ]]
then
echo "FATAL!! No Domain found for that vm!"
exit -2
else
echo "(if nothing happends press enter key)"
echo "Remember, Ctrl+] on guest or xenconsole-dettach-ng on host escapes this console"
/usr/lib/xen/bin/xenconsole $DOM_ID 2>/dev/null
reset
fi
exit 0
else
i=$(expr $i + 1)
fi
done
echo "Virtual Machine not found!"
exit -1
EOF

cat << EOF > /root/bin/xenconsole-dettach-ng
#!/bin/bash

RUNNING_VM_NAMES=$(xe vm-list power-state=running is-control-domain=false params=name-label --minimal)

ATTACHED_CONSOLES=$(ps aux | grep "/xenconsole " | sed "s/ */ /g" | cut -f 12 -d " ") #field 2=pid, 12=dom_id

echo "List of running virtual machines to dettach from:"
i=0
avmn=""
avmp=""
for vmn in $RUNNING_VM_NAMES
do
DOM_ID=$(xe vm-list name-label=$vmn params=dom-id --minimal)

if [[ -z "$(echo $ATTACHED_CONSOLES | grep $DOM_ID)" ]]
then
echo "$vmn not attached"
else
echo -n "$vmn attached with pid "
PID=$(ps aux | grep "/xenconsole $DOM_ID" | sed "s/ */ /g" | cut -f 2 -d " ")
echo "$PID"
avmn="$avmn $vmn"
avmp="$avmp $PID"
fi
i=$(expr $i + 1)
done

i=0
for vmn in $avmn
do
echo "$i - $vmn"
i=$(expr $i + 1)
done
i=$(expr $i - 1)
echo -n "Select a number (0-$i): "
read s

i=0
for pid in $avmp
do
if [[ $i -eq $s ]] ;
then
echo -n "Dettaching console $i ($pid) ..."
kill -9 $pid
echo " Done!"
exit 0
else
i=$(expr $i + 1)
fi
done
echo "Console not found!"
exit -1
EOF


Sure they can be polished, or even completely rewritten, but they work for me and I just wanted to share with you all ;) and have them for the records :P

Thanks also to this document site where I finally found a way to connect to the text-based console and much much more information ;)

Of course, you can alo use OpenXenManager for Linux or XenCenter for Windows, but my way is more geeky ;)

Monday 31 May 2010

Migración IMAP

Tanto si vais a cambiar de servidor de correo, como si queréis migrar a gmail o a Google Apps, aquí va una receta de cómo migrar todo el correo de un lado al otro usando IMAP.

En Gmail o Google Apps, las etiquetas se tratan como carpetas desde una conexión IMAP. Lo primero es habilitar la conexión IMAP en la configuración de GMail.

Luego usamos un comando de este estilo:

imapsync --host1 imap.server.org \
--user1 user@server.org \
--passfile1 ./passfile1 \
--host2 imap.gmail.com \
--port2 993 --user2 user@gmail.com \
--passfile2 ./passfile2 --ssl2 \
--split1 100 --split2 100 \
--buffersize 18192000 --maxsize 18192000 \
--noauthmd5 \
--folderrec ElDirQueSea \
--syncinternaldates \
--authmech1 LOGIN --authmech2 LOGIN \
--useheader 'Message-Id' --skipsize

Explicación de la falla:
Los primeros parámetros son obvios, datos de configuración de la conexión IMAP, que para el caso de GMail es especial ya que requiere SSL (de ahí el --ssl2) y no soporta authmd5 (de ahí el --noauthmd5). En los passfiles se guardan en texto plano los passwords y listos. Tmb se puede meter el pass directamente en la línea de comandos pero es un poco más salvaje a nivel de seguridad ya que al fichero siempre le puedes meter un chmod 600.
Después --syncinternaldates se asegura de que los correos vayan con su fecha, y no con la fecha de la migración, que siempre es interesante.
Los --buffersize 18192000 y --maxsize 18192000 lo que hacen es ampliar la memoria de imapsync, y limitar el tamaño del mensaje máximo para evitar que pete por out-of-memory, muy típico de imapsync.
Imapsync sincronizará la etiqueta o carpeta que le pongas en el --folderrec de manera rec-ursiva, jeje.
La última línea es muy importante si estás usando GMail, ya que de lo contrario vuelve a copiar los correos ya existente, que si bien no es problema por los duplicados ya que GMail lo detecta y elimina duplicados, sí es un engorro pq estás ejecutando el comando 20.000 horas de más, así que --useheader 'Message-Id' --skipsize obligado! ;)
Y por último los splits ... la verdad no he notado diferencia de velocidad, pero según reza la ayuda es el número de peticiones simultaneas a servidor origen y servidor destino respectivamente ... o eso creo :P

Por si sirve de ayuda, yo primero he hecho un --justfolders para que cree la estructura de directorios/etiquetas, y luego he creado un fichero de texto con cada folder en una línea. Luego con lo siguiente he ido saltando de folder en folder para evitar que un fallo me pare el proceso entero:

while read i
do
imapsync bla bla bla ... --folder $i
done < folder.list.txt

Ale, felices migraciones ;)

Links de interés:
http://www.thamtech.com/blog/2008/03/29/gmail-to-google-apps-email-migration/
http://www.linux-france.org/prj/imapsync/FAQ
http://wiki.zimbra.com/wiki/Guide_to_imapsync

Monday 10 May 2010

Trust Slimline Sketch Tablet en Ubuntu Karmic (9.10)

Pues eso, me he comprado por fin, después de varios años de deseo, una tableta digitalizadora Trust Slimline Sketch Tablet. Y como uno trabaja en Ubuntu ... pues me ha tocado ver cómo hacerla ir. Afortunadamente me he encontrado con este post que paso a traducir/resumir/adaptar.

http://jan.varho.org/blog/computers/linux-computers/trust-slimline-sketch-tablet-on-ubuntu-karmic/

Primero instalamos el wizardpen
#> sudo add-apt-repository ppa:doctormo/xorg-wizardpen
#> sudo aptitude update
#> sudo aptitude install xserver-xorg-input-wizardpen

Después creamos el fichero de configuración
#> sudo gedit /etc/hal/fdi/policy/99-x11-wizardpen.fdi






wizardpen
true
1688
2831
30748
30619
30748
30619





Y por último calibramos nuestra tableta ejecutando este comando y sustituyendo en el fichero .fdi anterior.
#> sudo wizardpen-calibrate /dev/input/by-id/usb-UC-LOGIC_Tablet_WP8060U-event-mouse

Cada vez que retoquemos el .fdi tenemos que reconectar la tableta para que la coja.

Y ee e e eeesstooo es toooodo amigoooos ;)