18 March 2012

110. Compiling, installing Gnuplot 4.6 on Debian

A new version of gnuplot doesn't happen very often, and this one has an interesting added feature in terms of support for using braces in algorithms.
http://www.gnuplot.info/announce.4.6.0

Building gnuplot 4.6 is similar to building 4.4.4 and is pretty straightforward:

sudo apt-get install libgd2-xpm-dev checkinstall

wget http://sourceforge.net/projects/gnuplot/files/latest/download?source=files
mv download\?source\=files gnuplot-4.6.tar.gz
tar -xvf gnuplot-4.6.tar.gz
cd gnuplot-4.6.0/

./configure --with-linux-vga
make
checkinstall -install=no
 sudo rm /usr/local/share/info/dir -rf
sudo dpkg -i gnuplot_4.6.0-1_amd64.deb

You may get an error if trying to install on a system with a home-compiled version of octave (see below).

The problem with handling small numbers is not present in this version (http://verahill.blogspot.com.au/2012/02/debian-testing-wheezy-64-bug-in-debian.html).


Error:
Selecting previously unselected package gnuplot.
(Reading database ... 258722 files and directories currently installed.)
Unpacking gnuplot (from gnuplot_4.6.0-1_amd64.deb) ...
dpkg: error processing gnuplot_4.6.0-1_amd64.deb (--install):
 trying to overwrite '/usr/local/share/info/dir', which is also in package octave 3.6.1-1
dpkg-deb: error: subprocess paste was killed by signal (Broken pipe)
Errors were encountered while processing:
 gnuplot_4.6.0-1_amd64.deb
Solution:

 sudo dpkg --force-overwrite -i gnuplot_4.6.0-1_amd64.deb

17 March 2012

109. Building Thunderbird 11 on Debian testing

The build is fairly straightforward and pretty much identical to building 10.0.2 (earlybird): http://verahill.blogspot.com.au/2012/02/debian-testing-wheezy-64-building.html

As always, uninstall existing versions before installing a new one.

--start here --
First install the dependencies:
sudo apt-get install libdbus-glib-1-dev gir1.2-notify-0.7 libnotify-dev yasm checkinstall libzip-dev zip 


Download the sources  and untar:
mkdir ~/tmp
cd ~/tmp

wget ftp://ftp.mozilla.org/pub/mozilla.org/thunderbird/releases/11.0/source/thunderbird-11.0.source.tar.bz2
tar -xvf thunder-bird-11.0.source.tar.bz2
cd comm-release/

Start the build
./configure --disable-necko-wifi
make -j3

3 is the number of cores +1. If you have a quadcore CPU substitute 3 with 5. The build takes a while so you will probably want to do a parallel build.

Finally, to install
sudo make install



checkinstall is segfaulting for me.

Error:

/home/me/tmp/comm-release/mozilla/js/src/config/nsinstall -R -m 644 ../mozilla-config.h ../../../config/nsStaticComponents.h  ../../../dist/include
make[5]: /home/me/tmp/comm-release/mozilla/js/src/config/nsinstall: Command not found
make[5]: *** [export] Error 127
make[5]: Leaving directory `/home/me/tmp/comm-release/mozilla/js/src/config'
make[4]: *** [export] Error 2
make[4]: *** Waiting for unfinished jobs....
make[4]: Leaving directory `/home/me/tmp/comm-release/mozilla/js/src'
make[3]: *** [export_tier_js] Error 2
make[3]: Leaving directory `/home/me/tmp/comm-release/mozilla'
make[2]: *** [tier_js] Error 2
make[2]: Leaving directory `/home/me/tmp/comm-release/mozilla'
make[1]: *** [default] Error 2
make[1]: Leaving directory `/home/me/tmp/comm-release/mozilla'
Solution:
I got this error because I accidentally untared the new sources into an existing directory with an older version of thunderbird. The solution was to delete the directory and untar the sources again.


15 March 2012

108. Building local version of sinfo without root/sudo on ROCKS/CentOS

Edit 04/04/2012: there were several errors and omissions. These have been fixed now.

Because I don't want to mess up a cluster which is on a different continent I'm trying to use my superuser powers as little as possible.

Here's how to make a local version of sinfo -- you'll still need to make sinfod runs as a service on all the nodes.

There's no reason the instructions here shouldn't work on most linux distros, including Debian.

boost:
cd ~/tmp
wget http://sourceforge.net/projects/boost/files/boost/1.49.0/boost_1_49_0.tar.gz/download
tar -xvf boost_1_49_0.tar.gz
cd boost_1_49_0/
./bootstrap.sh --prefix=/export/home/me/.libboost


Edit tools/build/user-config.jam and add
using mpi ;
The space between mpi and ; is needed.

Start installation:
./b2 install

cd /export/home/me/.libboost/lib
ln -s libboost_signals.so libboost_signals-mt.so
ln -s libboost_serialization.so libboost_serialization-mt.so
ln -s libboost_date_time.so libboost_date_time-mt.so
ln -s libboost_wserialization.so libboost_wserialization-mt.so
ln -s libboost_regex.so libboost_regex-mt.so


asio:
cd ~/tmp
wget "http://downloads.sourceforge.net/project/asio/asio/1.5.3%20%28Development%29/asio-1.5.3.tar.bz2?r=http%3A%2F%2Fsourceforge.net%2Fprojects%2Fasio%2F&ts=1331441086&use_mirror=aarnet"
tar -xvf asio-1.5.3.tar.bz2
cd asio-1.5.3/

./configure --prefix=/export/home/me/.asio --with-boost=/export/home/me/.libboost/include
make
make install

sinfo/d:
wget http://www.ant.uni-bremen.de/whomes/rinas/sinfo/download/sinfo-0.0.45.tar.gz
tar -xvf sinfo-0.0.45.tar.gz
cd sinfo-0.0.45/

export LIBS=-L/export/home/me/.libboost/lib
export LDFLAGS=$LIBS
export CPPFLAGS="-I/export/home/me/.libboost/include -I/export/home/me/.asio/include/"
./configure --prefix=/export/home/me/.sinfo --disable-IPv6
make

make install 

Getting started:
In order to make something happen at boot you need sudo/root access. However, HPC clusters are rarely rebooted, so even if you launch something as a user it will persist for a long time. If you're lucky the right ports are open -- and they should be open between nodes.

You also need to add this to your ~/.bashrc:
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/export/home/me/.libboost/lib

Start sinfod (the daemon) using:
~/.sinfo/sbin/./sinfod --quiet

ps aux |grep sinfod 
will show it it's running

And check that everything is ok using
~/.sinfo/bin/./sinfo



13 March 2012

107. Fun with gnu screen -- setting up a screenrc

This is going to be a short post.

The problem:
If I have three nodes on a cluster, each with htop installed, how do I set up gnu screen so that it automatically signs in to each node and starts a copy of htop on each node, and display the output in a split window? Basically, how to you open screen instances and inject commands in them?

...like so. Guess which computer is running a full gnome-shell environment...


The solution:
create a file called multitop.screenrc:

screen ssh 192.168.1.101
stuff htop\015
title node01
split
focus
screen ssh 192.168.1.102
title node02
stuff htop\015
split
focus
screen ssh 192.168.1.103
title node03
stuff htop\015
stuff string injects string into the active window. \015 basically injects <enter>.

start screen using
screen -c multitop.screenrc 
and as usual,don't exit using exit or q, but use C+a - d to leave it running.


To make things a bit prettier and to enable users to reconnect to a running session, edit /etc/screenrc:

multiuser on
acladd me
defscrollback 5432
termcapinfo xterm|xterms|xs|rxvt ti@:te@
caption     always        "%{+b rk}%H%{gk} |%c %{yk}%d.%m.%Y | %72=Load: %l %{wk}"
hardstatus alwayslastline "%?%{yk}%-Lw%?%{wb}%n*%f %t%?(%u)%?%?%{yk}%+Lw%"
and
sudo chmod +s /usr/bin/screen
sudo chmod 755 /var/run/screen


If you start a session using e.g.
screen -S mytest
as user me

then other users can connect using
screen -x me/mytest

106. htop 1.0.1 and sinfo-0.0.45 on rock 5.4.3/centos 5.6

There are a number of performance monitor tools in the debian repos. ROCKS 5.4.3/Centos doesn't seem quite as well-equipped.

First out, htop:

htop:
wget http://downloads.sourceforge.net/project/htop/htop/1.0.1/htop-1.0.1.tar.gz
tar -xvf htop-1.0.1.tar.gz
cd htop-1.0.1/
./configure --prefix=/home/me/.htop
make
make install

It's as simple as that.
Add e.g.
alias htop='/home/me/.htop/bin/htop'
to your ~/.bashrc
Note: this works on Scientific Linux (boron) 5.4 as well.

sinfo:
Update 13/03/2012:
Sinfo <0.0.44 has IPv6 enabled by default.
On sinfo >=0.0.45 you can disable IPv6 using ./configure --disable-IPv6

Sinfo is probably the snazziest cluster monitoring tool that I know of. Sure, ganglia etc. are nice too, but they run as web service. Sinfo is a 'simple' curses program, but building it on CentOS was a bit of a challenge.

Be aware that sinfo versions prior to 0.045 expect ipv6 to work -- by default ROCKS disables IPv6, so use sinfo 0.0.45 and above.





First boost:
(yum install boost-devel didn't do anything for me)
cd ~/tmp
wget http://sourceforge.net/projects/boost/files/boost/1.49.0/boost_1_49_0.tar.gz/download
tar -xvf boost_1_49_0.tar.gz
cd boost_1_49_0/
./bootstrap.sh --prefix=/usr

Edit Jamroot and add
using mpi ;
The space between mpi and ; is needed.

Symlink to your mpic++, e.g. if your mpic++ is in /opt/openmpi:
sudo ln -s /opt/openmpi/bin/mpic++ /usr/bin/mpic++

The following step takes a long time:
sudo ./b2 -a install --layout=versioned --build-type=complete

These days all the libboost libs are multithread aware (or so I hear), and in debian it turns out that the -mt.so libs are just symbolic links to the 'regular' libs.
sudo ln -s /usr/lib/libboost_signals.so /usr/lib/libboost_signals-mt.so
sudo ln -s /usr/lib/libboost_date_time.so /usr/lib/libboost_date_time-mt.so
sudo ln -s /usr/lib/libboost_serialization.so /usr/lib/libboost_serialization-mt.so
sudo ln -s /usr/lib/libboost_wserialization.so /usr/lib/libboost_wserialization-mt.so
sudo ln -s /usr/lib/libboost_regex.so /usr/lib/libboost_regex-mt.so

sudo ln -s /usr/lib/libboost_signals.so.1.49.0 /usr/lib64/libboost_signals.so.1.49.0

Then asio
cd ~/tmp
wget "http://downloads.sourceforge.net/project/asio/asio/1.5.3%20%28Development%29/asio-1.5.3.tar.bz2?r=http%3A%2F%2Fsourceforge.net%2Fprojects%2Fasio%2F&ts=1331441086&use_mirror=aarnet"
tar -xvf asio-1.5.3.tar.bz2
cd asio-1.5.3/
./configure
make
sudo make install

Then sinfo
cd ~/tmp
wget http://www.ant.uni-bremen.de/whomes/rinas/sinfo/download/sinfo-0.0.45.tar.gz
tar -xvf sinfo-0.0.45.tar.gz
cd sinfo-0.0.45/
./configure --disable-IPv6

The build should be fine.

Configuration:
you'll end up with
/usr/local/sbin/sinfod
/usr/local/bin/sinfo
You may want to make sure there are paths to them by adding the following to your ~/.bashrc:
export PATH=$PATH:/usr/local/bin:/usr/local/sbin
The changes take effect next time you log in to a shell, or just run
source ~/.bashrc
for immediate effect.

Also, create a file called /etc/default/sinfo with the following in it:
OPTS="--quiet --bcastaddress=192.168.1.255"

Start sinfod with
sinfod --quiet --bcastaddress=192.168.1.255

then check that it's running
ps aux | grep sinfod

If it's not running, then try
sinfod -F

If it gives something along the lines of
exception:open:address family not supported
you most likely
1) haven't enabled ipv6 for your interface and
2) didn't disable IPv6 during compilation and/or
3) used version<0.045

Check by doing ifconfig -- does it return both an ipv4 and an ipv6 address?

Enabling ipv6
Unless you know what you're doing, don't fiddle with the network interfaces on a production cluster -- network interfaces on a multinode cluster are typically highly tuned to minimise latency, so don't mess it up.

Anyway. First check your /etc/modules.conf and - if present - comment out
alias ipv6 off
options ipv6 disable=1
Edit your /etc/sysconfig/network-scripts/ifcfg-eth1
DEVICE=eth1:0
IPADDR=192.168.1.111
NETMASK=255.255.255.0
BOOTPROTO=none
MTU=1500
TYPE=Ethernet
GATEWAY=192.168.1.1
USERCTL=no
IPV6INIT=yes
PEERDNS=yes
ONPARENT=yes
IPV6ADDR=fe80::2f0:4dff:f383:b44/64
IPV6_DEFAULTGW=fe80::2f0:4dff:fe83:a48/64
I just made up the IPV6ADDR, and took the IPV6_DEFAULTGW from my gateway machine (running debian, so ipv6 enabled by default)

Assuming that your firewall is allowing traffic at port 60003 and free traffic in and out on 192.168.1.255 things should work fine.



Errors


Error (boost):
MPI auto-detection failed: unknown wrapper compiler mpic++
Please report this error to the Boost mailing list: http://www.boost.org
You will need to manually configure MPI support.
Solution:
make sure you've symlinked to your mpic++ instance in /usr/bin
e.g. if your mpic++ is in /opt/openmpi/bin/mpic++
sudo ln -s /opt/openmpi/bin/mpic++ /usr/bin/mpic++


Error (sinfo):
message.cc: In member function 'void Message::popFrontMemory(void*, size_t)':
message.cc:183: error: 'memory' was not declared in this scope
message.cc:193: error: 'boost' has not been declared
message.cc:193: error: expected primary-expression before 'char'
message.cc:193: error: expected `;' before 'char'
message.cc:196: error: 'newMemory' was not declared in this scope
message.cc:196: error: 'memory' was not declared in this scope
make[2]: *** [message.lo] Error 1
make[2]: Leaving directory `/state/partition1/home/me/tmp/sinfo-0.0.44/libmessage'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/state/partition1/home/me/tmp/sinfo-0.0.44/libmessage'
make: *** [all-recursive] Error 1
Solution:
You need to make sure that the libs are found -- either symlink manually between your build directory and /usr/lib, or use boostrap.sh --prefix=/usr. See above for how to do it.

Error (sinfo):
udpmessagereceiver.h:14: error: 'asio' has not been declared
udpmessagereceiver.h:14: error: ISO C++ forbids declaration of 'endpoint' with no type
udpmessagereceiver.h:14: error: expected ';' before 'sender_endpoint'
udpmessagereceiver.h:16: error: 'asio' has not been declared
udpmessagereceiver.h:16: error: ISO C++ forbids declaration of 'io_service' with no type
udpmessagereceiver.h:16: error: expected ';' before '&' token
udpmessagereceiver.h:17: error: 'asio' has not been declared
udpmessagereceiver.h:17: error: ISO C++ forbids declaration of 'socket' with no type
udpmessagereceiver.h:17: error: expected ';' before 'sock'
udpmessagereceiver.h:20: error: expected ',' or '...' before '::' token
udpmessagereceiver.h:20: error: ISO C++ forbids declaration of 'asio' with no type
udpmessagereceiver.h:23: error: 'asio' has not been declared
udpmessagereceiver.h:23: error: expected `)' before '&' token
udpmessagereceiver.cc:5: error: 'asio' has not been declared
udpmessagereceiver.cc:5: error: expected `)' before '&' token
make[1]: *** [udpmessagereceiver.lo] Error 1
make[1]: Leaving directory `/state/partition1/home/me/tmp/sinfo-0.0.44/libmessageio'
make: *** [all-recursive] Error 1

