Create ram disk by: mount -t tmpfs -o size=256m tmpfs /r not works

Questions about applications and software
Forum rules
Before you post please read how to get help
Post Reply
abdu
Level 1
Level 1
Posts: 5
Joined: Sun Jul 08, 2018 10:30 am

Create ram disk by: mount -t tmpfs -o size=256m tmpfs /r not works

Post by abdu » Sat Jul 14, 2018 6:37 am

I tried to create ram disk by command:

Code: Select all

sudo mkdir /r
sudo chmod a+rwx /r
sudo mount -t tmpfs -o size=256m tmpfs /r 
but not work, has no effect whatsoever on Nemo nor such on the device at left pane
It occurred right after partial reinstallation of LMv18.3 Cinn, worked on previous first installation.
Anyone with any useful guide to solve this ? Thanks so much in advance.

fungus
Level 4
Level 4
Posts: 360
Joined: Mon Sep 07, 2015 6:09 am

Re: Create ram disk by: mount -t tmpfs -o size=256m tmpfs /r not works

Post by fungus » Sat Jul 14, 2018 6:57 am

You should not create any mounts in the root folder, use the media folder instead (eg. /media/username/*). But I think your problem is that the ramdisk is created with sudo, root therefore owns it and no user can access it - you need to change the owner with "sudo chown 1000:1000 /r" before you can access it.
Linux Mint 17.3 64bit KDE @ Asus B150M-A, i3 6100, Crucial 16GB DDR4, Crucial BX100
One bit says: YES, the other answers: NO.. Guess who's he and who's she..! ;)

gm10
Level 13
Level 13
Posts: 4533
Joined: Thu Jun 21, 2018 5:11 pm

Re: Create ram disk by: mount -t tmpfs -o size=256m tmpfs /r not works

Post by gm10 » Sat Jul 14, 2018 8:00 am

This is a script I use to throw up a quick ramdisk. Should give you the idea, modify as needed

Code: Select all

#!/bin/bash 
#!/bin/bash 
RAMDISK="/media/Ramdisk"
if ! grep -qs $RAMDISK /proc/mounts; then
	if [ ! -d $RAMDISK ]; then
		sudo mkdir $RAMDISK
	fi
	sudo mount -t ramfs -o mode=777,size=1.5g ramfs $RAMDISK
else
	read -r -p "Ramdisk already mounted. Unmount? [y/N] " response
	if [[ "$response" =~ ^([yY][eE][sS]|[yY])+$ ]]; then
	    sudo umount $RAMDISK
	fi
fi
PS: Seeing it now I noticed it should probably have a check whether the ramdisk is already mounted in case you're accidentally running it twice. added.
Last edited by gm10 on Sat Jul 14, 2018 8:16 am, edited 3 times in total.

fungus
Level 4
Level 4
Posts: 360
Joined: Mon Sep 07, 2015 6:09 am

Re: Create ram disk by: mount -t tmpfs -o size=256m tmpfs /r not works

Post by fungus » Sat Jul 14, 2018 8:08 am

Use tmpfs and not ramfs. tmpfs is newer and will not grow and (maybe) cause an out-of-memory crash, ramfs will :)
Linux Mint 17.3 64bit KDE @ Asus B150M-A, i3 6100, Crucial 16GB DDR4, Crucial BX100
One bit says: YES, the other answers: NO.. Guess who's he and who's she..! ;)

gm10
Level 13
Level 13
Posts: 4533
Joined: Thu Jun 21, 2018 5:11 pm

Re: Create ram disk by: mount -t tmpfs -o size=256m tmpfs /r not works

Post by gm10 » Sat Jul 14, 2018 8:13 am

fungus wrote:
Sat Jul 14, 2018 8:08 am
Use tmpfs and not ramfs. tmpfs is newer and will not grow and (maybe) cause an out-of-memory crash, ramfs will :)
Depends on your use case. tmpfs can be swapped, the cases that I use such a temporary ram disk for are when I do not want that, hence ramfs. But you are right, for general purpose use tmpfs is the better choice.

Post Reply

Return to “Software & Applications”