Installing MATLAB

Enabling Linux Binary Compatibility
Installing Matlab

These directions are for installing the Linux version of MATLAB 7.0 (R14) under Linux Binary Compatibility. I'll assume that you already have the install CDs, and a valid license.

Enabling Linux Binary Compatibility

The first thing we need to do is install linux binary compatibility. First we need to set a few configuration options. First add the following line to /etc/rc.conf

linux_load=YES

In order to get the latest version of the linux base (which is required for Flash9) add the following line to /etc/sysctl.conf

compat.linux.osrelease=2.6.16

Now in order to make this change happen immediately, run the following command

/etc/rc.d/sysctl start

Finally we need to add an additional option to /etc/make.conf in order to be able to use fedora8 as our linux base.

OVERRIDE_LINUX_BASE_PORT=f8

Now with these preliminaries finished we can move onto installation

cd /usr/ports/emulators/linux_base-f8
make install clean

In order to start compatibility, use the following command:

kldload linux.ko

That will be run automatically everytime you boot with the line we added to rc.conf. Now add the following line to /etc/fstab.

linprocfs /compat/linux/proc linprocfs rw 0 0

Now run the following two commands:

kldload linprocfs
mount /compat/linux/proc

From now on that will be done for you automatically.

Installing Matlab

Now we need to install linux-java. First you'll have to download the linux-java binary from Sun. Accept the license agreement, and download the file j2sdk-1_4_2_10-linux-i586.bin or its closest equivalent. Once downloaded, move the file to /usr/ports/distfiles/. Then we can install linux-java:

cd /usr/ports/java/linux-sun-jdk14
make install clean

Now we can move on to installing MATLAB. When you mount the cds you will have to mount them with executable permissions. Or you can follow my method of copying the contents of the cds to disk, and run the install from there. Either way will work, but I'll walk you through doing it the same way that I did.

cd /usr
mkdir mat mat2 mat3

Now copy all of the contents to those respective directories (mat for cd1, mat2 for cd2, etc).

cd /compat/linux/usr/
mkdir local
cd local
mkdir matlab
cd matlab
mkdir etc
cd etc

That was a slight pain. At this point you will want copy your prepared license.dat file to etc.

cp license.dat /compat/linux/usr/local/matlab/etc

Now that the license is prepared we're ready to begin the install.

cd /compat/linux/usr/local/matlab
/compat/linux/bin/sh /usr/mat/install

Modify that command if you are installing directly off of the cd. For the install itself you will want to take the default installation directory (the directory you are currently in). The rest of the installer is self explanatory. I'll assume the install was successful.

cd /compat/linux/usr/local/matlab/etc
ln -s lmboot /usr/local/etc/lmboot_TMW
ln -s lmdown /usr/local/etc/lmdown_TMW

We just made a few links for files that will be referenced in our license manager script. Now we'll get that script going.

cp rc.lm.glnx86 /usr/local/etc/rc.d/flexlm.sh
cd /usr/local/etc/rc.d/
chmod +x flexlm.sh
vi flexlm.sh

That will give us a good template for the file. We just need to edit a few paths. In the end your file should look like this:

#!/bin/sh
case "$1" in
  start)
        if [ -f /usr/local/etc/lmboot_TMW ]; then
              /compat/linux/bin/sh /usr/local/etc/lmboot_TMW -u xaenn && echo 'MATLAB_lmgrd'
        fi
        ;;
  stop)
    if [ -f /usr/local/etc/lmdown_TMW ]; then
            /compat/linux/bin/sh /usr/local/etc/lmdown_TMW > /dev/null 2>&1
    fi
        ;;
  *)
    echo "Usage: $0 {start|stop}"
    exit 1
    ;;
esac

exit 0

You will want to change xaenn to the appropriate username for your system.

/usr/local/etc/rc.d/flexlm.sh start

For the first time we need to start it manually, but it will happen at startup automatically from now on. Right now we could use MATLAB, but it's a bit cumbersome to invoke, so let's write a quick script.

vi ~/bin/matlab

Add the following lines:

#!/bin/sh
/compat/linux/bin/sh /compat/linux/usr/local/matlab/bin/matlab

As per the FreeBSD Handbook, depending on your version of emulators/linux_base, you may need to edit the matlab script.

vi /compat/linux/usr/local/matlab/bin/matlab

Edit the following line

if [ `expr "$lscmd" : '.*->.*'` -ne 0 ]; then

and replace it with

if test -L $newbase; then

And one final note, sound support has been hit or miss for me. Sometimes it works, and other times it won't. As an alternative you may use the wavwrite function, and then play the output from mplayer. It's not ideal, but it works. Finally, you'll have something nice like this: