I need to mount a shared folder at a boot up automatically so I don't have to manually write this line to the xterm every time:
sudo mount -t vboxsf share ~/host
I have done this:
sudo crontab -e
And added at the end of the file:
@reboot /home/richard/mounthost
The file /home/richard/mounthost contains:
sudo mount -t vboxsf share ~/host
But it is not working. Any help?
I am using Ubuntu 10.10
For mounting on boot, you should add it to
/etc/fstab
. Take a look here:The proper place to add filesystems to be mounted on boot is
/etc/fstab
. See thefstab(5)
man page for details.Add a line to /etc/fstab. This will mount the file system at startup, The header will show you which column to place the various option. Use
man mount
and man fstab for additional information.The other answers here have already pointed out the proper way of specifying boot-time mounts.
So why does your script not work? Have you set execute permissions on it? e.g.
Perhaps the device is not yet ready to be mounted at the point in time when cron runs its @reboot jobs? Check the system logs for messages.
Finally, a note about system security: It is very bad policy to run scripts from the root crontab that are not owned by root! If the
richard
account is ever compromised, an intruder can gain root access by modifying/home/richard/mounthost
. If you decide not to put your device into/etc/fstab
, I would strongly recommend changing your crontab entry so that it runs themount
command directly, and does not run a non-root-owned script.