RAM disks

Sometimes it is desirable to have a ram disk for reasons as:

More feature, more simple and more modern is using mount -t tmpfs -o size=256M tmpfs /mnt/tmpfs.

cat /etc/mtab | grep tmpfs shows already available ram disk space.

/run is a top directory and /run/user is a subdirectory with the permissions set for each user. It is therefore ready to be used.

Important

The /run/user directories can easily get wiped out once the user or root logs in and out. For daemons and systemd services it is therefore recommended to create directories directly under /run. systemd services can do this automatically by adding

[Service]
ExecStart=/<path to executable>
RuntimeDirectory=<subdirectory under /run>
RuntimeDirectoryMode=0755 

To create a ram disk the "old-way" check if it is already available ls -l /dev/ram*

and if it is already mounted: cat /etc/mtab | grep ram

If no /dev/ram* device files exist, check the kernel:

If necessary modify it to have something as:

CONFIG_BLK_DEV_RAM=y
CONFIG_BLK_DEV_RAM_COUNT=16
CONFIG_BLK_DEV_RAM_SIZE=4096

Then format it mke2fs -m 0 /dev/ram0

Create a mounting point and mount it: mount /dev/ram0 /mnt/ram

Recheck that it is mounted: cat /etc/mtab | grep ram

Check the disk size df -T | grep ram

cat /usr/src/linux/.config | grep DEV_RAM

The size can be reconfigured without recompiling the kernel by passing a parameter to the kernel at boot time. Using grub, add something as the following to get 16MByte

kernel /kernel-3.<version>-gentoo-r<release> ramdisk_size=16000

df -h | grep /dev/ram and lsblk shows the status


Linurs startpage