1

Is it possible to run a system command such as mount a certain amount of time after system reboot?

My problem is that I had an entry in /etc/fstab to mount a host disk in a Linux (Ubuntu) virtual machine. A direct mount wouldn't work because of some timing issues in loading kernel modules. So I used a noauto option in fstab and added a line in /etc/rc.local to mount /some_disk.

This had worked for Ubuntu (12.04 & 14.04), but now I switched to Lubuntu. And the above no longer works. I guess it's probably because Lubuntu reboots much faster, and rc.local is executed early. BTW, I verified that other commands in rc.local execute fine. And mount /some_disk works when sudo'ed after the system is up.

So I wonder how to postpone mount /some_disk in a script like rc.local, say 1 minute after the reboot?

Note: I can do

sudo mount /some_disk

successfully seconds after reboot (GUI is up).

1
  • Use sleep 60; mount /some_disk? Commented Oct 23, 2014 at 15:27

3 Answers 3

1

Yes it's possible. just create an init script and place it into /etc/init.d/.

Then register the script with the different runlevels. via the following command:

update-rc.d <scriptname> defaults 99 01 

The 99 means, it is called at the very end of the boot process.

Sophisticated daemon scripts look like /etc/init.d/skeleton.

However, as your script is not a supposed to be a daemon at all, the following script should work.

#!/bin/sh

case "$1" in
  start)

    sleep 60
    # your code

    ;;
esac

quit 0
0
2

The answer of @D Schlachter is a good idea, but lacks in the point of the command needed to be executed as root. Nevertheless, you can use the systemwide crontab in /etc/crontab or the root's crontab,

sudo crontab -e

Please note the syntax difference between those files, since the system-wide crontab needs an extra column for the user the command will be executed as.

@reboot root sleep 60; mount /some_disk
1

You can use cron. Add this line to your crontab (crontab -e):

@reboot sleep 60 ; mount /some_disk

[1] [2]

1
  • Thanks. This however, does not seem to work. I don't know if it executes the mount as root, or something else is going on. I still have no mount, but I can get a mount manually seconds after reboot.
    – tinlyx
    Commented Oct 23, 2014 at 15:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .