Let’s say you need to reboot a headless system running Linux. How do you check when it’s back online, and IF it’s back online? You can start pinging it, sure, but what if you are right next to it in the same room? Is there a better way to get instantly notified when your system is back up?

Sure there is! Make it beep at you when it’s ready 😄. We will use a piezoelectric speaker, aka. buzzer, that’s built into most computers, so that it sends few short beeps when the system is booted.

I’m using Ubuntu Server 20.04 LTS here as an example, but this should be similar on other distros.

First, we need to enable kernel module responsible for buzzer support. By default it’s disabled in Ubuntu. So let’s edit the blacklist:

sudo vim /etc/modprobe.d/blacklist.conf

Find and comment out this line to enable PC speaker. Add # at the front:

#blacklist pcspkr

Oh, look, there’s a comment from the developer!

# ugly and loud noise, getting on everyone's nerves; this should be done by a
# nice pulseaudio bing (Ubuntu: #77010)

Right, but what if I don’t want to connect speakers to my headless system? I have a buzzer that’s already built in.

At this point, you can either restart your server or load the module manually like this, then check if it’s loaded:

sudo modprobe pcspkr
lsmod | grep pcspkr

Now, install beep:

sudo apt -y install beep

Test it. It should beep at you:

sudo env -i beep

Next, prepare a simple script that we will trigger later on reboots:

sudo vim /usr/local/sbin/beep-me.sh

Paste this content there:

#/bin/bash
beep -f 5000 -l 50 -r 2

This will send two short beeps when triggered, with a higher pitch than the default (and annoying) ones. If you want to adjust it, see beep man page for info. You can even make it play a short melody if you wish (imperial march, maybe?).

Next, edit crontab:

sudo vim /etc/crontab

Add this line at the bottom of your crontab to trigger our script once on every reboot:

@reboot root /usr/local/sbin/beep-me.sh

Since we edited main crontab directly (skipping validation), it’s a good practice to check if we did it right. Restart cron and check it’s status to make sure it’s running correctly:

sudo systemctl restart cron
sudo systemctl status cron

Now your system will beep at you to let you know it’s ready after reboots.