Posts: 587
Joined: Mon Oct 22, 2018 11:25 pm
Location: Seattle, WA
Contact: Twitter

Raspbian Lite-Er

Fri Aug 09, 2019 12:11 am

I'm sure I'm not the only one who likes their Raspbian lean and mean. I thought I'd share the configuration changes that I've found that make Raspbian Lite (or Full...all work on both) even...lighter :lol: . These all work on both Stretch and Buster. Each of these items is completely independent of the others. You can implement none, one, some, or all.

Have some of your own to share? Or feedback or corrections? Great!

* Disable TriggerHappy: If you're not using TriggerHappy's global hot keys, completely disable TriggerHappy
  • Why it's better: One less process running
  • How to configure:

    Code: Select all

    sudo -s
    mv /usr/sbin/thd /usr/sbin/.thd           # Minutely speeds up /etc/init.d/raspi-config.service
    systemctl disable triggerhappy.service
    systemctl disable triggerhappy.socket
* ssh: Let systemd start sshd server processes on demand
  • Why it's better: One less process running
  • How to configure:

    Code: Select all

    sudo -s
    systemctl disable ssh.service
    systemctl enable ssh.socket
* VNC: Let systemd start VNC server processes on demand
  • Why it's better: No VNC servers running when not being used, and it easily and simultaneously supports multiple screen resolutions
  • How to configure: See
Disable rsyslogd: rsyslogd isn't really needed any more. Why are you running it?
  • Why it's better: Journalctl does a fantastic job of logging. In fact, all the logging is done through journalctl and by default forwarded on to rsyslogd. Unless you need the bare text file logs in /var/log, you can disable the rsyslogd service and eliminate one process
  • One caution: If you're using logwatch you'll need to make a couple minor tweaks until the changes make their way into logwatch. Ask me about them if needed
  • How to configure:

    Code: Select all

    sudo -s
    systemctl disable rsyslog.service
    sed -i "s/\#ForwardToSyslog=yes/ForwardToSyslog=no/" /etc/systemd/journald.conf
    mkdir /etc/logrotate.d/.save
    mv /etc/logrotate.d/rsyslog /etc/logrotate.d/.save
    # If you want the journal to be permanent, execute the next 2 lines. If you want the journal wiped between reboots don't do these
    # This assumes that the default in /etc/systemd/journald.conf is set to the default: #Storage=Auto
    mkdir /var/log/journal
    systemd-tmpfiles --create --prefix /var/log/journal
In case they're helpful, here are the journalctl command aliases that I've added to my bash login file (.bashrc or wherever you prefer to put them):

Code: Select all

alias jc='journalctl -b'               # Show msgs from this boot only. Use 'jc -1' to see messages from the previous boot if journal is permanent (1 for 1st prior, 2, etc...)
alias jca='journalctl'                 # Lists all journal entries from all boots
alias jcf='journalctl -f'              # Lists the journal in 'tail' mode
alias jcr='journalctl --list-boots'    # Lists the system reboots if journal is permanent
function jci() {                       # List journal entries for specific syslog identifier (service name, etc)
    local id=$1
    [ -z "${id}" ] && id="asdf"        # Change asdf to your favorite default if preferred
    journalctl SYSLOG_IDENTIFIER=${id} $2 $3 $4
} ; declare -fx jci

If you disable rsyslogd and then discover that you really like the warm and fuzzy feeling of having all those text log files, you can easily re-enable it:
  • sudo nano /etc/systemd/journald.conf and comment out the ForwardToSyslog=no line
  • sudo systemctl enable rsyslog.service
  • sudo reboot
* rsyncd: let systemd start rsync server processes on demand
  • Why it's better: One less process running, if you normally run rsyncd
  • How to configure:

    Code: Select all

    sudo cat > /etc/systemd/system/rsyncd.socket <<EOF
    Description=Rsync Server Socket
    sudo cat > /etc/systemd/system/rsyncd@.service
    Description=Start the rsync server daemon
    ExecStart=/usr/bin/rsync --daemon --no-detach
You'll also need to have a valid /etc/rsyncd.conf file, which is not covered here, but fully documented in 'man rsyncd.conf'

* systemd-networkd and systemd-resolved: For simple network configurations (LAN client with DHCP, or always statically configured) use systemd-networkd and systemd-resolved instead of dhcpcd and/or Network Manager. This works well for both static or dynamic IP addresses for both eth0 and wlan0.
  • Why it's better: Integrated with systemd (arguable if you don't like systemd!), and one less config file language/format to learn and remember (no dhcpcd.conf needed)
  • How to configure: The network device configurations are in /etc/systemd/network

    Code: Select all

    sudo cat > /etc/systemd/network/ <<EOF
    # Uncomment next 5 lines and adjust as appropriate for static IP. Also change DHCP=Yes to DHCP=No
    sudo cat > /etc/systemd/network/ <<EOF
    # If you want to use static IP for your WiFi device, similar comments as for eth0 configuration
    sudo -s
    sed -i '1i resolvconf=NO' /etc/resolvconf.conf               # For systemd-resolved
    ln -sf /run/systemd/resolve/resolv.conf /etc/resolv.conf     # ...
    systemctl daemon-reload
    systemctl enable systemd-networkd
    systemctl enable systemd-resolved
    systemctl disable dhcpcd
    # ** Adjust and as appropriate for your configuration
Super-useful tools:
RPi SD Card Manager:
Lightweight Virtual VNC Config:
Easy-Peasy VPN installer/manager:

Return to “Advanced users”