Thursday, April 14, 2011

Winexe: To run code on windows machines from Linux

The instructions on this post are a summary of information collected from this link. And I made some changes to it as well

These are instructions of how to get winexe working on Ubuntu 10.04.1 LTS system

To begin with make sure your system has the required libraries:
sudo apt-get install build-essential autoconf checkinstall

You will also need the python development libraries and header files:
sudo aptitude install python python-all python-dev python-all-dev python-setuptools

Now get the source code of winexe using svn. And apply the first patch:
svn co
cd source
patch -p0 -i fix_winexe_service.diff

Now there is bug in the source/winexe/service.c file:
replace file


Save,close and you are ready to compile:
cd source/
make proto bin/winexe
sudo cp bin/winexe /usr/local/bin/

and now you can test that that winexe is working correctly by doing:
winexe -W WORKGROUP -U Administrator%SecretPassword // 'cmd.exe'

Friday, January 14, 2011

Compiling C/C++ code from Matlab on Ubuntu Linux machine

It seems that there is much easier way of compiling and running C/C++ from your Matlab application, than the one I was trying before.

Reproducing the instructions on this blog here:

My version of gcc (4.4) is too high for Matlab R2009b (4.3), and Matlab chokes on it. The solution is as follows:

Install gcc-4.3:

sudo apt-get install gcc-4.3
sudo apt-get install g++-4.3

In matlab, run mex -setup and select the GCC compiler.(Choose option 2). Next, at the command line:

sudo gedit ~/.matlab/R2009b/

Replace all instances of CC=’gcc’ with CC=’gcc-4.3′, and al instances of CXX='g++' with CXX='g++-4.3'.
And restart Matlab !

Compile gcc from souce on Ubuntu 10.04.1 LTS

