I'm working on designing a group of Java programs that I hope to turn into a Java-based OS someday. Until I get a kernel working, I want to just run them on top of Ubuntu. Because of this, I need all filesystem calls directed to a different directory in my home folder, so accessing / from within Java would actually access /home/<user>/Thunderbolt/.

I've looked at the community documentation for using chroot, but it says to set up a basic installation of Ubuntu in it. Is this really necessary? All I want is to run Java applications inside it so the app thinks it is in its own fake filesystem. I don't want all the extra Ubuntu stuff.

According to the aforesaid docs:

In many ways, a chroot is like installing another operating system inside your existing operating system.

But I don't want this. All I want is to hide most of the real filesystem from the app so it sees only one directory.

I've also seen the manpage for the chroot function. Will this do what I want?

Is there any simple way to run a Java application in its own fake filesystem using chroot (without all the extra Ubuntu stuff), and if so, how?


What I did was create a directory called Thunderbolt in my home folder. Then for the executables I wanted, I ran ldd and copied the needed libraries and the actual executable into my Thunderbolt directory, like

$ ldd /bin/bash
    linux-gate.so.1 =>  (0xb7781000)
    libtinfo.so.5 => /lib/i386-linux-gnu/libtinfo.so.5 (0xb7743000)
    libdl.so.2 => /lib/i386-linux-gnu/libdl.so.2 (0xb773e000)
    libc.so.6 => /lib/i386-linux-gnu/libc.so.6 (0xb7593000)
    /lib/ld-linux.so.2 (0xb7782000)

For Java itself, along with copying the needed libraries, I used mount --bind to bind the Java home directory (/usr/lib/jvm/java-7-openjdk-i386/):

$ mount --bind -o ro /usr/lib/jvm/java-7-openjdk-i386/ sys/java/

To run the chroot, I created a script called thunderbolt that called .profile (which set up the environment) than ran my Java app (/sys/Thunderbolt.sys is a Jar file, I just changed the extension):

source /.profile
/sys/java/bin/java -jar /sys/Thunderbolt.sys Files

To run the chroot, I used the following command

sudo chroot /home/mspencer/Thunderbolt /bin/bash /thunderbolt

NOTE: This doesn't work perfectly yet, I'm getting this warning whenever I run Java: OpenJDK Server VM warning: Can't detect initial thread stack location - find_vma failed

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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