Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save micrub/bfb6bf610acfe0c608a61642bb263fac to your computer and use it in GitHub Desktop.
Save micrub/bfb6bf610acfe0c608a61642bb263fac to your computer and use it in GitHub Desktop.
JDK and Leiningen on ram disk with Ubuntu 14.04

Overview

  1. Create RAM disk
  2. Create JAVA + Leiningen squashfs image
  3. Mount Image to RAM disk and set it as permanent
  4. Set Java on RAM disk to be default and patch lein executable to read standalone jar from RAM disk.

Create RAM disk

Create RAM disk using tmpfs:

sudo mkdir /media/ramdisk
sudo mount -t tmpfs tmpfs /media/ramdisk

To allow it's mount on os boot, edit file /etc/fstab ,add following as last line :

tmpfs /media/ramdisk tmpfs defaults,mode=1777 0 0

sudo reboot to unsure that it is loaded after reboot.

Create JAVA + Leiningen squashfs image

JDK and Liening needs to be installed. On ubuntu usually they are installed in:

/usr/lib/jvm/java-8-oracle/
~/.lein

Leiningen also stores profile.clj in LEIN_HOME which will become read only when used from RAM disk. Generally it is easy to patch lein executable in a way that will cause it to read profile from non read only source.

Create .sqsh image to be mounted later as RAM disk image.

SquashFS compresses files, inodes and directories, and supports block sizes up to 1 MB for greater compression. SquashFS is intended for general read-only file system use and in constrained block device/memory systems (e.g. embedded systems) where low overhead is needed.

sudo apt-get install squashfs-tools -y 
take ramdisk-origin
cp /usr/lib/jvm/java-8-oracle/* . -r
cp ~/.lein/* . -r
mksquashfs . ~/jdk8.sqsh

Mount it and add to alternatives

sudo mount ~/jdk8.sqsh /media/ramdisk -t squashfs -o loop 
sudo update-alternatives --install "/usr/bin/java" "java" "/media/ramdisk/bin/java" 1 

Patch Lein executable and test setup

Set LEIN_HOME to be /media/ramdisk/

Add LEIN_HOME="/media/ramdisk" before original export:

LEIN_HOME="/media/ramdisk"
export LEIN_HOME="${LEIN_HOME:-"$HOME/.lein"}"

Check/Set install java complete

sudo update-alternatives --config java # java in ram disk

Make it permanant on startup.

Edit /etc/fstab add following line :

/home/username/jdk8.sqsh /media/ramdisk squashfs ro,defaults,loop 0 0

Reboot:

sudo reboot

Ensure that lein is loaded from RAM disk

You can add -x debug flag to lein executable to ensure that it loaded from RAM disk.

References

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment