Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

In my case Java app is JDownloader. I prepared chroot environment as explained here:

http://www.0x61.com/forum/post5240333.html#p5240333

and here:

http://interreality.org/~reed/java-chroot.html

and here:

http://www.elstel.com/openroot/

So, I have java installed, added group and user, JDownload files copied, but when I try to run it (as regular user under chroot; I run chroot as root, but once I am in chroot, I switch to chroot regular user):

java -Xmx512m -jar JDownloader.jar

I got some positive messages like loading skins by JDownloader

10 4/6/11 2:15:17 PM - FINER [jd.JDClassLoader()] -> Look and Feel JAR loaded: /mnt/jd/libs/laf/syntheticaSilverMoon.jar

but that's end of the story -- app does not show up. No matter if I use chroot to run chroot environment or openroot, the outcome is the same.

When I run JDownload as chroot-root I got a little more output but at then end exception occurs:

10 4/6/11 2:39:23 PM - FINER [jd.config.DatabaseConnector()] -> Loading database

10 4/6/11 2:39:23 PM - FINER [jd.config.DatabaseConnector(checkDatabaseHeader)] -> Checking database

10 4/6/11 2:39:23 PM - INFO [jd.Main(main)] -> init Splash

------------------------ Thread: 11 -----------------------

11 4/6/11 2:39:25 PM - INFO [jd.gui.swing.laf.LookAndFeelController(setUIManager)] -> Use Look & Feel: de.javasoft.plaf.synthetica.SyntheticaSimple2DLookAndFeel

11 4/6/11 2:39:25 PM - SEVERE [jd.controlling.JDLogger(exception)] -> SEVERE Exception occurred java.lang.reflect.InvocationTargetException

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)

I have the same Jave installed in chroot and normal system, I can run the same JDownloader in normal system, no problems here.

QUESTION -- what I am missing here? How to run GUI Java app?

Thank you in advance.

share|improve this question
1  
Consider using cgroups or LXC, they might suit you better (and are much easier to deal with). –  Let_Me_Be Apr 6 '11 at 13:54
    
@Let_Me_Be Many thanks. cgroups is pretty new I guess, because I didn't find anything to read really, but LXC looks VERY promising. However I will try to finish chroot approach first, and then move to LXC. –  greenoldman Apr 7 '11 at 8:21
    
Actually LXC is built on top of cgroups :) –  Let_Me_Be Apr 7 '11 at 9:35
add comment

3 Answers

up vote 6 down vote accepted

If you're trying to get any chrooted app to show up in X11, you will need a couple of things set up correctly. One is a valid DISPLAY environment variable, second is a proper Xauthority file, and third and most important, access to the socket used by X11/Xorg. X11 can use either a TCP network socket or a Unix Domain socket. A TCP socket will be easier to use from a chroot, but most modern desktops have TCP turned off with -nolisten tcp or something similar set on the X server. TCP sockets start at TCP port 6000 for display :0 up through 6063 for the last display. As long as TCP sockets are listening, you shouldn't need to do anything more with sockets. You still need to worry about DISPLAY and Xauthority. Unix domain sockets require a little more work and, at least on Linux, reside under /tmp/.X11-unix/X? where ? is a number from 0 to 63. If your chroot resided on the same filesystem as /tmp then you can use hard links, at least on Linux. Symbolic links won't leave a chroot. Replace ? with the correct display number:

mkdir /path/to/chroot/tmp
chmod 1777 /path/to/chroot/tmp
mkdir /path/to/chroot/tmp/.X11-unix
chmod 1777 /path/to/chroot/tmp/.X11-unix
ln -f /tmp/.X11-unix/X? /path/to/chroot/tmp/.X11-unix/X?

mkdir and chmod only need to be done once, but the socket file will need to be recreated with ln on each X session. If /tmp is not on the same file system, life is harder and you will need some kind of hackery such as making /tmp/.X11-unix a symbolic link to the corresponding directory under the chroot. Next, make sure the DISPLAY environment variable is set and matches what is used by your terminal and other X11 apps. Lastly, to copy over the .Xauthority, use xauth. You need to find the matching cookie for your X11 session and this cookie will be different for every session. Use xauth list $DISPLAY to print out cookies for your DISPLAY. The name will look like host:? or host/unix:? where host is the hostname of the computer and ? is the display number. The display number can be retrieved with echo $DISPLAY and it will be the number following the colon (:) and before any period (.) To copy over the Xauthority, use something like this:

xauth extract /path/to/chroot/.Xauthority host/unix:1
xauth -f /path/to/chroot/.Xauthority list

The second command simple list the copied entries. If you need to copy while using sudo or other command to change users, try something like this:

xauth extract - host/unix:1 | sudo xauth -f /path/to/chroot/.Xauthority merge -

If the place you put the .Xauthority file is not the home directory for the chrooted user, you will have to set the XAUTHORITY environment variable:

export XAUTHORITY=/path/to/chroot/.Xauthority

As you can probably tell, it's not typical to run a GUI app under a chroot.

share|improve this answer
    
Many, many thanks. Thank to your tutorial I was able to run xterm without problems (btw. I thought that openroot is design to "hide" all those scary details from user), however when I run JDownloader -- no change, literally. It fails with exception (the one, I posted in question). –  greenoldman Apr 7 '11 at 9:46
1  
chroot's can be difficult to debug. Obviously something's still missing, but I'm not sure what. Sometimes I can figure out by using strace or equivalent program. Comparing a working strace with a broken one. Mostly likely it's attempting to access some file, possibly a socket. strace -efile -oprog.trace prog limits tracing to only file access, stores the trace to prog.trace and runs prog. –  penguin359 Apr 7 '11 at 19:06
    
Thank you once again, I will dig deeper :-) –  greenoldman Apr 8 '11 at 7:09
    
Note: if your chroot is not on the same filesystem as /tmp, then you can bind mount .X11-unix –  totaam Feb 23 at 17:25
add comment

I don't think there's anything you need to do specifically for Java apps, but you do have to do something for GUI apps in general.

I've done this on my home computer, but I'm not at home right now so bear with me. I have a script that mounts everything into my chroot like /dev and /proc, but it also copies ~/.X* as well. If I remember correctly, in your home folder there are files that start with .Xauth, and you copy those into the home folder of your chroot environment. In my experience these files need to be copied every time that X is restarted.

What I would do to test this method out was I'd just run a simple X application like xterm. It was just a fast and simple app I could test with. xterm should give you an error message if it can't connect to the X server.

I happen to have the full X11 package installed into my chroot, but I don't know enough about X to know if chroot'd apps run on a chroot'd X server or on the host X server.

share|improve this answer
    
Good point. With openroot and root user within chroot environment I get error: "Invalid MIT-MAGIC-COOKIE-1 keyWarning: This program is an suid-root program or is being run by the root user." and with regular simply "xterm Xt error: Can't open display: :0". –  greenoldman Apr 7 '11 at 9:29
add comment

That worked for me on an ArchLinux chrooting into a Debian. In the host:

$ xauth list
latitude/unix:0  MIT-MAGIC-COOKIE-1  d4474d13c

Now in the chroot environment:

# xauth add latitude/unix:0 MIT-MAGIC-COOKIE-1 d4474d13c
# xcalc # works!
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.