Ram Disks

This revision is from 2024/06/17 07:53. You can Restore it.

Two scripts, one is the system service so that the ram disk is re-instated upon reboot, this is obviously the situation of a ram disk and 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

#!/bin/bash # Set variables

RAMDISK_SIZE="1G"

MOUNT_POINT="/mnt/ramdisk"

WEB_SOURCE="/var/www/html"

WEB_DEST="$MOUNT_POINT/html"

# Create the mount point if it doesn't exist

mkdir -p $MOUNT_POINT

# Mount the RAM disk

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

# Copy the website files

cp -r $WEB_SOURCE $WEB_DEST

# Start the web server (e.g., Apache or Nginx) # systemctl restart apache2 # or `systemctl restart nginx` for Nginx

  

📝 📜 ⏱️ ⬆️