Ubuntu – How to mount /tmp in /mnt on EC2

amazon ec2fstabUbuntuubuntu-12.04

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.

Best Answer

There are a couple problems with the initial suggestion you list, though it seems like it's headed in a good direction:

  1. For security purposes, the mkdir command should create the directory with the sticky bit set in the mode:

    mkdir -m 1777 /mnt/tmp
    
  2. 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.

Related Topic