Ram Disks
This revision is from 2024/06/17 08:43. 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
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 # Setup the ram disk and chroot the environment # Set variablesRAMDISK_SIZE="1G"
RAM_DISK="/mnt/ramdisk"
# Create the mount point if it doesn't existmkdir -p $RAM_DISK
# Mount the RAM diskmount -t tmpfs -o size=$RAMDISK_SIZE tmpfs $RAM_DISK
# Configure schroot /etc/schroot/schroot.conf # sudo apt-get install schroot # [jimbo] # description=Chroot for jimbo # directory=/mnt/ramdisk # users=jimbo # root-groups=rootsudo cp -R /home/x/ram_disk/os_chroot/* ${RAM_DISK}
sudo chown -R root:root ${RAM_DISK}
sudo chmod -R u=rwx,g=rwx,o= ${RAM_DISK}
sudo mount -o bind /dev ${RAM_DISK}/dev
sudo mount -o bind /proc ${RAM_DISK}/proc
sudo mount -o bind /sys ${RAM_DISK}/sys
mkdir -p ${RAM_DISK}/home/jimbo
chown jimbo:jimbo ${RAM_DISK}/home/jimbo
# log jimbo using command # sudo schroot -c jimbo --directory=/home/jimbo