mardi 28 septembre 2010

chroot java on linux x86_64

I had to chroot java on linux 86_64. I have found many blogs, but all I read missed some of the steps:


export JAIL=/home/jail
#Make all dirs 
mkdir -p $JAIL/dev $JAIL/lib $JAIL/etc $JAIL/opt/ $JAIL/proc
#copy hosts file
cp /etc/hosts $JAIL/etc/hosts
#copy libs required by java (1.6.20) 
cp /lib/ld-linux-x86-64.so.2 /lib/libc.so.6 /lib/libdl.so.2 /lib/libgcc_s.so.1 /lib/libm.so.6 /lib/libnsl.so.1 /lib/libpthread.so.0 /lib/librt.so.1 $JAIL/lib/ 
#needed by my Java app
cp /usr/lib/libstdc++.so.5 $JAIL/lib/ 
#Although you link this to your "real" /lib, in your jail, it will be the lib directory in your jail.
ln -s /lib $JAIL/lib64
#Mount proc 
sudo mount -t proc /proc $JAIL/proc
#create devices 
sudo mknod -m 666 $JAIL/dev/random c 1 8 
sudo mknod -m 666 $JAIL/dev/null c 1 3 

sudo mknod -m 666 $JAIL/dev/zero c 1 5

Now just copy/install java, then start it with:
sudo chroot $JAIL /opt/java/bin/java -version
Assuming that /opt/java is where you installed java.
If java does not launch, make sure with ldd, that all so files are in the $JAIL/lib dir.
I got
chroot: failed to run command `/opt/java/bin/java': No such file or directory
Because the lib64 directory was not linked to /lib.


I see quite a few people like this blog post, please leave a comment ... thanks.

mercredi 8 septembre 2010

SQLPLUS command history

I was using sqlplus on Linux and needed command history. I looked around the net and found rlwrap.

To my surprise, it was even in Debian's apt repositories!

$ sudo apt-get install rlwrap

worked like a charm.

To use the program:

$ rlwrap sqlplus scott/tiger@orcl

I finally went for gqlplus, beacuse it is even better; it has table name completion, like the bash shell does for files & folders. It needs libncurses-dev. You should read the readme, do not perform make install, just copy the gqlplus binary into your path. Note that sqlplus must be on the path as well.

I created an alias named sqlplus that runs gqlplus.