Automatically mount directories in centos / virtualbox

Posted by alexmoreno on Mon, 21/01/2013 - 18:29

If you try to mount a shared folder in centos, runing under a virtual box, you'll probably have problems trying to fix this directory, mounting automatically each time the system reboots.

In any other distribution, like ubuntu, you just have to go to your /etc/fstab and add this line:

varhtml                 /var/www/html   vboxsf  defaults        0 0

The problem is centos is that when the system arrives to this line, the vboxsf module has not been loaded yet.

The solution is quite simple, execute a mount command when everything has been loaded. This can be done in /etc/rc.local:

mount  /var/www/html

Your fstab must give information about this directory (like you've seen in mine), or use the large version of mount command.

As you can read in rc.local:

This script will be executed *after* all the other init scripts.

So, there is probably a better way to do this, but this one does the trick too :-).

categorias: