Ubuntu: Want to mount tmpfs on /tmp

I thought perhaps there might be an Ubuntu guru reading this...

I am running Ubuntu Lucid Lynx off an SD card on my Mele A1000 ARM box.

It is a normal "full" install, and I think that it is hitting the SD card really hard, that is, lots of writes to it. In particular, a lot of stuff happens on /tmp, and I would like to mount a tmpfs (in RAM) onto /tmp at bootup.

However, I am unfamiliar with the init/bootup scripts used in Ubuntu -- is it the 'launchd' system? Anyway, I will need to mount the tmpfs on /tmp as early as possible in the bootup, and I cannot see what script to put it into.

In Puppy, I would do that in /etc/rc.d/rc.sysinit, right after remounting '/' as rw.

Posted on 28 Apr 2012, 17:32


Posted on 28 Apr 2012, 20:37 by Dougal
tmpfs /tmp
Ubuntu and Debian are actually moving to it as the default. A quick google search finds this:

Posted on 29 Apr 2012, 7:49 by K Godt
mount /tmp
Interestingly the kernel overlays the current directory on HDD if /dev or /tmp gets mounted on their specific filesystems (devtmpfs/tmpfs)

mkdir /tmp_new

cp -a /tmp/* /tmp_new
cp -a /tmp/.[a-zA-Z0-9]* /tmp_new
mount -t tmpfs none /tmp
cp -a /tmp_new/* /tmp
cp -a /tmp_new/.[a-zA-Z0-9]* /tmp
rm -r /tmp_new

none on /tmp type tmpfs (rw,relatime)
mkdir /tmp_new

cp -a /tmp/* /tmp_new
cp -a /tmp/.[a-zA-Z0-9]* /tmp_new
umount /tmp
cp -u /tmp_new/* /tmp
cp -u /tmp_new/.[a-zA-Z0-9]* /tmp
rm -r /tmp_new

So the original /dev or /tmp directory still exist underneath and don't have to be created new if umount ing the temporary /directory .
For now i encountered only a problem with an already running pmount having some files in there . pup_event_frontend_d handles the switch nicely until now .

Solution #1: Mount /tmp as tmpfs in /etc/init.d scripts

Posted on 29 Apr 2012, 8:20 by BarryK
/tmp solution
K Godt,
Thanks for that link.

Solution #1 does not work, as there is no /etc/init.d/mountkernfs.sh file. I think that is for an older version of Ubuntu.

I have gone for Solution #2, put an entry into /etc/fstab:
tmpfs /tmp tmpfs nodev,nosuid,noexec,mode=1777 0 0

...except, I took out the 'noexec'.
...um, shouldn't have 'auto' in it?

Which reminds me, my USB hard drive is getting mounted with 'nodev', which prevents me for compiling source packages in it.
I have to manually unmount the mount it myself.

I don't know where that 'nodev' gets set for USB drives, maybe a udev rule?
Whatever, when I get a SATA hard drive, I will put entries into /etc/fstab to mount a swap partition, and a working partition (with the options that I want).

Posted on 29 Apr 2012, 9:13 by K Godt
man mount
That was dougal finding the Page ..

man mount reads like

If no -t option is given, or if the auto type is specified,mount will try to guess the desired type. Mount uses the blkid or volume_id library for guessing the filesystem type; if that does not turn up anything that looks familiar, mount will try to read the file /etc/filesystems, or, if that does not exist, /proc/filesystems. All of the filesystem types listed there will be tried, except for those that are labeled "nodev" (e.g., devpts, proc and nfs). If /etc/filesystems ends in a line with a single * only, mount will read /proc/filesystems afterwards.

nodev Do not interpret character or block special devices on the file system.

where i am unsure about "interpret" character-block special devices .. read them like cat /dev/tty1 _?

Posted on 29 Apr 2012, 11:03 by BarryK
Maybe 'noexec'
Ah, maybe it was the 'noexec' that caused trouble for my usb hard drive.

Posted on 29 Apr 2012, 20:01 by Dougal
USB Drive
"I have to manually unmount the mount it myself."
"mount -o remount" with the other options added would be easier.
You could also add an fstab line based on your USB drive's UUID...

Posted on 3 May 2012, 23:58 by PeterM321
<<It is a normal "full" install, and I think that it is hitting the SD card really hard, that is, lots of writes to it. In particular, a lot of stuff happens on /tmp,...>>

There are quite a few options to mount a /tmp tmpfs volume, the one I ended up choosing was

declare ramsize=300
mount -t tmpfs -o size=${ramsize}m,atime,diratime,rw /dev/shm /tmp

However, if you are wanting to save a USB device a few more write cycles it may be worth considering re-assigning the $HOME directory. (The hidden files in particular get written to rather frequently):

mkdir /tmp/home
cp -ar $HOME /tmp/home
mount --bind $HOME /tmp/home