Getting Some Extra CPU on Raspberry

I was just looking at my Raspberry Pi Zero and realized that I’m running stuff that I don’t need! Why am I wasting precious CPU cycles on the likes of cups (printer software), aplay and pulseaudio (sound software), Xorg, and lxpanel (the desktop GUI)? I’ll let avahi-daemon live for now. I think the DNS updates that it provides are helpful on other systems when I run something like “arp -a”.

root@zero-basement:~# top
top - 08:03:37 up 7 min,  3 users,  load average: 0.90, 0.68, 0.49
Tasks: 106 total,   1 running, 105 sleeping,   0 stopped,   0 zombie
%Cpu(s):  3.7 us,  4.3 sy,  0.0 ni, 91.7 id,  0.3 wa,  0.0 hi,  0.0 si,  0.0 st
MiB Mem :    477.6 total,    135.0 free,    139.6 used,    203.0 buff/cache
MiB Swap:    100.0 total,    100.0 free,      0.0 used.    282.6 avail Mem


  PID USER      PR  NI    VIRT    RES    SHR S  %CPU  %MEM     TIME+ COMMAND
  358 root      20   0   41124   9308   7620 S  24.2   1.9   0:01.10 cups-browsed
 1330 root      20   0   91192   5476   4816 S   3.5   1.1   0:00.11 aplay
  643 pi         9 -11  357180   8160   7044 S   2.3   1.7   0:05.16 pulseaudio

  243 avahi     20   0    5912   2972   2616 S   1.9   0.6   0:02.06 avahi-daemon
  248 root      20   0   36920   7924   6756 S   1.9   1.6   0:00.31 cupsd
  616 pi        20   0  409312  28940  23024 S   0.6   5.9   0:11.53 lxpanel
    9 root      20   0       0      0      0 S   0.3   0.0   0:02.05 ksoftirqd/0
...

Turn off the Sound Card on Raspberry Pi

Let’s get rid of sound, since this Raspberry is just a Zero that hosts a temperature probe in the basement. Create a file using vi or any text editor and save it in “/etc/modprobe.d/alsa-blacklist.conf”. The entire contents of the file should look like this:

blacklist snd_bcm2835

Save the file and reboot the machine. This does just what it looks like. It “blacklists” the module loader from installing the hardware drivers for the sound chip. This is also useful if you’re planning on installing a third-party sound HAT, like the HiFiBerry AMP2. Now, we just need to pull the software, but what’s the command? I dunno’ Let’s do a little digging:

root@zero-basement:~# apt search aplay | grep installed

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

alsa-utils/oldstable,now 1.1.8-2+rpt1 armhf [installed]
root@zero-basement:~#

A-ha! Now, let’s remove that!

root@zero-basement:~# apt remove alsa-utils
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
  libfftw3-single3 libsamplerate0 triggerhappy
Use 'apt autoremove' to remove them.
The following packages will be REMOVED:
  alsa-utils raspi-config
0 upgraded, 0 newly installed, 2 to remove and 12 not upgraded.
After this operation, 2,213 kB disk space will be freed.
Do you want to continue? [Y/n]

Uh-oh! Double-check that! This is going to remove “raspi-config” No! I like that program! I’m answering “N”. Let’s move on. Honestly, the reason aplay and PulseAudio were running was that the Raspberry GUI was running and there was a process that was offering screen reading to the visually impaired audience. Now that the GUI is gone, the process stopped.

Remove the GUI Desktop on Raspberry Pi

This is a big one! I’m running headless (no monitor or keyboard) and I only ever ssh in to this Raspberry, so I’m going to remove all the GUI software AND CUPS in one swell foop! There are actually two commands to run. The first one does what we want. The second one removes all the dependencies. Some software depends on lots of other software to be installed. The autoremove command removes all the extra stuff, all those extra dependencies, that you won’t be using anymore. (Caveat Emptor: if you plan on running VLC remote desktop, don’t remove the x11 stuff! You’re gonna need it.)

sudo apt-get remove --auto-remove --purge 'libx11-.*'
sudo apt-get autoremove --purge

Run the first command, answer “Y” and let ‘er rip! When it’s done, run the second command and answer “Y” and let that run too. You can actually run the second command again. The system might realize there were some secondary dependencies that could be removed as well. Try it a third time? You never know…

I think we’re good for now. Let’s run “top” again:

top - 09:31:12 up  1:06,  2 users,  load average: 0.08, 0.15, 0.38
Tasks:  87 total,   1 running,  86 sleeping,   0 stopped,   0 zombie
%Cpu(s):  2.0 us,  2.0 sy,  0.0 ni, 96.1 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
MiB Mem :    477.6 total,     59.2 free,     81.9 used,    336.5 buff/cache
MiB Swap:    100.0 total,     89.2 free,     10.8 used.    339.3 avail Mem

  PID USER      PR  NI    VIRT    RES    SHR S  %CPU  %MEM     TIME+ COMMAND
 6768 root      20   0   10292   3000   2476 R   1.3   0.6   0:00.53 top
  541 root      20   0  101764  37968   8692 S   1.0   7.8   2:02.99 salt-minion
  249 avahi     20   0    5908   2920   2572 S   0.7   0.6   0:16.09 avahi-daemon
  772 root      20   0   12188   5856   5040 S   0.3   1.2   0:03.66 sshd
 3534 root      20   0       0      0      0 I   0.3   0.0   0:03.36 kworker/u2:1-brcmf_wq/mmc1:0001:1
 6766 root      20   0       0      0      0 I   0.3   0.0   0:00.25 kworker/0:3-events
    1 root      20   0   34784   8080   6200 S   0.0   1.7   1:48.78 systemd
    2 root      20   0       0      0      0 S   0.0   0.0   0:00.02 kthreadd

That’s better! “salt-minion” is a program that I use for configuration management. The rest looks good!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.