Ram Disks

This revision is from 2024/06/24 22:51. You can Restore it.

Two scripts, one is the system service so that the ram disk is re-instated upon reboot, ram volatility is obviously the situation with ram disks and the ram disk script.

Setup RAM disk service on Linux

# Filename: setup-ramdisk.service # /etc/systemd/system/setup-ramdisk.service # sudo cp /home/x/ram_disk/setup-ramdisk.service /etc/systemd/system/setup-ramdisk.service # sudo systemctl daemon-reload # sudo systemctl enable setup-ramdisk # sudo systemctl start setup-ramdisk # After reboot check with df -h | grep ramdisk # sudo systemctl status setup-ramdisk

[Unit]

Description=Setup RAM disk and start web server

After=network.target

[Service]

Type=oneshot

ExecStart=/home/x/ram_disk/setup-ramdisk.sh

RemainAfterExit=true

[Install]

WantedBy=multi-user.target

The second script involves keeping a copy of linux as chrooted jail for a user. Alpine Linux is sufficiently small that its works for this purpose. The second program is named schroot, apt-get install schroot. Putting the ram disk in a chroot jail insures we do not use the disk at all, a lib or two could sneak under the radar causing a bottleneck.

#!/bin/bash # Set variables

RAMDISK_SIZE="1G"

RAM_DISK="/mnt/ramdisk"

# Create the mount point if it doesn't exist

mkdir -p $RAM_DISK

# Mount the RAM disk

mount -t tmpfs -o size=$RAMDISK_SIZE tmpfs $RAM_DISK

# Configure schroot (not part of the script) # sudo apt-get install schroot # [jimbo] # description=Chroot for username # directory=/mnt/ramdisk # users=jimbo # root-groups=root

  

📝 📜 ⏱️ ⬆️