bls
Posts: 205
Joined: Mon Oct 22, 2018 11:25 pm

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
    reboot
    
* 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
    reboot
    
* 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 https://github.com/gitbls/RPiVNCHowTo
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
    exit
    
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
    [Unit]
    Description=Rsync Server Socket
    Conflicts=rsync.service
    
    [Socket]
    ListenStream=873
    Accept=yes
    
    [Install]
    WantedBy=sockets.target 
    EOF
    
    sudo cat > /etc/systemd/system/rsyncd@.service
    [Unit]
    Description=Start the rsync server daemon
    After=network.target
    ConditionPathExists=/etc/rsyncd.conf
    
    [Service]
    ExecStart=/usr/bin/rsync --daemon --no-detach
    #IOSchedulingClass=idle
    #CPUSchedulingPolicy=batch
    #PrivateTmp=true
    StandardInput=socket
    EOF
    
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/10-eth0.network <<EOF
    [Match]
    Name=eth0
    
    [Network]
    DHCP=Yes
    LinkLocalAddressing=No
    IPv4LL=false
    LinkLocalAddressing=no
    IPv4LL=false
    # Uncomment next 5 lines and adjust as appropriate for static IP. Also change DHCP=Yes to DHCP=No
    #Address=192.168.1.201/24
    #Gateway=192.168.1.1
    #DNS=192.168.1.1
    #Domains=mydomain.me
    #NTP=192.168.1.1
    
    [DHCP]
    UseDomains=yes
    EOF
    
    sudo cat > /etc/systemd/network/11-wlan0.network <<EOF
    [Match]
    Name=wlan0
    
    [Network]
    DHCP=ipv4
    # If you want to use static IP for your WiFi device, similar comments as for eth0 configuration
    
    [DHCP]
    RouteMetric=20
    UseDomains=yes
    EOF
    
    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 10-eth0.network and 11-wlan0.network as appropriate for your configuration
    reboot  
    

Return to “Advanced users”