To run C/C++ code using the mex utility of Matlab 7.11.0 (R2010b I needed to compile a different version of GCC than what was already installed on my machine. (I had the gcc version 4.4.1-4ubuntu9 and the currently supported version with mex is 4.3.4)

So I downloaded gcc-4.3 release from here.
Untarred the file: tar -jxvf gcc-4.3.4.tar.bz2

And now when I tried to use the ./configure from inside the gcc-4.3.4 folder, the system complained that it could not find two necessary API's namely GMP and MPFR.

The issue can be resolved by doing the following. We need to (1) download the GMP and MPFR libraries separately , (2) place them inside the GCC folder and then, (3) tell the configure script to look for it there.
tar -jxf gcc-4.3.2.tar.bz2
tar -jxf mpfr-2.3.2.tar.bz2
mv mpfr-2.3.2 gcc-4.3.2/mpfr
tar -jxf gmp-4.2.4.tar.bz2
mv gmp-4.2.4 gcc-4.3.2/gmp
cd gcc-4.3.2
./configure --with-gmp-include=$(pwd)/gmp --with-gmp-lib=$(pwd)/gmp/.libs
make install

Hopefully, that should solve the issues !

Thursday, October 14, 2010

Disable the graphics on your machine

Just a quick note about how to disable the graphical user interface on your machine safely and quickly. This may be useful if you are having issues with your video card causing your system to crash. By disabling the graphics you could get command line interface to your machine.. and hopefully determine the exact problem to get your GUI to work.

mv /etc/init/gdm.conf /etc/init/gdm.disabled

This works on Ubuntu 10.04 LTS.
Remember that this would disable the graphics on all your boots. Not just the the one from which you make the change. And of course run the reverse mv command and reboot your machine to start your graphics again.

Wednesday, September 29, 2010

Removing entries from the known_hosts

One often encounters the following error message, particularly in situations where the machine owning the target IP address has changed:

user@host-machine:~$ ssh user@target_IP
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that the RSA host key has just been changed.
The fingerprint for the RSA key sent by the remote host is
Please contact your system administrator.
Add correct host key in /home/user/.ssh/known_hosts to get rid of this message.
Offending key in /home/user/.ssh/known_hosts:4
RSA host key for target_IP has changed and you have requested strict checking.
Host key verification failed.

The issue can be resolved by using the ssh-keygen command with the -R option to remove and update the known_hosts file. Simply do:

user@host-machine:~$ ssh-keygen -R target_IP -f /home/user/.ssh/known_hosts
/home/user/.ssh/known_hosts updated.
Original contents retained as /home/user/.ssh/known_hosts.old
user@host-machine:~$ ssh user@target_IP
The authenticity of host 'target_IP (target_IP)' can't be established.
RSA key fingerprint is XX:XX:XX.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'target_IP' (RSA) to the list of known hosts.
user@target_IP's password:
Linux XenOpen #2 SMP Mon Sep 27 10:23:06 EDT 2010 x86_64 GNU/Linux
Ubuntu 10.04.1 LTS

Starting new domains on Xen 4.0.1 from command line

So, I have issues with my installation of Xen4.0.1 as the graphics driver keeps crashes during boot up, resulting in a hung machine. For now, I am using a work around suggested by my colleagues David Wolinsky and Pierre St. Juste, namely to disable the graphics display module (using "mv /etc/init/gdm.conf /etc/init/gdm.disabled") and hence I only have command line access to my domain-0 at this point.

At this point, Domain-0 boots up just fine, and xm and xend seem to be working. I now need to start Virtual domains using only the command line. (Later I will explore ways to do the same thing using APIs like Virt-Manager, or its console variant Virt-install)

Creating an Image
The first step is to create an image that will hold the user-domain (domU) virtual disk. This can be just a raw zero-filled file and so we can use the dd command here:
dd if=/dev/zero of=/var/lib/xen/images/domain1.img oflag=direct bs=1M seek=2047 count=1
The above command will create /var/lib/xen/images/domain1.img file of 2048MB although the actual data blocks are allocated in a lazy fashion. To reserve all the data blocks right away, get rid of the seek option from above. So do:
dd if=/dev/zero of=/var/lib/xen/images/domain1.img oflag=direct bs=1M count=2048
This will avoid data block allocation problems if the volume that holds the image is full. It is important to check that the image has the correct security context (permissions), otherwise access to the virtual disk will be denied to the user domain system. You can check this as follows:
ls -l /var/lib/xen/images/domain1.img
-rw-r--r-- 1 root root 2147483648 2010-10-13 10:23 /var/lib/xen/images/domain1.img
Preparing a Xen configuration file for the installation
Xen uses a configuration file per domain. The configuration for the domains is different because we have to provide installation kernels, initial ram-disk and possibly some boot parameters. The domainU installation initrd image and kernel for my machine architecture (64-bit x86) can be downloaded from this page. You can put them in some sensible directory and name them appropriately.
root@Xen-Open:~# mkdir /home/user/x86_64_domU_images
root@Xen-Open:~# cd /home/user/x86_64_domU_images
root@Xen-Open:~/x86_64_domU_images# wget
root@Xen-Open:~/x86_64_domU_images# wget
root@Xen-Open:~/x86_64_domU_images# ls
initrd.gz vmlinuz
root@Xen-Open:~/x86_64_domU_images# gunzip -c initrd.gz > initrd.img
root@Xen-Open:~/x86_64_domU_images# ls
initrd.gz initrd.img vmlinuz
In this example, the kernel and the initrd image were named /home/user/x86_64_domU_images/vmlinuz and /home/user/x86_64_domU_images/initrd.img respectively. With the images in place, we can now create the installation configuration file named /etc/xen/domain1.cfg

kernel = "/home/user/x86_64_domU_images/vmlinuz"
ramdisk = "/home/user/x86_64_domU_images/initrd.img"
name = "domain1"
memory = "256"
disk = [ 'file://var/lib/xen/images/disk.img,xvda,w', ]
vif = [ '' ]
root="/dev/xvda ro"
on_reboot = 'destroy'
on_crash = 'destroy'

Couple of points to note:
  1. The netmask and gateway values to be used can be determined by using the route command on your control domain. If you encounter problems in getting the network to start, you could try using methods suggested here.

  2. The [ 'file://var/lib/xen/images/disk.img,xvda,w', ] line here does not work if you use "tap:aio" instead of "file". Also for some reason, if you replace "xvda" with "xvda1" or something else, it does not work either. If you do any of those things you will get the following error:

    Error message:

    Error informing the kernel about modifications to partition
    -- Invalid argument. This means Linux won't know about
    any changes you made to /dev/xvda1p1 until you reboot -- so you
    shouldn't mount it or use it in any way before rebooting.
Once your config file is ready, you can start creating a domain with:
sudo xm create -c /etc/xen/domain1.cfg
And now, to access your domain, do:
sudo xm domain1
This will open an interactive installation window. Everything is self explanatory in general. If you get an error to the effect that the Ubuntu repository cannot be reached, check your control domain network and here is the fix.

Once your domain is properly created it will ask permission to reboot and will automatically get destroyed in the process because of the last two lines in the configuration command line, namely:
on_reboot = 'destroy'
on_crash = 'destroy'
So now you need to change your configuration file to the following:
name ="domain1"
memory ="256"
disk =[ 'file://var/lib/xen/images/disk.img,xvda,w', ]
vif=[ '' ]

And now just use the xm create command to create your new domain. Finally in order to automatically start and stop your domains when domain-0 starts, move the location of the configuration file to /etc/xen/auto.

At this point, it is a good idea to create a copy of your virtual machine image. To create new virtual machines using the same image all you have to do is to change the configuration file (name, location of the disk image etc) to point to the copy and start the new machines... waaa la !

Monday, September 13, 2010

How to install Xen4.0 on Ubuntu 10.04 LTS

This post provides documentation about how to get Xen4.0 (the opensouce version) up and running on an Ubuntu 10.04 LTS (Long Term Support) 64-bit machine.

Start of with a fresh new installation of Ubuntu 10.04 LTS. Install the required packages first:
apt-get install bcc bin86 gawk bridge-utils iproute libcurl3 libcurl4-openssl-dev bzip2 module-init-tools transfig tgif texinfo texlive-latex-base texlive-latex-recommended texlive-fonts-extra texlive-fonts-recommended pciutils-dev mercurial build-essential make gcc libc6-dev zlib1g-dev python python-dev python-twisted libncurses5-dev patch libvncserver-dev libsdl-dev libjpeg62-dev iasl libbz2-dev e2fslibs-dev git-core uuid-dev ocaml libx11-dev
On a 64-bit machine, you will also need this additional package:
apt-get install gcc-multilib
The next step is to get Xen4.0.1
cd /usr/src/
Un-tar and make:
tar xf xen-4.0.1.tar.gz
cd xen-4.0.1
make xen
make tools
make stubdom
At this point you should have the Xen hypervisor/tools binaries in "dist/" directory ready for installation. Now run:
make install-xen
make install-tools
make install-stubdom
The next step is to download and compile a dom0 kernel, and to update the grub file. We can do this using the following commands:
make prep-kernels
This will create a build-linux-2.6-pvops_x86_64 directory in /usr/src/ which has by a .config file in it. You need to modify the .config file to suit your requirements. You can have a look at mine here. (Source Boris Derzhavets).
You could use make menuconfig from inside the build-linux-2.6-pvops_x86_64 to make alterations to your .config file.
cd build-linux-2.6-pvops_x86_64
make menuconfig
chmod g-s /usr/src/ -R
make deb-pkg
dpkg -i ../linux-image-*.deb
update-initramfs -c -k
At this point enable Xend at boot:
update-rc.d xend defaults 20 21
update-rc.d xendomains defaults 21 20
When I typed in the last two lines, I got warning messages saying:
update-rc.d: warning: xend start runlevel arguments (2 3 4 5) do not match LSB
Default-Start values (3 4 5)
update-rc.d: warning: xend stop runlevel arguments (0 1 6) do not match LSB
Default-Stop values (0 1 2 6)

Apparently these messages are benign and should not cause any issues in the working of Xen Daemon. Now create the Grub2 entry for your new kernel:
vim /etc/grub.d/40_custom
Following is what I entered to in the 40_custom file. My installation still has issues because the graphics driver keeps crashing, and I think that the grub file has something to do with it.
exec tail -n +3 $0
# This file provides an easy way to add custom menu entries. Simply type the
# menu entries you want to add after this comment. Be careful not to change
# the 'exec tail' line above.

menuentry 'Xen 4.0.1, Ubuntu 10.4 kernel' {
insmod ext2
set root='(hd0,1)'
multiboot (hd0,1)/boot/xen-4.0.1.gz dummy=dummy dom0_mem=832M
module (hd0,1)/boot/vmlinuz- dummy=dummy root=/dev/sda1 nopat ro nomodeset console=tty0 earlyprintk=xen
module (hd0,1)/boot/initrd.img-
Update grub and reboot... And choose the correct grub option from the boot-up menu.