Solution: you've only got boost::asio installed, not the independent asio. See above for how to compile and install asio.

Error (sinfo):

/usr/bin/ld: cannot find -lboost_signals-mt
collect2: ld returned 1 exit status
make[2]: *** [sinfod] Error 1
make[2]: Leaving directory `/state/partition1/home/me/tmp/sinfo-0.0.44/sinfod'
make[1]: *** [all] Error 2
make[1]: Leaving directory `/state/partition1/home/me/tmp/sinfo-0.0.44/sinfod'
make: *** [all-recursive] Error 1
Solution:
You need a symlink pointing form /usr/lib/libboost_signals-mt.so to /usr/lib/libboost_signals.so
ln -s /usr/lib/libboost_signals.so /usr/lib/libboost_signals-mt.so 

Error (sinfod):
sinfod --quiet --bcastaddress=192.168.1.255 gives nothing and sinfod exits silently immediately
sinfod -F gives
exception:open:address family not supported
Here's the relevant strace output:
[..]
 socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP) = 6
[..]
 socket(PF_INET6, SOCK_DGRAM, IPPROTO_UDP) = -1 EAFNOSUPPORT (Address family not supported by protocol)
futex(0x333a40d350, FUTEX_WAKE_PRIVATE, 2147483647) = 0
close(6)                                = 0
close(3)                                = 0
close(4)                                = 0
close(5)                                = 0
write(2, "Exception: ", 11)             = 11
write(2, "open: Address family not support"..., 46) = 46
write(2, "\n", 1)                       = 1
exit_group(0)                           = ?

