RAMify is a script that allows you to cache a folder's contents in a RAM disk to improve read performance. It creates a shadow folder on the disk that mirrors the contents of the RAM disk and syncs any changes back to the shadow folder.
./ramify.sh [-s <size>] /path/to/folder
-s <size>
: Optional. Specify the size (in KB) of the tmpfs mount (RAM disk). If not specified, the script will calculate the size based on the folder size, adding a 10% buffer.
/path/to/folder
: The folder you want to cache in the RAM disk.
- Moves the target folder to a shadow folder (with a
.ramify
suffix). - Creates a tmpfs mount (RAM disk) at the target folder's original location.
- Copies the contents of the shadow folder to the RAM disk.
- Uses
inotifywait
to monitor changes in the RAM disk. - Syncs the changes from the RAM disk back to the shadow folder using
rsync
.
- Bash
- Python (used for calculating the RAM disk size)
- Inotify tools (
inotifywait
command) - Rsync
- Save the script as
ramify.sh
. - Make the script executable with
chmod +x ramify.sh
.
Cache the contents of the folder /path/to/your-folder
in a RAM disk:
sudo ./ramify.sh /path/to/your-folder
Cache the contents of the folder /path/to/your-folder
in a RAM disk with a user-defined size of 2048 KB:
sudo ./ramify.sh -s 2048 /path/to/your-folder
- The script must be run as root (or with sudo) to create the tmpfs mount and move the original folder.
- If the script is interrupted or terminated, it will automatically sync the contents of the RAM disk back to the shadow folder, unmount the tmpfs, and move the shadow folder back to its original location.
This script creates a RAID 1 array with a RAM disk and a folder on your filesystem. It is designed to improve read performance while still retaining data durability in case of a crash.
sudo ./ram_disk_raid.sh /path/to/folder
/path/to/folder
: The folder you want to include in the RAID 1 array with a RAM disk.
- Creates a directory in the
/mnt/tmpfs
folder to store a copy of the target folder. - Copies the contents of the target folder to the new directory in the
/mnt/tmpfs
folder. - Binds the folders to loopback devices (e.g.,
/dev/loop0
and/dev/loop1
). - Creates a RAID 1 array using the loopback devices, marking the real disk folder as "write-mostly".
- Mounts the RAID 1 array to the original folder location.
- Bash
- mdadm
- Save the script as
ram_disk_raid.sh
. - Make the script executable with
chmod +x ram_disk_raid.sh
.
Create a RAID 1 array with a RAM disk for the folder /path/to/your-folder
:
sudo ./ram_disk_raid.sh /path/to/your-folder
- The script must be run as root (or with sudo) to create the RAID 1 array and mount it.
- The script does not implement automatic syncing or cleanup on exit. If you need to update the original folder, you will need to manually stop the RAID 1 array and sync the data back to the folder.