I have /var on a 10Gb EXT4 partition separate from /. I want to stick /var/cache in RAM using tmpfs. The /etc/fstab entry would be quite simple:

tmpgs /var/cache tmpfs size=500M,rw,nodev,nosuid,noexec,noatime 0,0

However, I notice that without this entry du -sh shows the size-on-disk as:

# du -sh /var/cache
215M    /var/cache

Yet if I apply the above fstab entry, reboot, and run du -sh again I get:

# du -sh /var/cache
160K    /var/cache

Without the tmpfs entry the folders ldconfig, yum, fontconfig and man are present. When using the tmpfs fstab entry only the latter two are present.

I'm curious about this because:

  1. I don't understand when to use the bind mount flag.
  2. I have /run in a tmpfs mount and now I'm not so sure about the contents of that mount being the same as what would be present if I didn't.

Why is this?

2 Answers 2


Since you listed /var/cache in /etc/fstab, a tmpfs filesystem is mounted to /var/cache during the boot sequence. Any contents of /var/cache are shadowed by the mount point. The files underneath a directory on which another filesystem is mounted still exist, but they can't be reached, since a path like /var/cache/foo goes into the other filesystem.

For more information about discrepancies between df and du, see Why are there so many different ways to measure disk usage?

On Linux, you can expose the shadowed contents of /var/cache by creating a bind mount of /var. You can use this to remove the old cache files that you're no longer using:

mount --bind /var /mnt
rm -r /mnt/cache/*
umount /mnt

I'm not sure what you mean about /run, but note that each time you mount a tmpfs filesystem, you get a distinct filesystem. So /run and /var/cache are unrelated, there's no way for a file from one to appear in the other. They're two filesystems that just happen to be provided by the same driver.


The mount hides, or shadows, anything already present in the given directory (this may cause fun problems if the permissions are wrong on the thus shadowed dir). So when the tmpfs mount is removed, the original stuff will be there. (If the cache will need to persist, you could mv /var/cache /var/cache.save, and then do rsync things after the tmpfs is first mounted and before it is unmounted, but that's more complication.)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .