6

The following commands are how I create a RAMDisk on Ubuntu 12.04 LTS:

sudo mkdir -p /media/ramdisk
sudo mount -t tmpfs -o size=1024M tmpfs /media/ramdisk

But now I have no idea to eject it.

These commands are what I've tried but not work:

sudo eject /media/ramdisk
sudo umount /media/ramdisk

How to eject RAMDisk properly?

Kevin Dong
  • 1,135

1 Answers1

16

The inverse of sudo mount -t tmpfs tmpfs /media/ramdisk is sudo umount /media/ramdisk.

The last command will only succeed if no application is using /media/ramdisk though. You can use sudo lsof -n /media/ramdisk to find out which programs are blocking the mount point.

Lekensteyn
  • 178,864
  • Well, it popped up this warning: lsof: WARNING: can't stat() fuse.gvfs-fuse-daemon file system /home/username/.gvfs Output information may be incomplete. – Kevin Dong Feb 12 '14 at 11:23
  • 2
    That's non-fatal, what make you think that /media/ramdisk has not been unmounted? What does mountpoint /media/ramdisk tell you? By the way, "unmounting" leaves the directory behind, so you still have to remove the directory after unmounting: sudo rmdir /media/ramdisk – Lekensteyn Feb 12 '14 at 11:40
  • I think it's important to know that you have to specify an absolute path as argument to sudo lsof -n otherwise it won't show what you're looking for. lsof 4.93.2 on Arch. – xdevs23 Dec 25 '19 at 21:02
  • At first it seems to be better to delete files that are inside of the ramdisk dir, because I used umount and free -g shows still through shared that the RAM is blocked. – mgutt Sep 29 '20 at 11:31