Solution: enable ipv6 (see above)

105. Nwchem 6.1 with openmpi on ROCKS 5.4.3/CentOS 5.6


EDIT 18 May 2012: 
Compiling nwchem 6.1 with internal libs on debian: http://verahill.blogspot.com.au/2012/05/compiling-nwchem-61-with-internal-libs.html
Compiling nwchem 6.1 with openblas on debian: http://verahill.blogspot.com.au/2012/05/building-nwchem-61-on-debian.html


I can build and use nwchem on ROCKS 5.4.3 -- see instructions below.

EDIT: the gfortran version is GNU Fortran (GCC) 4.1.2 20080704 (Red Hat 4.1.2-50)
On debian, which yields a segfaulting binary, the version is GNU Fortran (Debian 4.6.3-1) 4.6.3

I'm still having no luck building binaries which don't segfault on execution on debian though. The openmpi versions are the same for both ROCKS and debain: 1.4.3.

--START HERE --

ROCKS 5.4.3/CentOS
The build is essentially the same as for nwchem-6.0 (http://verahill.blogspot.com.au/2012/03/building-nwchem-60-on-rocks-543centos.html) - the single difference is that you need to define USE_MPIF4 or you get errors

To build:

wget http://www.nwchem-sw.org/images/Nwchem-6.1-2012-Feb-10.tar.gz
tar -xvf Nwchem-6.1-2012-Feb-10.tar.gz
cd nwchem-6.1/
export LARGE_FILES=TRUE
export TCGRSH=/usr/bin/ssh
export NWCHEM_TOP=/export/home/me/tmp/nwchem-6.1
export NWCHEM_TARGET=LINUX64
export NWCHEM_MODULES=all
export USE_MPI=y
export USE_MPIF=y
export USE_MPIF4=y
export MPI_LOC=/opt/openmpi
export MPI_INCLUDE=/opt/openmpi/include
export LIBRARY_PATH=$LIBRARY_PATH:/opt/openmpi/lib
export LIBMPI="-lmpi -lopen-rte -lopen-pal -ldl -lmpi_f77 -lpthread"
cd $NWCHEM_TOP/src
make clean
make  nwchem_config
make  FC=gfortran

Building takes a little while.

Running:
Make sure that you make the reference to your openmpi libs permanent and make life easier by putting the following in your ~/.bashrc or /etc/profile:

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/openmpi/lib

export NWCHEM_EXECUTABLE=/export/home/me/tmp/nwchem-6.1/bin/LINUX64/nwchem
export NWCHEM_BASIS_LIBRARY=/export/home/me/tmp/nwchem-6.1/src/basis/libraries/
PATH=$PATH:/export/home/me/nwchem-6.1/bin/LINUX64



To run on multiple procs do
mpirun -n 3 nwchem input.nw
where 3 is the number of cores

104. Building gromacs with fftw3 and openmpi on ROCKS 5.4.3/CentOS

This guide was heavily modified on 13/03/2012 to remove the need for sudo/root privileges.

Not all flavours of linux are equal. I've always been a Debian man, but have recently become a user of a ROCKS based HPC cluster on a different continent. To make sure that I don't screw things up I'm currently trying to work out how to reliably compile common computational packages under ROCKS 5.4.3, which is CentOS based.

If you installed the bio roll from the beginning you'll have openmpi in /opt/openmpi (rocks_openmpi.x86_64 package), and fftw in /opt/rocks/lib and /opts/rocks/include (fftw.x86_64 package)

If you only installed the basic rolls, you won't have either. Now, you can either download the bio roll and install from there, or you can install the regular openmpi package and compile fftw yourself. In fact, you'll need to do the latter if you want double-precision gromacs anyway.

My goal is to avoid having to use sudo or root at all. I've rewritten this guide a couple of times, so there may be weird annoying errors that I've missed.

Installing openmpi:
If you don't have openmpi in /opt, then you can install it from the base roll
sudo yum install openmpi


fftw3:
You can skip this step IF
1. you have fftw files in /opt/rocks/lib and /opt/rocks/include
AND
2. you only want single precision

Otherwise:

wget http://www.fftw.org/fftw-3.3.1.tar.gz
tar -xvf fftw-3.3.1.tar.gz
cd fftw-3.3.1


Then use --prefix to tell make where to install the files:

Single precision fftw3 libraries:
make distclean
./configure --enable-float --enable-mpi --enable-threads --with-pic --prefix=/export/home/me/.fftwsingle
make
make install

Double-precision fftw3 libraries:
make distclean
./configure --disable-float --enable-mpi --enable-threads --with-pic --prefix=/export/home/me/.fftwdouble
make 
make install

gromacs:

First download and extract:

cd ~/tmp
wget ftp://ftp.gromacs.org/pub/gromacs/gromacs-4.5.5.tar.gz

tar -xvf gromacs-4.5.5.tar.gz
cd gromacs-4.5.5/

Before building you need to define where the openmpi libs are i.e.
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/openmpi/lib
OR
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib64/openmpi/1.4-gcc/lib

We now have three permutations of possible builds:
1. We use the single precision fftw libs in /opt/rocks/lib and /opt/rocks/include
export LDFLAGS=-L/opt/rocks/lib
export CPPFLAGS=-I/opt/rocks/include
./configure --enable-mpi --enable-float --with-fft=fftw3 --program-suffix=_spmpi --prefix=/export/home/me/gromacs
make
make install

2. We use the single precision fftw libs in /export/home/me/.fftwsingle

export LDFLAGS=-L/export/home/me/.fftwsingle/lib
export CPPFLAGS=-I/export/home/me/.fftwsingle/include
./configure --enable-mpi --enable-float --with-fft=fftw3 --program-suffix=_spmpi --prefix=/export/home/me/gromacs
make
make install

3. We use the double precision fftw libs in /export/home/me/.fftwdouble

export LDFLAGS=-L/export/home/me/.fftwdouble/lib
export CPPFLAGS=-I/export/home/me/.fftwdouble/include
./configure --enable-mpi --disable-float --with-fft=fftw3 --program-suffix=_ddmpi --prefix=/export/home/me/gromacs
make
make install


Running

You will now have single and double-precision binaries, e.g.
grompp_spmpi and grompp_ddmpi

Make sure that you define/have defined LD_LIBRARY_PATH in /etc/profile or ~/.bashrc and included the paths to your mpi libs and your fftw libs, e.g.:
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/openmpi/lib:/export/home/me/.fftwsingle:/export/home/me/.fftwdouble

Actually, it doesn't seem necessary to include the fftw path.

You may also want to include your gromacs bins in your path:
export PATH=$PATH:/export/home/me/gromacs/bin

Dynamic load-balancing seems to be disabled by default, so to use multiple cores run using e.g.
mpirun -n 4 mdrun_spmpi -s inp.tpr -o out.trr etc.

DONE


Troubleshooting

Error:
checking size of off_t... configure: error: in `/export/home/me/tmp/gromacs-4.5.5':
configure: error: cannot compute sizeof (off_t)
See `config.log' for more details
config.log:
./conftest: error while loading shared libraries: libmpi.so.0: cannot open shared object file: No such file or directory
Solution:
Set LD_LIBRARY_PATH to your openmpi libs e.g.
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/openmpi/lib

Error:
/usr/local/lib/libfftw3f.a: could not read symbols: Bad value
collect2: ld returned 1 exit status
make[3]: *** [libmd.la] Error 1
Solution:
Compile fftw3 using the --with-pic switch:
./configure --enable-float --enable-mpi --enable-threads --with-pic 




103. Building nwchem 6.0 on Rocks 5.4.3/CentOS

I've always been a Debian man, but for various reasons I need to be able to compile various scientific packages on a HPC running ROCKS. ROCKS 5.4.3 is based on CentOS 5,6and it turns out that debian is wonderfully easy, accommodating and robust in comparison. Well, since it's not my HPC, CentOS is what I'm stuck with.

Here's how to build nwchem on a rocks 5.4.3 (viper) cluster based on CentOS 5.6 and its ancient kernel.
(Linux  2.6.18-238.19.1.el5 #1 SMP Fri Jul 15 07:31:24 EDT 2011 x86_64 x86_64 x86_64 GNU/Linux )

There are three different approaches:




CASE 1.
 Using LD_LIBRARY_PATH
This method requires no root access.
Check to see whether you've installed the rocks-openmpi package from the bio roll - it should be in /opt/openmpi. Otherwise use yum to install the base-roll openmpi package, which will end up in /usr/lib64/openmpi/1.4-gcc/lib -- you'll need root or sudo to do anything with yum.

For compilation, do
export LIBRARY_PATH=$LIBRARY_PATH:/opt/openmpi/lib
or
export LIBRARY_PATH=$LIBRARY_PATH:/usr/lib64/openmpi/1.4-gcc/lib/
depending on whether there is an openmpi directory in /opt or not.

You can also put the export line in your buildconf.sh below
For execution:
in either you ~/.bashrc (user basis) or /etc/profile (global) put
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/openmpi/lib






CASE 2. /opt/openmpi is present; using symlinked libs

mpicc and mpif77 are probably already symlinked, but if not:

sudo ln -s /opt/openmpi/bin/mpicc /usr/bin/mpicc
sudo ln -s /opt/openmpi/bin/mpif77 /usr/bin/mpif77


The following allows for building and running:
sudo ln -s /opt/openmpi/lib/libmpi.so /usr/lib/libmpi.so
sudo ln -s /opt/openmpi/lib/libopen-rte.so /usr/lib/libopen-rte.so
sudo ln -s /opt/openmpi/lib/libopen-pal.so /usr/lib/libopen-pal.so
sudo ln -s /opt/openmpi/lib/libmpi_f77.so /usr/lib/libmpi_f77.so
sudo ln -s /opt/openmpi/lib/libmpi.so /usr/lib64/libmpi.so.0
sudo ln -s /opt/openmpi/lib/libopen-rte.so /usr/lib64/libopen-rte.so.0
sudo ln -s /opt/openmpi/lib/libopen-pal.so /usr/lib64/libopen-pal.so.0
sudo ln -s /opt/openmpi/lib/libmpi_f77.so /usr/lib64/libmpi_f77.so.0


the /usr/lib64 symlinks are necessary for execution, or you'll get
./nwchem: error while loading shared libraries: libmpi.so.0: cannot open shared object file: No such file or directory



CASE 3. /opt/openmpi is NOT present; using symlinked libs

yum install openmpi openmpi-devel
And then put in all the symlinks...dunno why this isn't done on install, but there you go.

sudo ln -s /usr/local/lib64/openmpi/1.4-gcc/bin/mpicc  /usr/bin/mpicc
sudo ln -s /usr/local/lib64/openmpi/1.4-gcc/bin/mpif77 /usr/bin/mpif77
sudo ln -s /usr/lib64/openmpi/1.4-gcc/lib/libmpi.so /usr/lib/libmpi.so
sudo ln -s /usr/lib64/openmpi/1.4-gcc/lib/libopen-rte.so /usr/lib/libopen-rte.so
sudo ln -s /usr/lib64/openmpi/1.4-gcc/lib/libopen-pal.so /usr/lib/libopen-pal.so
sudo ln -s /usr/lib64/openmpi/1.4-gcc/lib/libmpi_f77.so /usr/lib/libmpi_f77.so

Using the above symlinks compilation will work just fine.
However, in order to actually run nwchem you need
sudo ln -s /usr/lib64/openmpi/1.4-gcc/lib/libmpi.so /usr/lib64/libmpi.so.0
sudo ln -s /usr/lib64/openmpi/1.4-gcc/lib/libopen-rte.so /usr/lib64/libopen-rte.so.0
sudo ln -s /usr/lib64/openmpi/1.4-gcc/lib/libopen-pal.so /usr/lib64/libopen-pal.so.0
sudo ln -s /usr/lib64/openmpi/1.4-gcc/lib/libmpi_f77.so /usr/lib64/libmpi_f77.so.0

or you'll get
./nwchem: error while loading shared libraries: libmpi.so.0: cannot open shared object file: No such file or directory
Finally, make sure we can find our mpirun:
sudo ln -s /usr/lib64/openmpi/1.4-gcc/bin/mpirun /usr/bin/mpirun


ALL CASES
Continue here:
We'll be working in /export/home/me/tmp
wget http://www.nwchem-sw.org/images/Nwchem-6.0.tar.gz
tar -xvf Nwchem
cd nwchem-6.0

create a file called buildconf.sh and stuff it with the following:
export LARGE_FILES=TRUE
export TCGRSH=/usr/bin/ssh
export NWCHEM_TOP=/export/home/me/tmp/nwchem-6.0
export NWCHEM_TARGET=LINUX64
export NWCHEM_MODULES=all
export USE_MPI=y
export USE_MPIF=y
export MPI_LOC=/usr/lib64/openmpi/1.4-gcc/lib
export MPI_INCLUDE=/usr/lib64/openmpi/1.4-gcc/include
export LIBMPI="-lmpi -lopen-rte -lopen-pal -ldl -lmpi_f77 -lpthread"
cd $NWCHEM_TOP/src
make clean
make nwchem_config
make FC=gfortran
NOTE: the above buildconf.sh works for the case when you installed openmpi yourself (CASE 2 or 3). If it got installed with ROCKS on setup and is present in /opt/openmpi (CASE 1 or 3) change the following:

export MPI_LOC=/opt/openmpi/lib
export MPI_INCLUDE=/opt/openmpi/include
Launch the build

sh buildconf.sh

You'll end up with a binary called nwchem in nwchem--6.0/bin/LINUX64 -- you can put a PATH to it in your ~/.bashrc


CASE 3
For execution you will need to make sure nwchem can find the openmpi libs --
echo $LD_LIBRARY_PATH
will tell you whether the path is included by default.
Otherwise, in either you ~/.bashrc (user basis) or /etc/profile (global) put
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/openmpi/lib


Running
If you move nwchem out of the compilation directory (to say /usr/local/nwchem) you may also want to define e.g.

export NWCHEM_TOP=/usr/local/nwchem-6.0
export NWCHEM_TARGET=LINUX64
export NWCHEM_BASIS_LIBRARY=${NWCHEM_TOP}/libraries/

Again, this goes into your .bashrc or /etc/profile, depending on scope.

To use multiple cores, do
mpirun -n 4 nwchem jobname.nw
where the number of cores is 4.


Errors and troubleshooting:
If you get errors about libraries missing or mpicc-related errors you should make sure that you've symlinked everything you need into the /usr/lib folder or set the LIBRARY_PATH (see above). You could probably edit /etc/ld.conf too, but it will get messy with time.

I also tried building using mpich2-1.2 as well as 1.4, but got error messages about undefined references left and right.

12 March 2012

102. Gnu Debugger (dgb) on CentOS/ROCKS 5.4.3

For a distro dedicated to HPC ROCKS seems to lack every single debugging tool that I'm familiar with. Here's another one: gdb

 --START HERE --


First compile texinfo:
cd ~/tmp
wget http://ftp.gnu.org/gnu/texinfo/texinfo-4.12.tar.gz
tar -xvf texinfo-4.12.tar.gz
cd texinfo-4.12/
./configure
make
sudo make install


ln -s /usr/loca/bin/makeinfo /usr/bin/makeinfo

Then gdb:
cd ~/tmp
wget http://ftp.gnu.org/gnu/gdb/gdb-7.4.tar.gz
tar -xvf gdb-7.4.tar.gz
cd gdb-7.4/
./configure
make
sudo make install

If you haven't symlinked makeinfo above you'll get errors.

Usage:
gdb programme
(gdb) run arg1 arg2



101. First adventures in ROCKS 5.4.3

I've recently been given access to a 40 core cluster running ROCKS 5.4.3, which is a customised version of CentOS 5.6. The notes below are older than the build instructions that I've recently posted.

They say that if you want to learn Debian, use Debian; if you want to learn CentOS, use CentOS, and if you want to learn linux, build LFS. I can't vouch for the last item (yet...), but I'd definitely agree with the first two statements. CentOS and Debian are just different enough that it takes a while before you find your way around CentOS if you're used to Debian.

Anyway, with the hope that this might be useful to someone in a similar situation:

Installation
The ROCKS installer is crap. There's no way around it.
Anyway, the first time you boot up from the CD or DVD you get this splash screen (this is from an earlier vbox installation):


You better type
build
quickly or you'll end up in a dead window.

There's an annoying question about the fully qualified domain name -- and it won't accept invalid FQDNs  -- which will screw things up later if you want to change it. I'll leave that one as a challenge.

Assuming you typed build, and everything worked ok up to this point (how about a 'back' button?), you get to choose whether to partition manually or automatically -- with debian I always do it manually, because why not?

Well, with ROCKS it took me a number of tries before I got it right -- and if you get it wrong it crashes and YOU HAVE TO START OVER AGAIN. How about having a 'back' button and clearly displaying the minimum requirements in the gparted screen? To be fair, it's mentioned if you read the instructions on the rocksclusters.org website, but who'd do that?

Anyway, it seems that you need, at a minimum:
16GB : /
3.6 GB: /var
The rest of the disk > 4 GB : /state/partition1 OR /export/home
Either seems to work

Keep that in mind if you're making a virtual machine image -- you'll need a pretty darn big one.

Anyway, presuming that everything works out you'll finish the installation and you'll get to your first boot.

First boot:
There are a few things that I don't like about the default setup

Create your locate database
As root:
updatedb

Create a user
By default there's only root -- apart from preferring to gain superuser powers via sudo, we most definitely need to have normal users present too.
adduser verahill
passwd verahill
To log in immediately
su verahill

First time you log in it will create an RSA keypair -- you're asked to set passwords for the keys -- don't confuse that password with your user password (although it can be the same).

Oh, and change those ugly b/w terminal colours to e.g. fg #FCF2F2 and bg #0E0C56 (this is more a hint for my future self)

Give your user superuser powers:
As root
visudo
and add
verahill ALL=(ALL:ALL) ALL

That'll do the trick
 
/etc/fstab
fstab uses labels by default to keep track of partitions. I don't like labels, and I don't like relative paths, when you can use UUID.
LABEL=/                 /                       ext3    defaults        1 1
LABEL=statepartition1       /state/partition1       ext3    defaults        1 2
LABEL=var       /var                    ext3    defaults        1 2

LABEL=SWAP-sda3         swap                    swap    defaults        0 0
and change to
UUID=779c8a5f-db6a-4433-a3e0-eaf4519e14b1                 /                       ext3    defaults        1 1
UUID=82835cfc-8b86-40b3-9412-f908908714be       /state/partition1       ext3    defaults        1 2
UUID=e286acd2-49cd-437b-bb1d-682faacb0628       /var                    ext3    defaults        1 2



To findout the UUIDs, do
 ls /dev/disk/by-uuid/ -lah
and to map the relative paths to the labels do  
ls /dev/disk/by-label/ -lah
I couldn't find the swap uuid, but I'm not too bothered by that. The example in the screenshot is more complex because I'm dualbooting using two physical harddrives.




/boot/grub/menu.lst
Again, a label tells grub where to find the root partition. No good. Change to UUID instead. Also, comment out hiddenmenu and change quiet to splash. It's grub '1', so you don't need to do update-grub or anything like that to make the changes take effect.

 screen
sudo yum install screen
 Just do the usual -- add  the following to /etc/screenrc
multiuser on
acladd verahill
and
sudo chmod +s /usr/bin/screen
sudo chmod 755 /var/run/screen

/etc/network/interfaces etc.
Well, they don't exist. Instead, you should go to /etc/sysconfig/network-scripts/
Each interface is configure by creating a file called ifcfg-ethX
You can set device specific routing using a file called route-ethX -- the route in the screen grab was to make sure that all traffic went via my gateway server.

Just look at the screen grab:

Oh, and it's not sudo service networking restart, it's sudo service network restart.

There's no /etc/hostname, instead it seems that you edit /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=roxy

Also, you edit /etc/hosts.local, not /etc/hosts
192.168.1.111   roxy
192.168.2.111   foxy
(not easy coming up with names when you have 9 wired ifs in the same office)


I edited /etc/resolv.conf and added my DNS hosts directly -- so far, so good.

Enable ipv6
at the moment it seems that sinfo/d requires ipv6 to be enabled.  And by default it isn't -- change your modprobe to this (i.e. comment out anything about ipv6)

alias eth0 r8169
alias scsi_hostadapter sata_nv
alias net-pf-10 off
#alias ipv6 off
#options ipv6 disable=1
alias eth1 forcedeth
Yum
Compared to apt it's more yuck than yum, but each to their own.
It's pretty straightforward:
yum check-updates
yum install screen
yum erase screen
yum provides /screen
etc.

The repos seem to be defined in /etc/yum.conf


chkconfig
There's no rcconf or sysv-rc-conf, but there's chkconfig:
Be aware that run levels are not the same in CentOS as in Debian: http://www.centos.org/docs/5/html/Installation_Guide-en-US/s1-boot-init-shutdown-sysv.html

Typically you'd be in 3 or 5.

/opt
A lot of what you'll need for scientic endeavours is found in /opt IF YOU INSTALLED EVERYTHING FROM THE BEGINNING:
If you didn't, and e.g. installed openmpi by yourself, then it'll be in a completely different place. You'll be using locate a lot...

For some reason nothing's symlinked from /usr/lib and /usr/lib64, so be prepared to be doing a lot of that by hand (see my posts on build nwchem, sinfo and gromacs on centos/rocks)

/etc/profile
you might want to add
export PATH=$PATH:/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin



A bit of a restart and you might have a usable system.

100. Compile strace on ROCK 5.4.3

Maybe I've set things up wrong, but I can't find any strace package in the yum repos on my ROCKS 5.4.3 installation.

The compilation is very easy, but I'll show it here for those who feel nervous about compiling their own programmes:

mkdir ~/tmp
cd ~/tmp

The wget takes a while to figure out where to download from -- be patient:
wget http://sourceforge.net/projects/strace/files/latest/download?source=files
unxz strace-4.6.tar.xz
tar -xvf strace-4.6.tar
cd strace-4.6/
./configure
make
sudo make install


How to use:
While I've spent a couple of years with Debian I'm a CentOS newbie, and I keep being confused about the location of the libs -- for my compiles I need to put libs in /usr/lib, but to execute I seem to need to put symlinks in /usr/lib64. strace can help you track where a program is looking for its libs

e.g. to see what the program sinfo is up to
 strace -o sinfo.log sinfo

Here is a snippet from sinfo.log:

open("/lib64/libc.so.6", O_RDONLY)      = 3
open("/usr/local/lib/sinfo/librt.so.1", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/opt/openmpi/lib/librt.so.1", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/lib64/librt.so.1", O_RDONLY)     = 3
open("/usr/local/lib/sinfo/libdl.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/opt/openmpi/lib/libdl.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/lib64/libdl.so.2", O_RDONLY)     = 3

You can see that it e.g. looks for libdl.so.2 first in /usr/local/lib/sinfo, then in /opt/openmpi/lib/ and finally finds it in /lib64

09 March 2012

97. Adjusting webcam sensitivity/brightness on linux

The past year I've had problems with web cams on debian -- some of them look fine, some are way too dark, but either way, I had no good method of adjusting any of the settings. Cheese could be used for some settings, but it's not enough.

Yesterday I was greeted with this image:



While I could probably let in a bit more light in my office, it's still on the dark side...

There are command line tools for adjusting v4l devices (e.g. v4l-conf), but in this particular case a GUI tool would come in handy -- v4l2ucp. It can be installed from the standard debian repos.


Auto Gain can't be turned off for the zc3xx driver. Turns out that the "Light frequency filter" was set to no flicker by default. Changing it to 50 or 60 Hz lead to the image below:


The number of settings you can change depends on your driver --  below is the v4l2ucp window for an integrated thinkpad webcam:


08 March 2012

96. Building a real-time kernel (3.2.9) on debian testing

Building an RT kernel is not terribly different from building a vanilla kernel:http://verahill.blogspot.com.au/2012/03/debian-testing-kernel-329.html

The main differences are:
1. the application of the relevant RT kernel patch
2. the configuration of RT specific kernel options

The latter step requires reading up on what an RT kernel does differently from a vanilla kernel, and the configuration will depend on your application.

The value of this guide is fairly small, since you wouldn't typically use an RT kernel on a desktop, but on a dedicate server or embedded system. I'm still working on a cross-compiling guide for non-x86 architectures.

In addition, having an RT kernel is only the first step -- it needs to be used in the correct way to allow for prioritising processes/pre-emptive execution in an efficient way. An overview for a particular application is given here: http://wiki.linuxmusicians.com/doku.php?id=system_configuration

Briefly,
sudo apt-get install kernel-package fakeroot
wget http://www.kernel.org/pub/linux/kernel/v3.0/linux-3.2.9.tar.bz2
wget http://kernel.org/pub/linux/kernel/projects/rt/3.2/patches-3.2.9-rt17.tar.bz2
tar -xvf linux-3.2.9.tar.bz2
cd linux-3.2.9/
bzcat ../patches-3.2.9-rt17.tar.bz2 |patch -p1
cat /boot/config-`uname -r` .config
make oldconfig

You get to answer a number of questions relating to real-time OS execution

  1. No Forced Preemption (Server) (PREEMPT_NONE)
> 2. Voluntary Kernel Preemption (Desktop) (PREEMPT_VOLUNTARY)
  3. Preemptible Kernel (Low-Latency Desktop) (PREEMPT__LL) (NEW)
  4. Preemptible Kernel (Basic RT) (PREEMPT_RTB) (NEW)
  5. Fully Preemptible Kernel (RT) (PREEMPT_RT_FULL) (NEW)
choice[1-5]: 4
[..]
 Testing module to detect hardware-induced latencies (HWLAT_DETECTOR) [M/n/y/?] (NEW)
[..]

Launch the build process
fakeroot make-kpkg -j7 --initrd --revision=3.2.9 --append-to-version=rt kernel_image kernel_headers 

where 7 is the number of cpu cores+1.

The deb-packages will be found in the folder above linux-3.2.9/ and can be installed using sudo pkg -i
.


97. Wine 1.4 out now -- very brief build instructions

UPDATE 16 May 2013: See here for Wine 1.5.30: http://verahill.blogspot.com.au/2013/05/416-wine-1530-in-chroot.html

UPDATE (10th Jan 2013): See here for Wine 1.5.21 using the multiarch approach in Debian Testing/Wheezy: http://verahill.blogspot.com.au/2013/01/308-compiling-wine-1521-on-debian.html

Updated list of dependencies for debian stable/squeeze: http://verahill.blogspot.com.au/2012/11/compiling-wine-155-from-source-using.html


The instructions are identical to those for wine1.4 rc4 and 5: http://verahill.blogspot.com.au/2012/02/debian-testing-wheezy-64-compiling-wine.html and wine 1.3.35: http://verahill.blogspot.com.au/2012/01/debian-testingwheezy-64-bit-installing.html

I've tested the build on 8 March 2012.

-- START HERE --
sudo apt-get install bison flex gcc libc6-dev libfontconfig-dev libfreetype6-dev libglu-dev libgsm1-dev libice-dev libjpeg-dev libldap-dev libmpg123-dev libncurses5-dev libopenal-dev libpng-dev libsm-dev libssl-dev libusb-dev libx11-dev libxcomposite-dev libxcursor-dev libxext-dev libxi-dev libxinerama-dev libxml2-dev libxrandr-dev libxrender-dev libxslt-dev libxt-dev libxxf86vm-dev make libcapi20-dev liblcms-dev libsane-dev libhal-dev libdbus-1-dev valgrind prelink libcups2-dev opencl-dev lib32opencl1 oss4-dev gettext lib32v4l-dev lib32ncurses5-dev lib32asound2-dev lib32z-dev ia32-libs-dev
mkdir ~/tmp
cd tmp/
wget http://prdownloads.sourceforge.net/wine/wine-1.4.tar.bz2
tar -xvf wine-1.4.tar.bz2
./configure

configure: gstreamer-0.10 base plugins 32-bit development files not found, gstreamer support disabled
configure: libgsm 32-bit development files not found, gsm 06.10 codec won't be supported.
configure: libtiff 32-bit development files not found, TIFF won't be supported.
configure: WARNING: libjpeg 32-bit development files not found, JPEG won't be supported.
configure: Finished.  Do 'make' to compile Wine.
The warnings about lack of support can safely be ignored if you don't need it. The TIFF error seems a bit random since it appears on some of my systems, but not others. I haven't figured out the responsible package yet.

make
sudo checkinstall --install=no
to build 23Mb deb package without installing it
 OR 
sudo make install
to install without building a package.


Note:
JPEG support is supposedly available if you
1. remove symlinks
sudo rm /usr/lib32/libjpeg.so.62 /usr/lib32/libjpeg.so.62.0.0
2. Then, create new ones
sudo ln -s /usr/lib32/libjpeg.so.8 /usr/lib32/libjpeg.so.62
sudo ln -s /usr/lib32/libjpeg.so.8 /usr/lib32/libjpeg.so.62.0.0




Edit:
I didn't know it before, but there's a slightly different, wine-specific, way of building described here http://chrisjrob.com/2012/03/08/wine-1-4-on-debian-wheezy/

To see you wine version do
winecfg
This is from a newer build - 1.5.6



Links to this page:
http://chrisjrob.com/2012/03/08/wine-1-4-on-debian-wheezy
http://forums.linuxmint.com/viewtopic.php?p=535245
http://debian.linux.pl/threads/26515-Instalacja-wine-1-4-w-Debianie-Squeeze

07 March 2012

96. Optimising, trimming and making your solid state drive last longer on linux

There's an excellent and informative guide here:
http://apcmag.com/how-to-maximise-ssd-performance-with-linux.htm

Please read it. I've tried it on my SSD and it didn't crash my system. In fact, it even seems snappier, but that might be subjective.

While the guide above talks about making Solid State Drives (SSD) last longer and work faster, it equally applies to other solid state media such as USB sticks.

Here we'll apply that guide to a USB stick with debian we installed as shown in this guide: http://verahill.blogspot.com.au/2012/02/installing-debian-on-usb-stick-live-usb.html

--START HERE --
Mount your USB stick as you would any other -- the wonderful things about *NIX is that all configuration options are set in files which you can easily edit.

/etc/fstab
Before editing, it looks like this

proc            /proc           proc    defaults        0       0
UUID=8c0c9c98-e73f-4f5a-b7d7-f91f95c9d8ca /               ext4    errors=remount-ro 0       1
UUID=e3305fbe-8e4e-4d0e-9975-0db692f87d32 none            swap    sw              0       0
/dev/scd0       /media/cdrom0   udf,iso9660 user,noauto     0       0
We'll edit to

  • enable TRIM by adding discard.
    From the manual: "discard/nodiscard - Controls  whether  ext4  should issue discard/TRIM commands to the underlying block device when blocks are freed.  This is useful for SSD devices and sparse/thinly-provisioned LUNs, but it is off by default until sufficient testing has been done."
  • noatime.
    From the man: "Do not update inode access times on this filesystem (e.g., for faster access on the news spool to speed up news servers)."
  • nodiratime
    Same as noatime, for directories
  • move some temporary /var files to the RAM instead of disk
  • the last line puts all log files (/var/log/) in RAM as well. If you do want logs to persist between boots, comment it out
  • 1777 = chmod +trwx, 0755= u+rwx g+rw o+rw
  • I've kept the swap since I might want to use my stick on underpowered machines, but you really probably shouldn't
  • A good source of information on mount options is here: http://www.tuxfiles.org/linuxhelp/fstab.html


proc            /proc           proc    defaults        0       0
UUID=8c0c9c98-e73f-4f5a-b7d7-f91f95c9d8ca /               ext4 noatime,nodiratime,discard,errors=remount-ro 0       1
UUID=e3305fbe-8e4e-4d0e-9975-0db692f87d32 none            swap    sw              0       0
/dev/scd0       /media/cdrom0   udf,iso9660 user,noauto     0       0
tmpfs /tmp tmpfs defaults,noatime,mode=1777 0 0
tmpfs /var/spool tmpfs defaults,noatme,mode=1777 0 0
tmpfs /var/tmp tmpfs defaults,noatime,mode=1777 0 0
tmpfs /var/log tmpfs defaults,noatime,mode=0755 0 0

/etc/default/grub 
To set a system-wide scheduler policy for disk I/O we can edit grub and define elevator as noop, deadline or anticipatory.

Change e.g.
GRUB_CMDLINE_LINUX_DEFAULT="text splash"
to
GRUB_CMDLINE_LINUX_DEFAULT="text splash elevator=deadline"
If you want to know more about schedulers, you can look here: http://www.cyberciti.biz/faq/linux-change-io-scheduler-for-harddisk/


We need to do update grub, and that's a bit trickier, but still not too difficult.
My USB stick is mount at /media/8c0c9c98-e73f-4f5a-b7d7-f91f95c9d8ca/


sudo mount -o bind /dev 8c0c9c98-e73f-4f5a-b7d7-f91f95c9d8ca/dev/
sudo mount -o bind /sys 8c0c9c98-e73f-4f5a-b7d7-f91f95c9d8ca/sys/
sudo mount -o bind /proc 8c0c9c98-e73f-4f5a-b7d7-f91f95c9d8ca/proc/
sudo chroot 8c0c9c98-e73f-4f5a-b7d7-f91f95c9d8ca/
root@beryllium:/# update-grub
Generating grub.cfg ...
Found linux image: /boot/vmlinuz-3.2.0-1-686-pae
Found initrd image: /boot/initrd.img-3.2.0-1-686-pae
Found linux image: /boot/vmlinuz-2.6.32-5-686
Found initrd image: /boot/initrd.img-2.6.32-5-686
grep: input file `/boot/grub/grub.cfg.new' is also the output
done

And exit the chroot jail (type exit)


/etc/rc.local
Add a line to the end
echo 0>/proc/sys/vm/swappiness
to prevent use of swap until the RAM is full.

You're now done.


For an SSD drive you can just boot into your system and make the changes as above, but without fiddling with mounting /dev, /sys, /proc and doing chroot.

95. Cross-compiling 32 bit binaries on 64 bit system

There are many ways of setting up toolchain for cross compiling. This is the method I've had more success with, and feel more comfortable with. It introduces more overhead than some other approaches.

My motivation for wanting to cross compile is because I have a slow 32 bit headless server, and a couple of fast multiu-core 64 bit systems. Compiling kernel 3.2.9 on my 32 bit server takes up to 3 hours, while it takes less than half an hour on a more modern box.


This method allows you to compile without it affecting the host system. Everything will happen in a jail made up chroot. You will only be able to use architectures for which your hardware is compatible i.e. i386 and amd64. Cross-compiling for other architectures is a future project.

-- Start Here --


Debootstrap
create a directory where you can store you architectures e.g.
mkdir -p /home/me/tmp/architectures/i386
cd /home/me/tmp/architectures

sudo apt-get install debootstrap

You will use scripts to point your jailed systems apt to the right place. Here's how to see what's available:

ls /usr/share/debootstrap/scripts/
breezy  edgy  etch-m68k  gutsy  hoary         intrepid  karmic  lucid     natty      oneiric  precise  sarge.buildd      sid      stable   unstable  warty.buildd  woody
dapper  etch  feisty     hardy  hoary.buildd  jaunty    lenny   maverick  oldstable  potato   sarge    sarge.fakechroot  squeeze  testing  warty     wheezy        woody.buildd


Time to get busy:
sudo debootstrap --arch i386 testing /home/me/tmp/architectures/i386/ http://ftp.au.debian.org/debian/

I: Retrieving Release
I: Retrieving Release.gpg
I: Checking Release signature
I: Valid Release signature (key id 9FED2BCBDCD29CDF762678CBAED4B06F473041FA)
I: Retrieving Packages
[..]
I: Configuring perl...
I: Configuring tasksel...
I: Base system installed successfully


You can look at e.g. ftp://ftp.au.debian.org/debian/dists/wheezy/ to see what other architectures are available. In this particular case, it's amd64, armel, i386, ia64, powerpc etc. You won't be able to chroot into an architecture your hardware doesn't support, so you're effectively limited to amd64 and i386. Cross-compiling for other architectures will be a future project.


Go to Jail

make sure you're in /home/me/tmp/architectures
sudo chroot i386
root@tantalum:/#


You're in. To convince yourself it's real -- and that you can't escape from the /home/me/tmp/architectures/i386/ folder -- you can navigate around your system.

You still need to install all your build tools
apt-get install build-essential

Do you want to continue [Y/n]?
[..]
Get:1 http://ftp.au.debian.org/debian/ testing/main libgmp10 i386 2:5.0.4+dfsg-1 [264 kB]
Get:2 http://ftp.au.debian.org/debian/ testing/main libgomp1 i386 4.6.2-12 [27.3 kB]
[..]


Note what architecture we're installing packages for...it's really that simple. Also, no need for sudo since you're root. With only build-essential installed the entire system is ca 450 Mb.

Install kernel-package as well, so you can build 32 bit kernels. This bring it up to ca 550 Mb.

You'll want checkinstall to make .deb packages.

Locales
Finally, set all locale parameters to C by running this in the terminal

export LC_ALL=C
export LC_MESSAGES=C
export LC_COLLATE=C
export LANGUAGE=C
export LANG=C

Save yourself that headache in the future by
apt-get install locale
Exit your chroot jail, and start it again:
exit
sudo chroot i386

Reconfigure:
dpkg-reconfigure locales
and pick the same as your host system, in my case en_AU.UTF-8



Build something


--kernel--
We'll build a 32 bit kernel, but you could really build anything you want.

From outside the chroot jail (i.e. another terminal)
sudo cp ~/tmp/linux3.2.9.tar.bz2 ~/tmp/architectures/i386/usr/src/
Inside the chroot jail
root@tantalum:/# ls /usr/src/
linux-3.2.9.tar.bz2

cd /usr/src/
tar -xvf linux-3.2.9.tar.bz2
cd linux-3.2.9/

either copy a .config from an existing 32 bit kernel version (see http://verahill.blogspot.com.au/2012/03/debian-testing-kernel-329.html for more information), or
make defconfig

fakeroot make-kpkg -jN --initrd --revision=3.2.9 kernel_image kernel_headers
Choose the default for most of the questions. N is the number of cores+1 on the host system, e.g. 5 for a four-core CPU.

With -j5 I made a full build in 1m 21 s. That's a fairly minimal kernel build though.
Using the .config generated from an existing 32 bit debian system and following this I got a full build in about 25 minutes.

--Wine--
Following method 3 on this: http://verahill.blogspot.com.au/2012/01/debian-testingwheezy-64-bit-installing.html
cd /usr/src
wget http://prdownloads.sourceforge.net/wine/wine-1.3.35.tar.bz2
tar -xvf wine-1.3.35.tar.bz2
cd wine-1.3.35

apt-get install bison flex gcc libc6-dev libfontconfig-dev libfreetype6-dev libglu-dev libgsm1-dev libice-dev libjpeg-dev libldap-dev libmpg123-dev libncurses5-dev libopenal-dev libpng-dev libsm-dev libssl-dev libusb-dev libx11-dev libxcomposite-dev libxcursor-dev libxext-dev libxi-dev libxinerama-dev libxml2-dev libxrandr-dev libxrender-dev libxslt-dev libxt-dev libxxf86vm-dev make libcapi20-dev liblcms-dev libsane-dev libhal-dev libdbus-1-dev valgrind prelink libcups2-dev libv4l-dev libncurses5-dev libasound2-dev libz-dev

./configure
make -j5
checkinstall --install=no



In the future
Next time you want to cross compile, just
cd /home/me/tmp/architecture
sudo chroot i386
and you're ready to go.




06 March 2012

94. Virtualisation from the command line -- creating a debian image in virtualbox

I came across these posts and decided to put my own spin on it.
EDIT: fixed the port/device numbers for the dvd drive


Virtual box on the CLI

Here's my take on it. Most of it is self-explanatory. As with everything else Linux, names are case-sensitive.

VBoxManage createvm --name debi_dd --ostype Debian_64 --basefolder /home/me/tmp/virtual

Virtual machine 'debi_dd' is created.
UUID: 3cab43c4-d071-4d71-9e01-22a6f4e80645
Register the vm:
VBoxManage registervm `pwd`/debi_dd.vbox

or you will get
VBoxManage: error: Could not find a registered machine named 'debi_dd'

Create a harddrive:
VBoxManage createhd --filename debi_hd --size 5000 --format VDI --variant Standard


0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%
Disk image created. UUID: b11e6465-3ac6-441d-9e14-6417135b7cd1
The size is given in mb, VDI is the standard virtualbox format, but you can use  VMDK or VHD too. There are several variants -- Fixed, Standard, Split2G, Stream and ESX. Fixed is fixed size, standard expands as data is added, Split2G splits the HDD into 2GB chunks for filesystems which can't handle large files, Stream is 'optimized for streaming downloads and can be compressed' and I suspect that ESX is referring to VMWare's hypervisor product.

Create a SATA controller (for a win xp guest , use IDE instead)
VBoxManage storagectl debi_dd --name "ATA controller" --add sata --controller IntelAhci

Attach your harddrive
VBoxManage storageattach debi_dd --storagectl "ATA controller" --port 0 --device 0 --type hdd --medium debi_hd.vdi

and a DVD player and point it towards your debian iso
VBoxManage storageattach debi_dd --storagectl "ATA controller" --port 1 --device 0 --type dvddrive --medium ~/jigdo/debian-testing-amd64-CD-1.iso

Configure your VM hardware
VBoxManage modifyvm debi_dd --memory 256 --acpi on --boot1 dvd --clipboard bidirectional --nic1 nat --cableconnected1 on --bridgeadapter1 eth0 --usb on --usbehci on

You will need to have an X server running, either on the computer hosting the virtualbox, or you need to ssh in using ssh -X -C user@server. But it works. Once you have a working linux installation you can run headless.
You can also use remmina to connect via rdp at localhost:3389.

VBoxManage startvm debi_dd

Waiting for VM "debi_dd" to power on...
VM "debi_dd" has been successfully started.
You'll now be doing the usual graphical installation...


** I had some problems with network dhcp, but manually setting the ip, gw, netmask and dns server went fine. It may be particular to my networking set up (3 cards, 2 using static ip)

Make sure to install ssh server so you can easily connect to your running VM.

So you're done installing...

Eject the DVD

VBoxManage storageattach debi_dd --storagectl "ATA controller" --port 1 --device 0 --type dvddrive --medium emptydrive


Associate e.g. localhost:2222 with virtualbox:22
VBoxManage modifyvm "debi_dd" --natpf1 "guestssh,tcp,,2222,,22"

Time to go headless:
VBoxHeadless -s debi_dd
Oracle VM VirtualBox Headless Interface 4.1.8
(C) 2008-2011 Oracle Corporation
All rights reserved.
VRDE server is listening on port 3389.

and 
ssh verahill@localhost -p 2222
to log in

You can also use remmina
Connect to localhost:3389 and you'll be greeted with:
remmina in action


Use
 VBoxManage controlvm debi_dd poweroff
to power off

There's a bit of housekeeping to do with any freshly installed linux machine:
sudo apt-get install bzip2 vim 
sudo updatedb
and edit /etc/apt/sources.list to remove the cd.
You may want to edit /etc/default/grub too and set
GRUB_TIMEOUT=1
GRUB_CMDLINE_LINUX_DEFAULT="text"

Don't forget to sudo update-grub

If you don't want headless mode, just
VBoxManage startvm debi_dd

Removal

VBoxManage storageattach debi_dd --storagectl "ATA controller" --port 1 --device 0 --type dvddrive --medium none
VBoxManage storageattach debi_dd --storagectl "ATA controller" --port 0 --device 0 --type dvddrive --medium none 
VBoxManage unregistervm debi_dd --delete 
VBoxManage closemedium disk debi_hd.vdi --delete 
rm debi_dd/ -rf

05 March 2012

93. Building and installing samba from source

Here's how to compile and get started with SAMBA, which may come in handy if you need to set up a mixed environment.


Compiling

sudo apt-get install build-essential


wget http://ftp.samba.org/pub/samba/samba-latest.tar.gz
tar -xvf samba-latest.tar.gz 
cd samba-3.6.3/
cd source3
./configure
make
sudo checkinstall

You may want to look through the checkinstall settings:
*****************************************
**** Debian package creation selected ***
*****************************************
This package will be built according to these values:
0 -  Maintainer: [ root@barebone ]
1 -  Summary: [ samba 3.6.3 ]
2 -  Name:    [ samba ]
3 -  Version: [ 3.6.3 ]
4 -  Release: [ 1 ]
5 -  License: [ GPL ]
6 -  Group:   [ checkinstall ]
7 -  Architecture: [ amd64 ]
8 -  Source location: [ source3 ]
9 -  Alternate source location: [  ]
10 - Requires: [  ]
11 - Provides: [ source3 ]
12 - Conflicts: [  ]
13 - Replaces: [  ]
Enter a number to change any of them or press ENTER to continue:
Once the package is installed you need to put symlinks in your /usr/lib to the installed samba libs:
sudo ln -s /usr/local/samba/lib/libtalloc.so.2 /usr/lib/libtalloc.so.2
 sudo ln -s /usr/local/samba/lib/libtdb.so.1 /usr/lib/libtdb.so.1



Finally, create smb.conf in /etc/samba/ and make samba find it using a symlink
sudo mkdir /etc/samba
sudo touch /etc/samba/smb.conf
sudo ln -s /etc/samba/smb.conf /usr/local/samba/lib/smb.conf

Done. Sort of. You need to configure samba using smb.conf...a minimal configuration file can be found at the end of the post.



Errors:
checking for gcc... no
checking for cc... no
checking for cl.exe... no
configure: error: in `/home/verahill/tmp/samba-3.6.3/source3':
configure: error: no acceptable C compiler found in $PATH
See `config.log' for more details.

Solution:
sudo apt-get install build-essential



error:
-bash: smbclient: command not found
solution:
 put /usr/local/samba/bin in PATH
export $PATH=PATH:/usr/local/samba/bin


error:
/usr/local/samba/bin/smbclient: error while loading shared libraries: libtalloc.so.2: cannot open shared object file: No such file or directory
solution:
sudo ln -s /usr/local/samba/lib/libtalloc.so.2 /usr/lib/libtalloc.so.2


error:
/usr/local/samba/bin/smbclient: error while loading shared libraries: libtdb.so.1: cannot open shared object file: No such file or directory
solution:
 sudo ln -s /usr/local/samba/lib/libtdb.so.1 /usr/lib/libtdb.so.1


Error:
/usr/local/samba/bin/smbclient: error while loading shared libraries: libwbclient.so.0: cannot open shared object file: No such file or directory
Solution:
 sudo ln -s /usr/local/samba/lib/libwbclient.so.0 /usr/lib/libwbclient.so.0


error:
/usr/local/samba/bin/smbclient: Can't load /usr/local/samba/lib/smb.conf - run testparm to debug it
solution:
because I know where debian normally puts the smb.conf --
sudo mkdir /etc/samba
sudo touch /etc/samba/smb.conf
sudo ln -s /etc/samba/smb.conf /usr/local/samba/lib/smb.conf



Configuration:
Following https://www.samba.org/samba/docs/man/Samba-HOWTO-Collection/install.html#id2551954

Minimal /etc/samba/smb.conf:
[global]
workgroup = WKG
netbios name = MYNAME
[share1]
path = /tmp
Also, open up the relevant ports in your firewall:
Iptables
sudo iptables -A INPUT -p udp -m udp --dport 137 -j ACCEPT
sudo iptables -A INPUT -p udp -m udp --dport 138 -j ACCEPT
sudo iptables -A INPUT -p tcp --dport 139 -j ACCEPT
sudo iptables -A INPUT -p tcp --dport 445 -j ACCEPT