How to mount /tmp in /mnt on EC2?
I was wondering what is the best way to mount the /tmp
endpoint in the ephemeral storage /mnt
on an EC2 instance and give the ubuntu
user default write permissions.
Some suggest editing /etc/rc.local this way:
mkdir -p /mnt/tmp && mount --bind -o nobootwait /mnt/tmp /tmp
However that doesn't work for me (files differs).
I tried editing the default fstab entry:
/dev/xvdb /mnt auto defaults,nobootwait,comment=cloudconfig 0 2
replacing /mnt with /tmp and and giving it a umask=0777, however it doesn't work because of cloudconfig.
I'm using Ubuntu 12.04. Thanks.
Solution 1:
There are a couple problems with the initial suggestion you list, though it seems like it's headed in a good direction:
-
For security purposes, the
mkdir
command should create the directory with the sticky bit set in the mode:mkdir -m 1777 /mnt/tmp
The
-o nobootwait
doesn't seem necessary as this is not being saved in/mnt/fstab
.
So, I'd recommend trying this in /etc/rc.local
:
test -d /mnt/tmp || mkdir -m 1777 /mnt/tmp
mount --bind /mnt/tmp /tmp
Any attempt to put the bind mount in /etc/fstab
is going to run into problems when you stop/start the instance or when you create an AMI and run a new instance as /mnt is ephemeral storage and all contents (including the /mnt/tmp
directory) are going to disappear.
Solution 2:
A more robust approach, since you're running Ubuntu, would be to put Eric Hammond's suggestion inside an Upstart script, and have the bind done immediately after mounting /mnt
:
# File /etc/init/mounted-mnt.conf
# mounted-mnt - Binds /tmp to /mnt/tmp
description "Binds /tmp to /mnt/tmp"
start on mounted MOUNTPOINT=/mnt
task
script
test -d /mnt/tmp || mkdir -m 1777 /mnt/tmp
mount --bind /mnt/tmp /tmp
end script
Some servers, like Apache/Passenger, might create important temporary files on /tmp
. Once rc.local
– the last in the boot sequence – ran they would get hidden and confuse the servers.