[LIVE] rc.local to automount a SMB share
#1
Guys
I'm actually using an Apple TV with a minimal Ubuntu image.

I'm having trouble with mounting my NAS share on boot. I have tested that the command works at the command line, but it doesnt seem to work in rc.local. Any thoughts?

My rc.local looks like this :

Code:
until ( ifconfig en0 ; ifconfig en1 ) 2>/dev/null | grep -q 'inet ' ; do  sleep 2
done
ping -c2 192.168.0.1   # Ping twice for the first packet
sudo -u xbmc smbmount //192.168.0.117/Public ~/nas
exit 0
AFTV Stick 4K
AFTV (Gen 1)
Reply
#2
Why not just put an entry in /etc/fstab?
Reply
#3
gsgleason Wrote:Why not just put an entry in /etc/fstab?

It looks like the network isn't up prior to the entry in fstab being actioned - is there a way to work around that?

I'm seeing a "network unreachable" error displayed during boot prior to CIFS mount errors.
AFTV Stick 4K
AFTV (Gen 1)
Reply
#4
Seems weird you'd have interfaces called 'en0' using Linux.

I to have a minimal install of ubuntu on an ION box, and the network is certainly up in time for fstab mounts to work, though I'm using nfs instead of samba.
Reply
#5
First things first... get rid of 'sudo -u'. It is not needed in rc.local, as it is running as root.

I would put this in rc.local:

Code:
sleep 30 && xbmc smbmount //192.168.0.117/Public ~/nas &

What it does is sleep for 30 seconds before trying to mount. That way everything is initialized a running before trying to mount. Once it is working you can try and lower the 'sleep' amount.

Also I do not understand why 'xbmc' is in there, but if it works on the command line then it should work here.

Jerry
Reply
#6
jawilljr Wrote:First things first... get rid of 'sudo -u'. It is not needed in rc.local, as it is running as root.

I would put this in rc.local:

Code:
sleep 30 && xbmc smbmount //192.168.0.117/Public ~/nas &

What it does is sleep for 30 seconds before trying to mount. That way everything is initialized a running before trying to mount. Once it is working you can try and lower the 'sleep' amount.

Also I do not understand why 'xbmc' is in there, but if it works on the command line then it should work here.

Jerry

Also, since this is running as root, ~/nas is going to be /root/nas. Is that what you want? Maybe use the full path instead, if not.
Reply
#7
Thanks guys.

I understand from the developer of the image that rc.local doesn't actually run at start up!

Is there a way to make it run at start up? If so I'll try the suggestions.
AFTV Stick 4K
AFTV (Gen 1)
Reply
#8
frumpy_uk Wrote:Thanks guys.

I understand from the developer of the image that rc.local doesn't actually run at start up!

Is there a way to make it run at start up? If so I'll try the suggestions.

that's weird, esp for a minimal ubuntu image.

It should start via a symlink in /etc/rc2.d/

Code:
$ ls -l /etc/rc2.d/S99rc.local
lrwxrwxrwx 1 root root 18 2010-06-03 13:07 /etc/rc2.d/S99rc.local -> ../init.d/rc.local

Do you have that?
Reply
#9
gsgleason Wrote:Also, since this is running as root, ~/nas is going to be /root/nas. Is that what you want? Maybe use the full path instead, if not.

Oops I missed that... that probably should be changed to '/home/user/nas'. Of course change 'user' to whatever the user is.

Jerry
Reply
#10
Thanks so far.

In order to rule out other stuff, I'm trying to just get the mount command verified.

So I now have in rc.local
Code:
smbmount //192.168.0.117/Public /home/xbmc/nas

If I run rc.local from the command line I get
Code:
mount error: permission denied or not superuser and mount.cifs not installed SUI

But if I sudo /etc/rc.local it works. So we're getting somewhere.


@gsgleason: here's the output
Code:
xbmc@AppleTV:~/nas$ ls -l /etc/rc2.d/S99rc.local
lrwxrwxrwx 1 root root 18 2010-06-07 18:36 /etc/rc2.d/S99rc.local -> ../init.d/rc.local

And this makes me wonder - am I editing the correct file...? I'm editing /etc/rc.local
AFTV Stick 4K
AFTV (Gen 1)
Reply
#11
Try my 'sleep 30' trick... it won't hurt.

Code:
sleep 30 && smbmount //192.168.0.117/Public /home/xbmc/nas &

Jerry
Reply
#12
Yes, the file is /etc/rc.local.

Normally it looks like this:
Code:
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

exit 0

So, add the shebang.

rc.local is very picky. Every command must work well. To test if it's even working at all, try commenting out everything you have, and add this:
echo "it works" > /tmp/test

And reboot. Then, see if that file exists with that text.
Reply
#13
gsgleason Wrote:Yes, the file is /etc/rc.local.

Normally it looks like this:
Code:
!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

exit 0

So, add the shebang.

rc.local is very picky. Every command must work well. To test if it's even working at all, try commenting out everything you have, and add this:
echo "it works" > /tmp/test

And reboot. Then, see if that file exists with that text.

On my rc.local the
Code:
!/bin/sh -e
is commented out. Should I uncomment it?
AFTV Stick 4K
AFTV (Gen 1)
Reply
#14
frumpy_uk Wrote:On my rc.local the
Code:
!/bin/sh -e
is commented out. Should I uncomment it?

Mine was a paste error.

It should read:
Code:
#!/bin/sh -e
Reply
#15
One more thing, are you putting the 'smbmount' before this command:

Code:
exit 0

If you are putting it after the exit command then it will never get run.

Jerry
Reply

Logout Mark Read Team Forum Stats Members Help
[LIVE] rc.local to automount a SMB share0