34

As stated in Why is my Audio (Sound) Output not working?, to initialise the sound driver, you must run sudo modprobe snd_bcm2835 every time you want to output sound.

How do I get this to run on boot? (i.e. before logging in and without any input)

Alex Chamberlain
  • 15,530
  • 14
  • 67
  • 113

4 Answers4

25

Loading modules at boot is a little different to running startup commands.

In Debian:

Add the module name as a new line in /etc/modules

In Arch Linux:

Add the module name to the module array in /etc/rc.conf, the line should look like this:

modules=(snd_bcm2835)

Or for the new systemd configuration:

echo "snd_bcm2835" | sudo tee -a /etc/modules-load.d/snd_bcm2835.conf
Jivings
  • 22,538
  • 11
  • 90
  • 139
  • I added snd_bcm2835 to the /etc/modules file on my Xbian but that created a loop at boot time. this seems not be allowed when starting OSMC – rubo77 Jun 17 '15 at 15:55
  • @rubo77 Interesting! Did you get to the bottom of it? – Jivings Jun 22 '15 at 08:11
  • Not sure. Maybe it was a coincident. The whole installation seems a bit broken by now... – rubo77 Jun 22 '15 at 11:27
14

Modprobe on Boot - Debian

To answer the specific question about sudo modprobe snd_bcm2835, add the module to /etc/modules and reboot. (You will need to be root to do this.)

Starting services - Debian

Debian using initscripts to initialise the system, and you can use them to run arbitrary commands. You need to install a script similar to the following in /etc/init.d.

#! /bin/sh
# /etc/init.d/blah
#

# Some things that run always
touch /var/lock/blah

# Carry out specific functions when asked to by the system
case "$1" in
  start)
    echo "Starting script blah "
    echo "Could do more here"
    ;;
  stop)
    echo "Stopping script blah"
    echo "Could do more here"
    ;;
  *)
    echo "Usage: /etc/init.d/blah {start|stop}"
    exit 1
    ;;
esac

exit 0

You should ensure it is runnable and owned by root.

sudo chmod 755 /etc/init.d/blah
sudo chown root:root /etc/init.d/blah

Then you need to register it to run at startup.

sudo update-rc.d blah defaults

References

jminardi
  • 133
  • 8
Alex Chamberlain
  • 15,530
  • 14
  • 67
  • 113
3

There are loads of ways of running a command at start-up in Linux but my favoured approach is to create an initialisation script in /etc/init.d and register it using update-rc.d. This way the application is started and stopped automatically when the system boots / shutdowns.

See this post for a set of instructions on how to create one on the Raspberry Pi.

Avio
  • 1,217
  • 2
  • 14
  • 25
Martin O'Hanlon
  • 616
  • 5
  • 11
0

My preferred approach would be to add the setup command to /etc/rc.local where it would be initialised at the end of boot, before you are asked to login.

Will
  • 380
  • 4
  • 17