PDA

View Full Version : [ubuntu] How do I run a command on start up?



chrisod
June 6th, 2009, 12:37 AM
Ever since I upgraded to 9.04 my NAT drive does not mount on boot, and if I don't remember to mount the drive before opening Rhythmbox it dumps the music dB and I have to wait 5 minutes for it rescan my music drive after I mount it again.

Fstab is fine as sudo mount -a mounts everything normally. I don't know why it's not mounting but I'm fine with a workaround if I can find one.

How can I automate a sudo - mount -a command on every startup?

kerry_s
June 6th, 2009, 01:03 AM
post your fstab.

for now you can put " mount -a &" in /etc/rc.local it runs as root already so no need sudo.

chrisod
June 6th, 2009, 02:24 AM
My fstab...(the NAT drive has a static IP of 192.168.11.7) None of the NAT drive mounts are mounting at boot.


# /etc/fstab: static file system information.
#
# -- This file has been automaticly generated by ntfs-config --
#
# <file system> <mount point> <type> <options> <dump> <pass>

proc /proc proc defaults 0 0
# Entry for /dev/sda5 :
UUID=54bed292-dd3b-451d-b414-c4e8a70dc7b5 / ext3 defaults,errors=remount-ro,relatime 0 1
# Entry for /dev/sda6 :
UUID=579b6ae8-6bc8-495b-8006-6b896c4c8abb none swap sw 0 0
/dev/scd0 /media/cdrom0 udf,iso9660 user,noauto 0 0
/dev/sda7 /home ext3 nodev,nosuid,relatime 0 2
192.168.11.7:/shares/SimplePool/Music /mnt/music nfs rsize=8192,wsize=8192,timeo=14,intr 0 0
192.168.11.7:/shares/SimplePool/Photos /mnt/photos nfs rsize=8192,wsize=8192,timeo=14,intr 0 0
192.168.11.7:/shares/SimplePool/backups /mnt/backups nfs rsize=8192,wsize=8192,timeo=14,intr 0 0
192.168.11.7:/shares/SimplePool/NetFolder /mnt/NetFolder nfs rsize=8192,wsize=8192,timeo=14,intr 0 0

kerry_s
June 6th, 2009, 03:00 AM
what i think is happening is the mount is run before your network is up.
check your /var/log/messages for errors.

did the "mount -a &" work in /etc/rc.local ?

click4851
June 6th, 2009, 08:27 AM
what is the perferred way to add a mount point, other than during installation?

MrWES
June 6th, 2009, 11:30 AM
My fstab...(the NAT drive has a static IP of 192.168.11.7) None of the NAT drive mounts are mounting at boot.


# /etc/fstab: static file system information.
#
# -- This file has been automaticly generated by ntfs-config --
#
# <file system> <mount point> <type> <options> <dump> <pass>

proc /proc proc defaults 0 0
# Entry for /dev/sda5 :
UUID=54bed292-dd3b-451d-b414-c4e8a70dc7b5 / ext3 defaults,errors=remount-ro,relatime 0 1
# Entry for /dev/sda6 :
UUID=579b6ae8-6bc8-495b-8006-6b896c4c8abb none swap sw 0 0
/dev/scd0 /media/cdrom0 udf,iso9660 user,noauto 0 0
/dev/sda7 /home ext3 nodev,nosuid,relatime 0 2
192.168.11.7:/shares/SimplePool/Music /mnt/music nfs rsize=8192,wsize=8192,timeo=14,intr 0 0
192.168.11.7:/shares/SimplePool/Photos /mnt/photos nfs rsize=8192,wsize=8192,timeo=14,intr 0 0
192.168.11.7:/shares/SimplePool/backups /mnt/backups nfs rsize=8192,wsize=8192,timeo=14,intr 0 0
192.168.11.7:/shares/SimplePool/NetFolder /mnt/NetFolder nfs rsize=8192,wsize=8192,timeo=14,intr 0 0

Shouldn't that be //192.168.11.7:/blah/blah....

chrisod
June 6th, 2009, 04:29 PM
did the "mount -a &" work in /etc/rc.local ?

Nope - NAT drive did not mount on a reboot. Upon investigation it seems as though rc.local is never running due to a DNS error during boot when it can't find 192.168.11.7. So the problem does seem to be that it is trying to mount the drive before the network is up.

My first thought about a fix was to just comment out the mount commands from fstab and mount in the rc.local script. That isn't working because I'm still getting a mount.nfs DNS resolution error on 192.168.11.7 on boot, so the rc.local script never runs. I can start the rc.local script manually so I know the script is good, if I can just get it to run. I don't know why my laptop is trying to mount 192.168.11.7 when all 4 mount commands are commented out of fstab. Where else would be picking up the NAT drive from?

Any ideas?

chrisod
June 7th, 2009, 01:34 AM
OK, I understand what is going on...and I have a workaround. With Intepid and Jaunty, the network connection is not established until you log in. It has something to do with how Network Manager works. If you have a desktop or laptop that isn't particularly mobile, you can simply configure the network the old fashioned way in /etc/network/interfaces and you should be ok. I'm mobile, so that would be a PITA for me. I took the mount commands out of fstab, added them to rc.local, and put a sleep 180 at the top of rc.local to give the network time to come up after login. It works fine as long as I log in immediately, which I usually do. It's not a perfect solution but good enough for now.

kerry_s
June 7th, 2009, 03:36 AM
OK, I understand what is going on...and I have a workaround. With Intepid and Jaunty, the network connection is not established until you log in. It has something to do with how Network Manager works. If you have a desktop or laptop that isn't particularly mobile, you can simply configure the network the old fashioned way in /etc/network/interfaces and you should be ok. I'm mobile, so that would be a PITA for me. I took the mount commands out of fstab, added them to rc.local, and put a sleep 180 at the top of rc.local to give the network time to come up after login. It works fine as long as I log in immediately, which I usually do. It's not a perfect solution but good enough for now.

i would just script it than, remove everything from rc.local and deal with it on the user end.

example:
make sure you have pmount> sudo apt-get install pmount
pmount mounts as the user so you shouldn't have permission problems

mkdir ~/bin
gedit ~/bin/connect


#!/bin/sh
if [ -d "192.168.11.7:/shares" ] ; then
pmount 192.168.11.7:/shares/SimplePool/Music
pmount 192.168.11.7:/shares/SimplePool/Photos
pmount 192.168.11.7:/shares/SimplePool/backups
pmount 192.168.11.7:/shares/SimplePool/NetFolder
else
exit 0
fi

chmod +x ~/bin/connect

(might need to add sleep to that if the connections slow connecting)

then just add> connect to your session startup

not sure if that's correct but i would go that route. work it out on the user end. just my thought.

chrisod
June 7th, 2009, 01:54 PM
Thanks. I'll try the script and report back if it works.

click4851
June 7th, 2009, 07:18 PM
is pmount all cli or is there a gui?

chrisod
June 7th, 2009, 07:21 PM
I'm having trouble to pmount. I get this error when trying to mount a drive with pmount.


Error: could not determine real path of the device: No such file or directory

However, the path is correct. If I change pmount to sudo mount, and add a mount point at the end of the command it mounts fine.

Google has failed to deliver anything useful on the pmount error.

kerry_s
June 7th, 2009, 11:43 PM
i'm looking at the "man pmount" and it looks like you might have to use the /etc/pmount.allow
try putting the "192.168.11.7" in there.

actually i through that out there when i had a really bad headache, i'm not even sure pmount can do nat storage, it's made for removable devices, i figured nat is removable :) my thinking at the time.

perhaps the best thing is to use the standard mount and add a entry in visudo for no password.

$users ALL=(ALL) NOPASSWD: /sbin/mount, /sbin/umount

so just change the script:

pmount 192.168.11.7:/shares/SimplePool/Music
to
sudo mount 192.168.11.7:/shares/SimplePool/Music /mnt/music

chrisod
June 8th, 2009, 03:52 PM
The pmount man pages made reference to the -t option being valid, and it listed nfs as one of the valid options, so I think nfs is fine. I'll look into /etc/pmount.allow tonight when I'm back on my laptop. I'm stuck on XP at work.