Access virtualbox Linux guest from windows host and access windows host share folder from virtualbox Linux guest

I have to do a lot of googling every time installing virtualbox. So I’d better summarize the process here for future reference.
The situation:
Installed Linux guest in Virtualbox on Windows 7 host.
The goal:
Windows 7 (the host) can access the Linux (the guest) and the guest and access the host as well.
The way:
(1) Create a shared folder in Virtualbox and call it D_DRIVE
(2) add mount.vboxsf D_DRIVE /home/junwei/D_Drive to the first line of /etc/rc.local
(3) sudo reboot
Now the guest Linux can access files on the host Windows via D_Drive.
(4) install samba on the guest Linux
“Ubuntu Software Center”->search samba->install it
(5) In Samba Server Configuration, add share. For example, I share /home/junwei
(6) sudo poweroff
(7) In Virtualbox, use two network adapter, one is NAT to allow the guest Linux to access Internet, one is “host-only” for Samba.
(8) power up the guest Linux
(9) On Windows host network, look for the name of the Virtual Linux machine. Double click it and provide the name and the password. There you go!

The benefit of doing the above is
(a) calculation results on Linux can be directly accessed from Windows software without copying to the Linux mounted shared folder.
(b) calculation results on Windows can be directly accessed from Linux software without copying to the Windows network shared folder.


Enjoy Lindows/Winux programming!

Install Madagascar (svn 7866) under sage

As I mentioned in the last post, SageMath is a powerful platform for scientific computation integrating your favorite software packages. One of my favorite packages, for example, is Madagascar for seismic data processing and visualization. So I decided to integrate it with sage. I took the following steps:

0. Sage is installed at $SAGE_ROOT
1. unzip one version of Madagascar (in my case it is svn 7866 checked out in Nov 2011). Newer versions should work as well.
2. under the directory of madagascar source, type

sage -sh

to get into the sage shell, followed by

./configure API=python

Sage will automatically configure it with Sage environmental variables and will install it to $SAGE_ROOT/local
4. exit sage shell, and type

sage --scons install

5. now you should find all Madagascar binary executables in $SAGE_ROOT/local/bin together with other binaries files:

x11pen             sfsort            sfplanemis3     sfitaupmo2         sfederiv2d          sfabalance                           mcube
vpwhitepruf        sfsnrstack        sfplanemis2     sfitaupmo          sfdwt97             sfaastack                           optimal
vpvrms             sfsnr             sfplane         sfisolr3           sfdwt               sfTestcdstep                    class.x
vpsg               sfsmstack         sfpick3         sfisolr2one        sfduwt              sfScanCoef                  ipbori                      cws.x
vpreflkine         sfsmoothreg2      sfpick          sfisolr2tau        sfdsr2              pspen                       PolyGUI                     mori.x
vpreflexpt         sfsmoothreg       sfphaserot      sfisolr2           sfdsr               ppmpen                      python2                     nef.x
vpreflector        sfsmoothderLS     sfpfactor2      sfisin2ang         sfdrays             pngpen                      python2-config              poly.x
vppen              sfsmoothder2      sfpetscawefd2d  sfiphase           sfdrayinte          pdfpen                      python-config               mori-11d.x
vpnmotraj          sfsmoothder1      sfpermlr2       sfinvrec1          sfdowmf             oglpen                      python                      nef-11d.x
vplot2png          sfsmoothder       sfpermlr3       sfinvbin1          sfdottest           latex2wiki                  python2.7                   cws-11d.x
vplot2gif          sfsmoothcur       sfpermlr1       sfinvbin           sfdots              jpegpen                     srptool                     class-11d.x
vplot2eps          sfsmooth          sfpen           sfinttest2         sfdonf              gdpen                       certtool                    poly-11d.x
vplot2avi          sfslice           xtpen           sfinttest1         sfdominantf         mayavi2                     gnutls-cli-debug            mori-6d.x
vphyplay           sfslant           sfpefdeburst    sfintshow          sfdomf              tvtk_doc                    psktool                     nef-6d.x
vpheadray          sfsizes           sfpef           sfintervalVTI      sfdoeps             editra                      gnutls-cli                  cws-6d.x
vpfrancis          sfsinc            sfpatch         sfinterpt          sfdmo               helpviewer                  gnutls-serv                 class-6d.x
vpellipse          sfsin             sfparcel        sfinterp2          sfdmeig             img2py                      libgnutls-extra-config      poly-6d.x
vpdcretard         sfsimilarity      sfpad           sfinterleave       sfdixshape          pyalamode                   libgnutls-config            mori-5d.x
vpdc               sfsimenv          sfovc           sfintegral1        sfdix               pycrust                     tconic                      nef-5d.x
vpcsp              sfsignoi          sfopsmigrk      sfintbin3          sfdivn              pywrap                      indep                       cws-5d.x
vpcroshyp          sfsigmoid         sfomp           sfintbin           sfdistmap           img2png                     allisog                     class-5d.x
vpconvert          sfsic3d           sfofsemb        sfint3d            sfdistance          img2xpm                     twist                       poly-5d.x
vpcmp              sfsic             sfofpwd2        sfinstattr         sfdisfil            pyalacarte                  torsion                     mori-4d.x
vp7ab              sfshotprop        sfofpwd         sfinmo3            sfdips              pyshell                     conductor                   nef-4d.x
tiffpen            sfshotholes       sfofilp         sfinmo             sfdiplet            pywxrc                      tate                        cws-4d.x
svgpen             sfshotconstkirch  sfoff2abs3      sfinitial          sfdipfilter         xrced                       findinf                     class-4d.x
sfztrace           sfshot2grid       sfoff2abs       sfinfill           sfdip2              wx-config                   ratpoint                    poly-4d.x
sfzomva            sfshot2cmp        sfofd2_7        sfin               sfdip               wxrc                        mwrank                      vsyasm
sfzomig3           sfshoot2          sfofd2_5        sfimray            sfdimag             wxrc-2.8                    opencdk-config              ytasm
sfzomig            sfshifts          sfofd2_25       sfimpl3            sfdijkstra          vtkpython                   fplll_micro                 yasm
sfzoeppritz        sfshift           sfofd2_13       sfimpl2            sfdiffraction       lproj                       llldiff                     freetype-config
sfzerocross        sfshearer         sfofd2_10       sfimpl1            sfdiffoc            vtkEncodeString             generate                    patch
sfzero             sfsharpsimi       sfofd1_5        sfimospray         sfdifference        vtkWrapPython               fplll_verbose               bzless
sfzcwt             sfsharpen         sfofd1          sfimage            sfdespike3          vtkWrapPythonInit           fplll                       bzcmp
sfxlagtoang2d      sfshapesigk       sfoctentwt      sfimag             sfdespike2          ctest                       sage_singular               bzegrep
sfxcor2d           sfshapebin1       sfocparcel      sfreal             sfdespike           cpack                       Singular                    bzfgrep
sfwmf              sfshapebin        sfoclet         sfigrad            sfderiv             cmake                       singular                    bzdiff
sfwkbjTI           sfshapeagc        sfnsmooth1      sfidempatch        sfdepth2time        ccmake                      LLL                         bzmore

