Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Is it possible to mount a Samba network share on start-up using the .bashrc file

In my fstab I got //192.168.1.104/ant /media/ant cifs gid=users,file_mode=0664,dir_mode=0775,auto,username=***,password=*** 0 0 but this is not working only when editing the fstab file and running mount -a, so I though maybe it will work if I use the .bashrc file?

share|improve this question
1  
Recent Linux distributions treat /media specially. Have you tried a different mount point? –  Michael Hampton Jul 30 '12 at 7:33
    
@MichaelHampton - Not let, I'll try that and then check if it's working –  Roland Jul 30 '12 at 8:07
add comment

3 Answers 3

up vote 2 down vote accepted

To answer your headline question yes, it is possible to mount your /media/ant from a .bashrc simply put

mount /media/ant 

in the relevant file. Unfortunately you have to run mount as root so you have to arrange arrange for the particular user to be able to run mount as root e.g. via sudo. This gets complicated and introduces other security issues.

As configured the /media/ant directory will be mounted when your system is started or when a root capable account issues a suitable mount command e.g. mount -a. If this doesn't do what you want then you probably want to configure the automounter to mount he share when it is accessed e.g.

Edit /etc/auto.master and add a line like

/media /etc/auto.cifs

Edit /etc/auto.cifs

ant -fstyp=cifs,gid=users,file_mode=0664,dir_mode=0775,auto,username=***,password=*** ://192.168.1.104/ant

Restart your autofs service

service autofs restart

or

/etc/init.d/autofs restart

Now when you try to access the /media/ant files it should be autmagically mounted. As noted in the comments it'll probably be a good idea to use a different mount point.

share|improve this answer
add comment

Another option could be a PAM from the project pam_mount.

It would be most useful if you are trying to do this with many or most users that login to this computer. After you configure PAM and pam_mount, everything is done for you automatically during the login process, including the username/password exchange for (in this case) your SAMBA share.

This is most useful if you are using a central database for usernames and passwords across multiple machines. In our case we are using Active Directory, but any username/password lookup that works with PAM would be acceptable (ie: Kerberos, LDAP, etc).

Not knowing your exact setup, I just wanted to put that option out there for you because it could be a better solution depending on what you are trying to achieve and the scale you are trying to implement.

share|improve this answer
add comment

All you need to do in order to make this work is enable the netfs system service. This was covered in your earlier question here.

Just make sure that the netfs service is set to start upon boot. This can be done in the ntsysv menu or by a simple chkconfig netfs on. Reboot and the NFS and SMB/CIFS mounts defined in /etc/fstab will mount as requested.

Note: I'd probably use a different mountpoint, as /media is reserved in the RPM-based distributions.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.