Skip to content

Instantly share code, notes, and snippets.

@forksofpower
Last active August 18, 2023 04:53
Show Gist options
  • Save forksofpower/0df7049ad0e478ef4c8326991a539fd5 to your computer and use it in GitHub Desktop.
Save forksofpower/0df7049ad0e478ef4c8326991a539fd5 to your computer and use it in GitHub Desktop.
startup sounds in linux

How to add startup sound to linux

I use this implementation on my RuneAudio player to play a sound when the raspberry pi is powered on.

  1. Place your audio file in /var/local/

    cp startupsound.mp3 /var/local/
  2. Create /usr/bin/startupsound.sh with these contents:

    #!/bin/sh
    # uses mpg123 to play /usr/local/startupsound.mp3 through
    # the card 1 interface. It uses a buffer of 10000kb to make
    # up for a delay in some recievers using optical input.
    /usr/bin/mpg123 -a hw:1,0 -b 10000 /usr/local/startupsound.mp3
  3. Make it executable

    chmod +x /usr/bin/startupsound.sh
  4. Test to make sure the sound is playable

    /usr/bin/startupsound.sh
  5. Create /usr/lib/systemd/system/startupsound.service

    [Unit]
    Description=Startup Sound
    After=alsa-restore.target
    
    [Service]
    Type=oneshot
    ExecStart=/usr/bin/startupsound.sh
    
    [Install]
    WantedBy=multi-user.target
  6. Reload the systemd service files

    systemctl daemon-reload
  7. Test the service by starting it (make sure your speakers are on!)

    systemctl start startupsound
  8. Enable the sound at boot

    systemctl enable startupsound

If the service does not run, check the log

journalctl -u startupsound
[Unit]
Description=Startup Sound
After=alsa-restore.target
[Service]
Type=oneshot
ExecStart=/usr/bin/startupsound.sh
[Install]
WantedBy=multi-user.target
#!/bin/sh
# uses mpg123 to play /usr/local/startupsound.mp3 through
# the card 1 interface. It uses a buffer of 10000kb to make
# up for a delay in some recievers using optical input.
/usr/bin/mpg123 -a hw:1,0 -b 10000 /usr/local/startupsound.mp3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment