Tuesday, June 17, 2008

Better way to mount network share in Ubuntu

A while ago I posted about mounting my Maxtor NAS as a local drive in Kubuntu using smbfs. This did not work for pas\sword protected shares. Hello cifs! So linux guru at work sent me a sample cifs command and I searched and tweaked and ended up with all this.

1. Used this for the unprotected share. Gave an error if no "username=" and "password=" so if there's a better way than using blank username/password please leave me a comment because I didn't find it with a quick search. (watch the line wrap if you copy/paste this, each > should be one line)

> sudo mkdir /mnt/nas
> sudo mount -t cifs //[share name or IP]/[share directory] /mnt/nas -o username=,password=,iocharset=utf8,file_mode=0777,dir_mode=0777

- Same command to access protected share, just add username and password values.

2. Now we alias this in .bashrc so a single command will mount the network share. I was browsing through the file and noticed a recommendation to use .bashrc_aliases. Cool, something new, I'm game.

> vi .bashrc_aliases
Insert

alias mountnas='sudo mount -t cifs //[share name or IP]/[share directory] /mnt/nas -o username=,password=,iocharset=utf8,file_mode=0777,dir_mode=0777'

3. Next uncomment call in .bashrc for .bashrc_aliases.
if [ -f ~/.bash_aliases ]; then
. ~/.bash_aliases
fi

4. Run this to re-initialize .bashrc without restarting terminal
> . .bashrc

So now I can get my music down to the mini. Soon to come, Amarok configuration...

No comments: