- Create RAM disk
- Create JAVA + Leiningen squashfs image
- Mount Image to RAM disk and set it as permanent
- Set Java on RAM disk to be default and patch lein executable to read standalone jar from 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.
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.
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
sudo mount ~/jdk8.sqsh /media/ramdisk -t squashfs -o loop
sudo update-alternatives --install "/usr/bin/java" "java" "/media/ramdisk/bin/java" 1
Add LEIN_HOME="/media/ramdisk"
before original export:
LEIN_HOME="/media/ramdisk"
export LEIN_HOME="${LEIN_HOME:-"$HOME/.lein"}"
sudo update-alternatives --config java # java in ram disk
Edit /etc/fstab add following line :
/home/username/jdk8.sqsh /media/ramdisk squashfs ro,defaults,loop 0 0
sudo reboot
You can add -x
debug flag to lein executable to ensure that it loaded from RAM disk.