Introduction: Raspberry Pi Startup and Shutdown Sound

About: I am a middle schooler who enjoys making things, especially gadgets and anything that has to do with aquariums. I have had a side hobby of photography for a few years now and use that skill with my other hobby…

As many old computers had startup and shutdown sounds, I wanted my raspberry pi to do the same. Using some mp3 files and a system file, my method is easy to recreate. Enjoy!

Supplies

Raspberry Pi running Raspberry Pi OS (I am using a pi 400, but any will work)

Mouse

Keyboard

Step 1: Find Your Sounds

I have always been pretty fond of the Windows XP sounds, so I will be using those, though any .mp3, .m4a, or .wav file will work. I downloaded my sounds from winhistory.de, which has a wide assortment of windows startup and shutdown sounds, free.

Step 2: Save Your Sounds

Save your sounds as startup.mp3, and shutdown.mp3, changing the endings to your file type. Move them to /home/pi/Downloads if they are not already there, and continue.

Step 3: Move Your Sounds

You can't move files in the os folders, so you will have to use the terminal for these steps.


Ensure that you have sudo privileges, then open your terminal and enter:

sudo mkdir /etc/sound

This makes a folder in /etc called "sound". This is where your sound files will go. To move them there, enter

sudo mv /home/pi/Downloads/startup.mp3 /etc/sound

and

sudo mv /home/pi/Downloads/shutdown.mp3 /etc/sound


These commands will move your sound files to the "sound" folder.

Open your file manager, and go to /etc/sound, and make sure that your files are there. If they are, you can move on.

Step 4: Create .service File

Next, you have to create a .service file called "sound.service". Open a new terminal, and enter

sudo nano /etc/systemd/system/sound.service

This creates a new file called "sound.service" located in '/etc/systemd/system' in the nano editor. After entering the command, you will be presented with a blank text editor, which is your files contents. Paste the following code into the editor:

[Unit]
Description=Runs script at system shutdown

[Service]
Type=oneshot
RemainAfterExit=true
ExecStart=/bin/omxplayer /etc/sound/startup.mp3
ExecStop=/bin/omxplayer /etc/sound/shutdown.mp3

[Install]
WantedBy=multi-user.target

Let me explain what this does. The top '[Unit]' lines do nothing to the script, but they let the user see what the purpose of the file is. The '[Service]' lines are the actual scripts. 'Type' declares the type of script it is, and 'RemainAfterExit' declares whether or not the the 'Exec' commands should be run after the service is stopped. 'ExecStart' and 'ExecStop' are short for "Execute on Start" and "Execute on Stop". The file paths after those tell the pi to open your sound files using omxplayer. And '[Install]' and 'WantedBy' tells the pi what file to use to run the script.

After you finish pasting your code, use Ctrl + O to write out (save) your file, click enter to confirm the file to write, and then Ctrl + X to exit the editor.

Step 5: Enable Your Script

The last step is to enable your script. To do this, open another terminal, and type

sudo systemctl enable sound

This enables your script so that it will run on start-up, and stay active until shutdown.

Step 6: Reboot

All thats left is to reboot your pi so the changes take effect. Type

sudo reboot

into your terminal. If you did everything correctly, you should be greeted with the chime of your sound when the pi finishes booting. If your sound starts late so you only hear the last half of it, change your sound files so they have about 2 seconds of silence before the actual sound starts. If you hear no sound at all, go back into your scripts, and check your file paths. If that doesn't work, try re-enabling the script. If you still can't get it to work, leave a comment, and I will do my best to help you out.

Good Luck!

Raspberry Pi Contest

Participated in the
Raspberry Pi Contest