and python files under

$SAGE_ROOT/local/lib/python2.7/site-packages/rsf$ ls    gui             sfbash.pyc        sfjun.pyc       sfplplot.pyc   sftour.pyc
apibak.pyc   sfgee.pyc       sfmain.pyc        sfseplib_compat.pyc        use.pyc        vplot2png.pyc       __init__.pyc    sfbrowaeys.pyc    sfjyan.pyc    sfpsava.pyc            sftrip.pyc       user        sfgeneric.pyc   sfmccowan.pyc     sfslim.pyc      vpplot.pyc
book.pyc     latex2wiki.pyc  sfchen.pyc    sfkourkina.pyc   sfrickettj.pyc          sftriptrace.pyc  version.pyc       sfgodwinj.pyc   sfparvaneh.pyc        sfsongxl.pyc
conf.pyc     path.pyc        sfcuda.pyc      sflcasasan.pyc       sfroman.pyc          sftsai.pyc       vpconvert.pyc   sfivlad.pyc     sfpens.pyc        sfsumain.pyc       prog.pyc        sfeffsilva.pyc       sflexing.pyc      sfsalah.pyc          sfxuxin.pyc      vplot2avi.pyc
doc.pyc     sfjeff.pyc    sfpetsc.pyc   sfsuplot.pyc   proj.pyc        sffomels.pyc   sflibplot.pyc       sfsaragiotis.pyc           sfyliu.pyc       vplot2eps.pyc      recipes     sfjennings.pyc     sfplot.pyc      sftariq.pyc 
flow.pyc       sfgchliu.pyc        sfllisiw.pyc     sfseismic.pyc            tex.pyc          vplot2gif.pyc

Now you can start a sage notebook and text the following code:

import m8r as sf
import numpy, pylab
f = sf.spike(n1=1000,k1=300)[0]
# sf.spike is an operator
# f is an RSF file object
# Inspect the file with sfattr
b = sf.bandpass(fhi=2,phase=1)[f]
# Now f is filtered through sfbandpass
c = sf.spike(n1=1000,k1=300).bandpass(fhi=2,phase=1)[0]
# c is equivalent to b but created with a pipe
g = c.wiggle(clip=0.02,title='Welcome to Madagascar')
# g is a Vplot file object
# Display it on the screen
d = b - c
# Elementary arithmetic operations on files are defined
g = g + d.wiggle(wanttitle=False)
# So are operations on plots
# This shows a movie

The result looks like the following

Link to the Madagascar sage notebook page.

install MayaVi2 under sage (v5.0.1) for 2D/3D interactive visulization

According to Wikipedia, “MayaVi is a scientific data visualizer written in Python, which uses VTK and provides a GUI via Tkinter”, while “Sage (previously SAGE, System for Algebra and Geometry Experimentation[3]) is mathematical software with features covering many aspects of mathematics, including algebra, combinatorics, numerical mathematics, number theory, and calculus”. Under the framework of sage, multiple scientific libraries were combined in order to offer a “open source alternative to Magma, Maple, Mathematica, and MATLAB”. From my point of view, although matplotlib under sage can produce high quality figures, it’s 3D scientific visualization capability can be better improved if MayaVi is included in sage as a package. Unfortunately, till version 5.0.1, sage community does not offer an official spkg package to install MayaVi. Users should either install MayaVi outside of sage using system python or install MayaVi under sage using sage’s own python and other libraries. The former is easy and MayaVi community provides good guidance. The latter can integrates the power of both MayaVi and Sage, but is not straightforward. Information scatters over the world wide web and none provides a systematic treatment. In this blog, I summarize how I installed MayaVi2 (v3.4.0) under sage (v5.0.1). I am aware a newer version of MayaVi (v4.2.0) exists, however, I still don’t know why it doesn’t work under sage v5.0.1. Let me know if you manage to get it work. Now, let’s start to install MayaVi2 under Sage.

0. sage v5.0.1 should be already installed on your system. I use $SAGE_ROOT and $SAGE_LOCAL to denote the path of sage root directory and $SAGE_LOCAL=$SAGE_ROOT/local.
1. make sure cmake is installed in your system. I use cmake 2.8.3 under ubuntu 11.04. Cmake package for sage, such as the one on this page, is not useful in my case. Because cmake under sage can’t find paths for X11 related libraries which are located in both /usr/lib and /usr/local/lib. For this reason, I use cmake outside of sage.
2. download mesa-7.2.spkg, vtk-cvs-20090316osmesa.spkg, configobj-4.5.3.spkg, wxPython- to $SAGE_ROOT.

# install a local osmesa, this will work according to Ondrej and Prabhu:
./sage -i mesa-7.2.spkg


# install the vtk-cvs-... (this is vtk-5.5.x) with modifications from Prabhu
# with osmesa enabled, see above.
# We use -f -m to keep the installation files in spkg/build,
# so we have VTKDATA and other stuff available
./sage -f -m vtk-cvs-20090316osmesa.spkg

5. The above installation will fail. No panic. This is the step to get out of sage. The error message is about python.h is not found. Go to directory: $SAGE_ROOTspkgbuildvtk-cvs-20090316osmesa, and edit file spkg-install. Basically just to change “2.5” to “2.7”. You may tell the age of this spkg. Under Linux shell, change directory to $SAGE_ROOTspkgbuildvtk-cvs-20090316osmesasrcVTKvtk-build and paste the following command:

export $SAGE_ROOT=/your/path/to/sage-5.0.1
export $SAGE_LOCAL=/your/path/to/sage-5.0.1/local

Afterwards, I like to use

ccmake ../

to check all parameters were set properly and all libraries are found. Then I type

make -j2

since I have two CPU cores in my Linux machine, and

make install
cd Wrapping/Python
sage --python install
cd $CWD
cp -a $SAGE_ROOT/local/lib/vtk-5.5/libvtk* $SAGE_ROOT/local/lib

You may tell that I was just following the steps in the spkg-install file, just not running it within sage or sage shell.


# install configobj.spkg, needed by mayavi2 (and all other enthought packages)
./sage -i configobj-4.5.3.spkg


# for now install wxPython
./sage -f -m wxPython.


# at last
./sage -f -m mayavi-3.1.1.rev23224.spk

The end of installation. Now go to sage notebook webpage, and evaluate the following command:

from enthought.mayavi import mlab as M
M.options.offscreen = True

If you should be able to see something like this:

mesh generated by Mayavi2 on sage notebook

Last but not least, you can now generate a x3d file on sage notebook and view it under any brower that has a viewer plugin. In my case I installed freeWRL. You can download the x3d file and view it on your own machine. Here is the source code:

#Test embedding x3d files
from enthought.mayavi import mlab
mlab.options.offscreen = True
import numpy
# A simple triangular mesh
# Some nice vectors.
x, y, z = numpy.mgrid[-2:3,-2:3, -2:3]
r = numpy.sqrt(x**2 + y**2 + z**4)
u = y*numpy.sin(r)/(r+0.001)
v = -x*numpy.sin(r)/(r+0.001)
w = numpy.zeros_like(z)
# Export a x3d file for online 3D viewing.
# FreeWRL ( works great!

a.x3d viewed from freewrl standalone application

The worksheet of sage notebook is published at