Just a quick worklog to give an idea of how you set this up and how it works. Of course, you may want todo things a little differently. It depends on if you want to keep the cloud9 directory “updated” Meaning over time maybe updates have updated the files, so perhaps one could make a fresh img file very time the cloud9 directory is mounted for use. Perhaps that part could be done in memory, but keep in mind once the board loses power, that stored “data” will also be lost. Which is why I think the best way to go about things would be to store the directory structure we don’t care about in memory.
Also keep in mind that this is just an example, and the files I’m demonstrating with have nothing to do with cloud9. The overall concept however should be solid. As such, you may need to double check permissions etc. But if you use dd to create your image, directory structure along with file permissions should remain intact.
Load the zram kernel module:
root@wgd:~# modprobe zram zram_num_devices=1
Test to make sure driver module loaded:
root@wgd:~# lsmod |grep zram
zram 25049 0
zsmalloc 13745 1 zram
lz4_compress 3334 1 zram
Notice here that zram is using the lz4 compression algorithm. This can be changed.
Set the zram memory constraints:
root@wgd:~# echo ‘256M’ > /sys/block/zram0/disksize
root@wgd:~# echo ‘128M’ > /sys/block/zram0/mem_limit
Make a file system on our ramdisk:
root@wgd:~# mkfs.ext4 /dev/zram0
mke2fs 1.43 (17-May-2016)
Discarding device blocks: done
Creating filesystem with 65536 4k blocks and 65536 inodes
Filesystem UUID: 2a08c7dd-234f-497a-a89b-fe4ecbb78c3f
Superblock backups stored on blocks:
32768
Allocating group tables: done
Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done
List directory contents( note" ‘testfile’ is empty ):
root@wgd:~# ls
git testfile
Get our current working directory:
root@wgd:~# pwd
/root
Find our ramdisk device:
root@wgd:~# ls /dev |grep zram*
zram0
Mount our ramdisk at /root/ ( root’s home directory ):
root@wgd:~# mount /dev/zram0 /root
The interesting part here is that we’re still seeing our original file structure:
root@wgd:~# ls
git testfile
But once we change directory . . . The new structure shows up:
root@wgd:~# cd /root/
root@wgd:~# ls
lost+found
Create a new test file, and test:
root@wgd:~# touch testfile
root@wgd:~# ls
lost+found testfile
root@wgd:~# echo “Hello World” > testfile
root@wgd:~# cat testfile
Hello World
Unmount the ramdisk( note: one must change out of the mountpoint before unmounting ):
root@wgd:~# cd …
root@wgd:/# umount /root/
Change back into our root home directory and retest:
root@wgd:/# cd ~
root@wgd:~# ls
git testfile
root@wgd:~# cat testfile