Search code examples
ubuntucron

Cron job to Mount AWS EFS on Startup - Ubuntu


I have a Ubuntu 18 Version and AWS EFS storage which i am mounting as NFS. I created a script called mount.sh and gave exe permission. I am able to run the script and the EFS is getting mounted. I wanted this to be auto executed during the system start up.

I created a sudo crontab - e with below command

@reboot sleep 120 /script/mount.sh

Mount.sh has the below command

   sudo mount -t nfs4 -o  
   nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2,noresvport  
   fs-xxxxxx.efs.ap-south-1.amazonaws.com:/ /efs

Can you help me with mounting this EFS on system startup. Very new to Ubuntu.


Solution

  • As of your requirement what I get is you want to mount AWS EFS with EC2 on reboot or startup. For those who still looking for a solution to mount EFS with EC2 on startup/reboot, My Answer to this Question might help them.

    Instead of creating a cronjob, you can use the fstab

    Steps to mount EFS on startup:

    1. sudo nano /etc/fstab
    2. Add below line at the bottom of the file: fs-xxxxxx.efs.ap-south-1.amazonaws.com:/ /efs nfs4 _netdev 0 0
    3. Then press Ctrl + x to save the file.

    This way your EFS will automatically mount on reboot For more information, you can watch this video

    I hope this will help you! Good Luck.