2

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 a Linux system (I'm using Ubuntu, if that matters). 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 basicly need the same thing as in this question, and also this question, but for Java.

I've seen stuff about chroot, and I think this might work, but I have no idea how to get it to work with Java. I don't need to worry about security at all, I just need the different fake filesystem.

Also, the core Java libraries need to be accessed without having to copy them into the fake filesystem.

Is this possible, and if so, how do I set it up?

Community
  • 1
  • 1
iBelieve
  • 1,502
  • 17
  • 32

3 Answers3

4

Not sure, but if you only want to reproduce filesystem semantics (possibly for testing), I'd suggest you abstract your filesystem backend.

A good alternative would be to use commons-vfs. It mimicks a virtual filesystem, supporting:

  • .zip files / .jar files
  • .gz files
  • a in-memory filesystem
  • a classpath-based filesystem
  • URL-based

So basically, your 'thunderbolt' directory would be another implemented filesystem, which you could use for testing and design.

All your apps would need to rely in calling VFS, but this is not a huge issue, I think.

aldrinleal
  • 3,559
  • 26
  • 33
  • My goal is to be able to use normal filesystem access APIs (File, FileInputStream, etc) just as I would once I move into a separate system with its own kernel, etc. but while running on top of Linux, simply redirect calls to a special directory. I'm not sure about commons-vfs, but it doesn't look like this does that? – iBelieve Jan 05 '13 at 21:23
  • No it doesn't. Of course, you can rewrite the whole JVM. Or even coming up with a better one. Be my guest :) – aldrinleal Jan 06 '13 at 00:31
0

[Linux] Chroot is correct (but not simple). for NOT recopy all libraries... you can use

mount --bind -o ro /source/ /destination/

(man mount for more info)

ggrandes
  • 2,067
  • 22
  • 16
  • So you're saying that if I set up a Chroot, I can just bind the Java libraries into my Chroot? – iBelieve Jan 05 '13 at 21:20
  • correct! you can bind subdirectories from outside of chroot to inside of chroot. so you save space and not having to update the versions separately – ggrandes Jan 05 '13 at 22:09
  • Thanks for your help! I got what I want to work using a chroot; So far I just copied most of the libraries I wanted, but I did bound the Java installation into my chroot. Here's what I did to get it to work: http://askubuntu.com/a/236821/109543. – iBelieve Jan 06 '13 at 02:59
0

There are not that many classes in the system library that take the file path string as an argument. File does, probably FileInputStream, FileReader, RandomAccessFile, probably URL should be reviewed, it may be some others - several days of reviewing should reveal the most.

I your specific case it may be reasonable to think about tweaking the Java system library using OpenJDK that is open source and allows this. There are two other alternative FOSS projects, GNU Classpath and Apache Harmony, these may be easier to build (I was building GNU Classpath a number of times in the past) but these projects are currently not very active. They have been started exactly for cases when research or other projects require to modify the Java system library.

If you find these projects difficult to build, you may try to build separately and replace just a few system classes.

This solution would allow also to run the third party Java programs that cannot be modified to route all filesystem access through commonsfs API.

Audrius Meškauskas
  • 20,936
  • 12
  • 75
  • 93