Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save DrChai/19f3a5680c80761c78cfb90b1e3fa99e to your computer and use it in GitHub Desktop.

Select an option

Save DrChai/19f3a5680c80761c78cfb90b1e3fa99e to your computer and use it in GitHub Desktop.

Revisions

  1. @hhromic hhromic revised this gist Aug 13, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion raspbian-stretch-lite-slimdown.md
    Original file line number Diff line number Diff line change
    @@ -14,7 +14,7 @@ Configure headless SSH and Wi-Fi (if necessary) before starting the SD card ([so

    $ mount /dev/sdX /media
    $ :> /media/ssh
    $ cat > /media/ssh/wpa_supplicant.conf <<"EOF"
    $ cat > /media/wpa_supplicant.conf <<"EOF"
    country=GB
    ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
    update_config=1
  2. @hhromic hhromic revised this gist Apr 22, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion raspbian-stretch-lite-slimdown.md
    Original file line number Diff line number Diff line change
    @@ -7,7 +7,7 @@ This guide does not strip Raspbian of basic functionality such as Bluetooth and

    Install a fresh Raspbian Stretch Lite image into the SD card ([source][1]).

    $ unzip -p 2018-03-13-raspbian-stretch-lite.zip | dd bs=4M of=/dev/sdX conv=fsync
    $ unzip -p 2018-04-18-raspbian-stretch-lite.zip | dd bs=4M of=/dev/sdX conv=fsync
    $ sync

    Configure headless SSH and Wi-Fi (if necessary) before starting the SD card ([source][2]).
  3. @hhromic hhromic renamed this gist Apr 17, 2018. 1 changed file with 9 additions and 9 deletions.
    Original file line number Diff line number Diff line change
    @@ -1,13 +1,13 @@
    # Slimming Down Raspbian Stretch
    # Slimming Down Raspbian Stretch Lite

    Notes for slimming down a fresh installation of Raspbian Stretch.
    Notes for slimming down a fresh installation of Raspbian Stretch Lite.
    This guide does not strip Raspbian of basic functionality such as Bluetooth and mDNS.

    ## Instructions

    Install a fresh Raspbian Stretch image into the SD card ([source][1]).
    Install a fresh Raspbian Stretch Lite image into the SD card ([source][1]).

    $ unzip -p 2017-09-07-raspbian-stretch.zip | dd bs=4M of=/dev/sdX conv=fsync
    $ unzip -p 2018-03-13-raspbian-stretch-lite.zip | dd bs=4M of=/dev/sdX conv=fsync
    $ sync

    Configure headless SSH and Wi-Fi (if necessary) before starting the SD card ([source][2]).
    @@ -27,7 +27,7 @@ Configure headless SSH and Wi-Fi (if necessary) before starting the SD card ([so
    $ umount /media
    $ sync

    Configure apt so that it does not install additional packages ([source][3]).
    Configure `apt` so that it does not install additional packages ([source][3]).

    $ cat > /etc/apt/apt.conf.d/80noadditional <<"EOF"
    APT::Install-Recommends "0";
    @@ -66,7 +66,7 @@ Remove all packages that were automatically installed and are no longer required

    ## Optionals

    Configure dpkg so that it does not install documentation in packages ([source][4]).
    Configure `dpkg` so that it does not install documentation in packages ([source][4]).

    $ cat > /etc/dpkg/dpkg.cfg.d/nodoc <<"EOF"
    path-exclude /usr/share/doc/*
    @@ -78,7 +78,7 @@ Configure dpkg so that it does not install documentation in packages ([source][4
    path-exclude /usr/share/linda/*
    EOF

    Configure dpkg so that it does not install locales in packages.
    Configure `dpkg` so that it does not install locales in packages.

    $ cat > /etc/dpkg/dpkg.cfg.d/nolocale <<"EOF"
    path-exclude /usr/share/locale/*
    @@ -133,11 +133,11 @@ Generate a unique hostname based on MAC address during boot.
    $ systemctl enable mac-hostname.service
    $ reboot

    Disable onboard Bluetooth device (RPi0W, RPi3).
    Disable onboard Bluetooth device (RPI0W, RPI3).

    $ echo dtoverlay=pi3-disable-bt >> /boot/config.txt
    $ systemctl disable hciuart
    $ apt-get purge bluez bluez-firmware pi-bluetooth # if BT not needed again
    $ apt-get purge bluez bluez-firmware pi-bluetooth # if BT is not needed again

    ## References

  4. @hhromic hhromic revised this gist Mar 21, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion raspbian-stretch-slimdown.md
    Original file line number Diff line number Diff line change
    @@ -98,7 +98,7 @@ Remove locales from already installed packages.
    Remove log files.

    $ rm -f /var/log/{auth,boot,bootstrap,daemon,kern}.log
    $ rm -f /var/log/{debug,messages,syslog}
    $ rm -f /var/log/{debug,dmesg,messages,syslog}

    Empty the Message-Of-The-Day file.

  5. @hhromic hhromic revised this gist Nov 17, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion raspbian-stretch-slimdown.md
    Original file line number Diff line number Diff line change
    @@ -120,10 +120,10 @@ Generate a unique hostname based on MAC address during boot.
    if [ "$_HOSTNAME" ]; then \
    _CURRENT_HOSTNAME=$(cat /etc/hostname | tr -d " \\t\\n\\r"); \
    if [ "$_HOSTNAME" != "$_CURRENT_HOSTNAME" ]; then \
    echo "Setting MAC-based hostname to <$_HOSTNAME>"; \
    echo "$_HOSTNAME" > /etc/hostname; \
    sed -i "s/127.0.1.1.*$_CURRENT_HOSTNAME/127.0.1.1\\t$_HOSTNAME/g" /etc/hosts; \
    /bin/hostname -b -F /etc/hostname; \
    echo "Setting MAC-based hostname to <$_HOSTNAME>"; \
    fi; \
    fi'

  6. @hhromic hhromic revised this gist Nov 17, 2017. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion raspbian-stretch-slimdown.md
    Original file line number Diff line number Diff line change
    @@ -120,8 +120,10 @@ Generate a unique hostname based on MAC address during boot.
    if [ "$_HOSTNAME" ]; then \
    _CURRENT_HOSTNAME=$(cat /etc/hostname | tr -d " \\t\\n\\r"); \
    if [ "$_HOSTNAME" != "$_CURRENT_HOSTNAME" ]; then \
    echo "$_HOSTNAME" > /etc/hostname; \
    sed -i "s/127.0.1.1.*$_CURRENT_HOSTNAME/127.0.1.1\\t$_HOSTNAME/g" /etc/hosts; \
    hostnamectl set-hostname "$_HOSTNAME"; \
    /bin/hostname -b -F /etc/hostname; \
    echo "Setting MAC-based hostname to <$_HOSTNAME>"; \
    fi; \
    fi'

  7. @hhromic hhromic revised this gist Nov 17, 2017. 1 changed file with 1 addition and 2 deletions.
    3 changes: 1 addition & 2 deletions raspbian-stretch-slimdown.md
    Original file line number Diff line number Diff line change
    @@ -120,9 +120,8 @@ Generate a unique hostname based on MAC address during boot.
    if [ "$_HOSTNAME" ]; then \
    _CURRENT_HOSTNAME=$(cat /etc/hostname | tr -d " \\t\\n\\r"); \
    if [ "$_HOSTNAME" != "$_CURRENT_HOSTNAME" ]; then \
    hostnamectl set-hostname "$_HOSTNAME"; \
    sed -i "s/127.0.1.1.*$_CURRENT_HOSTNAME/127.0.1.1\\t$_HOSTNAME/g" /etc/hosts; \
    echo "Setting MAC-based hostname to <$_HOSTNAME>"; \
    hostnamectl set-hostname "$_HOSTNAME"; \
    fi; \
    fi'

  8. @hhromic hhromic revised this gist Nov 17, 2017. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions raspbian-stretch-slimdown.md
    Original file line number Diff line number Diff line change
    @@ -112,7 +112,7 @@ Generate a unique hostname based on MAC address during boot.
    DefaultDependencies=no
    After=sysinit.target local-fs.target
    Before=basic.target

    [Service]
    Type=oneshot
    ExecStart=/bin/bash -c '\
    @@ -125,7 +125,7 @@ Generate a unique hostname based on MAC address during boot.
    echo "Setting MAC-based hostname to <$_HOSTNAME>"; \
    fi; \
    fi'

    [Install]
    WantedBy=basic.target
    EOF
  9. @hhromic hhromic revised this gist Nov 17, 2017. 1 changed file with 5 additions and 5 deletions.
    10 changes: 5 additions & 5 deletions raspbian-stretch-slimdown.md
    Original file line number Diff line number Diff line change
    @@ -112,20 +112,20 @@ Generate a unique hostname based on MAC address during boot.
    DefaultDependencies=no
    After=sysinit.target local-fs.target
    Before=basic.target

    [Service]
    Type=oneshot
    ExecStart=/bin/bash -c '\
    _HOSTNAME=$(sed "s/^.*macaddr=\([0-9A-F:]*\) .*$/\1/;s/://g;s/\(.*\)/rpi-\L\1/" /proc/cmdline); \
    _HOSTNAME=$(sed "s/^.*macaddr=\\([0-9A-F:]*\\) .*$/\\1/;s/://g;s/\\(.*\\)/rpi-\\L\\1/" /proc/cmdline); \
    if [ "$_HOSTNAME" ]; then \
    _CURRENT_HOSTNAME=$(cat /etc/hostname | tr -d " \t\n\r"); \
    _CURRENT_HOSTNAME=$(cat /etc/hostname | tr -d " \\t\\n\\r"); \
    if [ "$_HOSTNAME" != "$_CURRENT_HOSTNAME" ]; then \
    hostnamectl set-hostname "$_HOSTNAME"; \
    sed -i "s/127.0.1.1.*$_CURRENT_HOSTNAME/127.0.1.1\t$_HOSTNAME/g" /etc/hosts; \
    sed -i "s/127.0.1.1.*$_CURRENT_HOSTNAME/127.0.1.1\\t$_HOSTNAME/g" /etc/hosts; \
    echo "Setting MAC-based hostname to <$_HOSTNAME>"; \
    fi; \
    fi'

    [Install]
    WantedBy=basic.target
    EOF
  10. @hhromic hhromic revised this gist Nov 17, 2017. 1 changed file with 6 additions and 6 deletions.
    12 changes: 6 additions & 6 deletions raspbian-stretch-slimdown.md
    Original file line number Diff line number Diff line change
    @@ -14,7 +14,7 @@ Configure headless SSH and Wi-Fi (if necessary) before starting the SD card ([so

    $ mount /dev/sdX /media
    $ :> /media/ssh
    $ cat > /media/ssh/wpa_supplicant.conf <<EOF
    $ cat > /media/ssh/wpa_supplicant.conf <<"EOF"
    country=GB
    ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
    update_config=1
    @@ -29,7 +29,7 @@ Configure headless SSH and Wi-Fi (if necessary) before starting the SD card ([so

    Configure apt so that it does not install additional packages ([source][3]).

    $ cat > /etc/apt/apt.conf.d/80noadditional <<EOF
    $ cat > /etc/apt/apt.conf.d/80noadditional <<"EOF"
    APT::Install-Recommends "0";
    APT::Install-Suggests "0";
    EOF
    @@ -46,7 +46,7 @@ Mark all libraries as autoinstalled, so they are autoremoved when no longer requ

    Remove non-critical packages.

    $ xargs apt-get purge <<EOF
    $ xargs apt-get purge <<"EOF"
    aptitude aptitude-common apt-listchanges apt-utils bash-completion blends-tasks build-essential
    bzip2 cifs-utils console-setup console-setup-linux cpp debconf-i18n dmidecode dosfstools
    dpkg-dev ed gcc gcc-4.6-base gcc-4.7-base gcc-4.8-base gcc-4.9-base gcc-5-base gcc-6 gdb
    @@ -68,7 +68,7 @@ Remove all packages that were automatically installed and are no longer required

    Configure dpkg so that it does not install documentation in packages ([source][4]).

    $ cat > /etc/dpkg/dpkg.cfg.d/nodoc <<EOF
    $ cat > /etc/dpkg/dpkg.cfg.d/nodoc <<"EOF"
    path-exclude /usr/share/doc/*
    path-include /usr/share/doc/*/copyright
    path-exclude /usr/share/man/*
    @@ -80,7 +80,7 @@ Configure dpkg so that it does not install documentation in packages ([source][4

    Configure dpkg so that it does not install locales in packages.

    $ cat > /etc/dpkg/dpkg.cfg.d/nolocale <<EOF
    $ cat > /etc/dpkg/dpkg.cfg.d/nolocale <<"EOF"
    path-exclude /usr/share/locale/*
    EOF

    @@ -122,7 +122,7 @@ Generate a unique hostname based on MAC address during boot.
    if [ "$_HOSTNAME" != "$_CURRENT_HOSTNAME" ]; then \
    hostnamectl set-hostname "$_HOSTNAME"; \
    sed -i "s/127.0.1.1.*$_CURRENT_HOSTNAME/127.0.1.1\t$_HOSTNAME/g" /etc/hosts; \
    echo "Setting hostname to \'$_HOSTNAME\'"; \
    echo "Setting MAC-based hostname to <$_HOSTNAME>"; \
    fi; \
    fi'

  11. @hhromic hhromic revised this gist Nov 17, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion raspbian-stretch-slimdown.md
    Original file line number Diff line number Diff line change
    @@ -106,7 +106,7 @@ Empty the Message-Of-The-Day file.

    Generate a unique hostname based on MAC address during boot.

    $ cat > /etc/systemd/system/mac-hostname.service <<EOF
    $ cat > /etc/systemd/system/mac-hostname.service <<"EOF"
    [Unit]
    Description=MAC-based hostname
    DefaultDependencies=no
  12. @hhromic hhromic revised this gist Nov 15, 2017. 1 changed file with 1 addition and 2 deletions.
    3 changes: 1 addition & 2 deletions raspbian-stretch-slimdown.md
    Original file line number Diff line number Diff line change
    @@ -120,9 +120,8 @@ Generate a unique hostname based on MAC address during boot.
    if [ "$_HOSTNAME" ]; then \
    _CURRENT_HOSTNAME=$(cat /etc/hostname | tr -d " \t\n\r"); \
    if [ "$_HOSTNAME" != "$_CURRENT_HOSTNAME" ]; then \
    echo "$_HOSTNAME" > /etc/hostname; \
    sed -i "s/127.0.1.1.*$_CURRENT_HOSTNAME/127.0.1.1\t$_HOSTNAME/g" /etc/hosts; \
    hostnamectl set-hostname "$_HOSTNAME"; \
    sed -i "s/127.0.1.1.*$_CURRENT_HOSTNAME/127.0.1.1\t$_HOSTNAME/g" /etc/hosts; \
    echo "Setting hostname to \'$_HOSTNAME\'"; \
    fi; \
    fi'
  13. @hhromic hhromic revised this gist Nov 15, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion raspbian-stretch-slimdown.md
    Original file line number Diff line number Diff line change
    @@ -123,7 +123,7 @@ Generate a unique hostname based on MAC address during boot.
    echo "$_HOSTNAME" > /etc/hostname; \
    sed -i "s/127.0.1.1.*$_CURRENT_HOSTNAME/127.0.1.1\t$_HOSTNAME/g" /etc/hosts; \
    hostnamectl set-hostname "$_HOSTNAME"; \
    echo "Setting hostname to \'$_HOSTNAME\'; \
    echo "Setting hostname to \'$_HOSTNAME\'"; \
    fi; \
    fi'

  14. @hhromic hhromic revised this gist Nov 15, 2017. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions raspbian-stretch-slimdown.md
    Original file line number Diff line number Diff line change
    @@ -123,6 +123,7 @@ Generate a unique hostname based on MAC address during boot.
    echo "$_HOSTNAME" > /etc/hostname; \
    sed -i "s/127.0.1.1.*$_CURRENT_HOSTNAME/127.0.1.1\t$_HOSTNAME/g" /etc/hosts; \
    hostnamectl set-hostname "$_HOSTNAME"; \
    echo "Setting hostname to \'$_HOSTNAME\'; \
    fi; \
    fi'

  15. @hhromic hhromic revised this gist Nov 15, 2017. 1 changed file with 29 additions and 15 deletions.
    44 changes: 29 additions & 15 deletions raspbian-stretch-slimdown.md
    Original file line number Diff line number Diff line change
    @@ -68,7 +68,7 @@ Remove all packages that were automatically installed and are no longer required

    Configure dpkg so that it does not install documentation in packages ([source][4]).

    $ cat > /etc/dpkg/dpkg.cfg.d/nodoc << EOF
    $ cat > /etc/dpkg/dpkg.cfg.d/nodoc <<EOF
    path-exclude /usr/share/doc/*
    path-include /usr/share/doc/*/copyright
    path-exclude /usr/share/man/*
    @@ -80,7 +80,7 @@ Configure dpkg so that it does not install documentation in packages ([source][4

    Configure dpkg so that it does not install locales in packages.

    $ cat > /etc/dpkg/dpkg.cfg.d/nolocale << EOF
    $ cat > /etc/dpkg/dpkg.cfg.d/nolocale <<EOF
    path-exclude /usr/share/locale/*
    EOF

    @@ -104,19 +104,33 @@ Empty the Message-Of-The-Day file.

    $ :> /etc/motd

    To generate a unique hostname during boot, add this snippet to `/etc/rc.local`.

    # Generate and set a unique hostname
    _HOSTNAME=$(sed "s/^.*macaddr=\([0-9A-F:]*\) .*$/\1/;s/://g;s/\(.*\)/rpi-\L\1/" /proc/cmdline)
    if [ "$_HOSTNAME" ]; then
    _CURRENT_HOSTNAME=$(cat /etc/hostname | tr -d " \t\n\r")
    if [ "$_HOSTNAME" != "$_CURRENT_HOSTNAME" ]; then
    echo "$_HOSTNAME" > /etc/hostname
    sed -i "s/127.0.1.1.*$_CURRENT_HOSTNAME/127.0.1.1\t$_HOSTNAME/g" /etc/hosts
    hostnamectl set-hostname "$_HOSTNAME"
    fi
    printf "My hostname is %s\n" "$_HOSTNAME"
    fi
    Generate a unique hostname based on MAC address during boot.

    $ cat > /etc/systemd/system/mac-hostname.service <<EOF
    [Unit]
    Description=MAC-based hostname
    DefaultDependencies=no
    After=sysinit.target local-fs.target
    Before=basic.target

    [Service]
    Type=oneshot
    ExecStart=/bin/bash -c '\
    _HOSTNAME=$(sed "s/^.*macaddr=\([0-9A-F:]*\) .*$/\1/;s/://g;s/\(.*\)/rpi-\L\1/" /proc/cmdline); \
    if [ "$_HOSTNAME" ]; then \
    _CURRENT_HOSTNAME=$(cat /etc/hostname | tr -d " \t\n\r"); \
    if [ "$_HOSTNAME" != "$_CURRENT_HOSTNAME" ]; then \
    echo "$_HOSTNAME" > /etc/hostname; \
    sed -i "s/127.0.1.1.*$_CURRENT_HOSTNAME/127.0.1.1\t$_HOSTNAME/g" /etc/hosts; \
    hostnamectl set-hostname "$_HOSTNAME"; \
    fi; \
    fi'

    [Install]
    WantedBy=basic.target
    EOF
    $ systemctl enable mac-hostname.service
    $ reboot

    Disable onboard Bluetooth device (RPi0W, RPi3).

  16. @hhromic hhromic revised this gist Nov 15, 2017. 1 changed file with 0 additions and 6 deletions.
    6 changes: 0 additions & 6 deletions raspbian-stretch-slimdown.md
    Original file line number Diff line number Diff line change
    @@ -82,12 +82,6 @@ Configure dpkg so that it does not install locales in packages.

    $ cat > /etc/dpkg/dpkg.cfg.d/nolocale << EOF
    path-exclude /usr/share/locale/*
    path-include /usr/share/locale/en*
    path-include /usr/share/locale/de*
    path-include /usr/share/locale/es*
    path-include /usr/share/locale/ja*
    path-include /usr/share/locale/fr*
    path-include /usr/share/locale/zh*
    EOF

    Remove documentation from already installed packages ([source][4]).
  17. @hhromic hhromic revised this gist Nov 15, 2017. 1 changed file with 16 additions and 0 deletions.
    16 changes: 16 additions & 0 deletions raspbian-stretch-slimdown.md
    Original file line number Diff line number Diff line change
    @@ -78,13 +78,29 @@ Configure dpkg so that it does not install documentation in packages ([source][4
    path-exclude /usr/share/linda/*
    EOF

    Configure dpkg so that it does not install locales in packages.

    $ cat > /etc/dpkg/dpkg.cfg.d/nolocale << EOF
    path-exclude /usr/share/locale/*
    path-include /usr/share/locale/en*
    path-include /usr/share/locale/de*
    path-include /usr/share/locale/es*
    path-include /usr/share/locale/ja*
    path-include /usr/share/locale/fr*
    path-include /usr/share/locale/zh*
    EOF

    Remove documentation from already installed packages ([source][4]).

    $ find /usr/share/doc -depth -type f ! -name copyright | xargs rm
    $ find /usr/share/doc -empty | xargs rmdir
    $ rm -rf /usr/share/man/* /usr/share/groff/* /usr/share/info/*
    $ rm -rf /usr/share/lintian/* /usr/share/linda/* /var/cache/man/*

    Remove locales from already installed packages.

    $ rm -rf /usr/share/locale/*

    Remove log files.

    $ rm -f /var/log/{auth,boot,bootstrap,daemon,kern}.log
  18. @hhromic hhromic revised this gist Nov 15, 2017. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions raspbian-stretch-slimdown.md
    Original file line number Diff line number Diff line change
    @@ -112,6 +112,7 @@ Disable onboard Bluetooth device (RPi0W, RPi3).

    $ echo dtoverlay=pi3-disable-bt >> /boot/config.txt
    $ systemctl disable hciuart
    $ apt-get purge bluez bluez-firmware pi-bluetooth # if BT not needed again

    ## References

  19. @hhromic hhromic revised this gist Nov 15, 2017. 1 changed file with 5 additions and 0 deletions.
    5 changes: 5 additions & 0 deletions raspbian-stretch-slimdown.md
    Original file line number Diff line number Diff line change
    @@ -108,6 +108,11 @@ To generate a unique hostname during boot, add this snippet to `/etc/rc.local`.
    printf "My hostname is %s\n" "$_HOSTNAME"
    fi

    Disable onboard Bluetooth device (RPi0W, RPi3).

    $ echo dtoverlay=pi3-disable-bt >> /boot/config.txt
    $ systemctl disable hciuart

    ## References

    [1]: https://www.raspberrypi.org/documentation/installation/installing-images/linux.md
  20. @hhromic hhromic revised this gist Nov 14, 2017. 1 changed file with 14 additions and 0 deletions.
    14 changes: 14 additions & 0 deletions raspbian-stretch-slimdown.md
    Original file line number Diff line number Diff line change
    @@ -94,6 +94,20 @@ Empty the Message-Of-The-Day file.

    $ :> /etc/motd

    To generate a unique hostname during boot, add this snippet to `/etc/rc.local`.

    # Generate and set a unique hostname
    _HOSTNAME=$(sed "s/^.*macaddr=\([0-9A-F:]*\) .*$/\1/;s/://g;s/\(.*\)/rpi-\L\1/" /proc/cmdline)
    if [ "$_HOSTNAME" ]; then
    _CURRENT_HOSTNAME=$(cat /etc/hostname | tr -d " \t\n\r")
    if [ "$_HOSTNAME" != "$_CURRENT_HOSTNAME" ]; then
    echo "$_HOSTNAME" > /etc/hostname
    sed -i "s/127.0.1.1.*$_CURRENT_HOSTNAME/127.0.1.1\t$_HOSTNAME/g" /etc/hosts
    hostnamectl set-hostname "$_HOSTNAME"
    fi
    printf "My hostname is %s\n" "$_HOSTNAME"
    fi

    ## References

    [1]: https://www.raspberrypi.org/documentation/installation/installing-images/linux.md
  21. @hhromic hhromic revised this gist Nov 14, 2017. 1 changed file with 7 additions and 3 deletions.
    10 changes: 7 additions & 3 deletions raspbian-stretch-slimdown.md
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    # Slimming Down Raspbian Stretch

    Notes for slimming down a fresh installation of Raspbian Stretch.
    This guide does not strip Raspbian of basic functionality such as Bluetooth.
    This guide does not strip Raspbian of basic functionality such as Bluetooth and mDNS.

    ## Instructions

    @@ -78,18 +78,22 @@ Configure dpkg so that it does not install documentation in packages ([source][4
    path-exclude /usr/share/linda/*
    EOF

    Remove documentation from already installed packages ([source][4]):
    Remove documentation from already installed packages ([source][4]).

    $ find /usr/share/doc -depth -type f ! -name copyright | xargs rm
    $ find /usr/share/doc -empty | xargs rmdir
    $ rm -rf /usr/share/man/* /usr/share/groff/* /usr/share/info/*
    $ rm -rf /usr/share/lintian/* /usr/share/linda/* /var/cache/man/*

    Remove log files:
    Remove log files.

    $ rm -f /var/log/{auth,boot,bootstrap,daemon,kern}.log
    $ rm -f /var/log/{debug,messages,syslog}

    Empty the Message-Of-The-Day file.

    $ :> /etc/motd

    ## References

    [1]: https://www.raspberrypi.org/documentation/installation/installing-images/linux.md
  22. @hhromic hhromic revised this gist Nov 14, 2017. 1 changed file with 14 additions and 27 deletions.
    41 changes: 14 additions & 27 deletions raspbian-stretch-slimdown.md
    Original file line number Diff line number Diff line change
    @@ -42,36 +42,23 @@ Update Raspbian in the freshly installed system.

    Mark all libraries as autoinstalled, so they are autoremoved when no longer required.

    $ dpkg-query -Wf '${binary:Package}\n' 'lib*[!libraspberrypi-bin]' | xargs apt-mark auto
    $ dpkg-query -Wf '${binary:Package}\n' 'lib*[!raspberrypi-bin]' | xargs apt-mark auto

    Remove non-critical packages.

    aptitude aptitude-common apt-listchanges apt-utils
    bash-completion blends-tasks plymouth mountall
    debconf-i18n dpkg-dev dmidecode locales
    gcc-4.6-base gcc-4.7-base gcc-4.8-base gcc-4.9-base gcc-5-base
    make cpp gcc gcc-6 gdb gettext-base groff-base sgml-base
    geoip-database kbd keyboard-configuration
    isc-dhcp-client isc-dhcp-common dosfstools
    libboost-iostreams1.58.0 libboost-iostreams1.60.0
    libc6-dbg logrotate netcat-openbsd netcat-traditional
    libfreetype6-dev libpng-dev libmnl-dev zlib1g-dev
    libraspberrypi-doc libraspberrypi-dev
    libsigc++-1.2-5c2 libsigc++-2.0-0v5
    libudev0 libusb-0.1-4 libglib2.0-data
    luajit dc ed info install-info htop ncdu hardlink
    manpages manpages-dev xxd xz-utils iputils-ping
    vim-tiny vim-common perl bzip2 unzip less
    v4l-utils build-essential strace wget iptables
    tasksel tasksel-data triggerhappy
    console-setup console-setup-linux
    rpcbind nfs-common rsync rsyslog tcpd
    python mime-support shared-mime-info
    samba-common cifs-utils xdg-user-dirs
    liblocale-gettext-perl libtext-charwidth-perl
    libtext-iconv-perl libtext-wrapi18n-perl
    net-tools traceroute usbutils xauth
    usb-modeswitch usb-modeswitch-data
    $ xargs apt-get purge <<EOF
    aptitude aptitude-common apt-listchanges apt-utils bash-completion blends-tasks build-essential
    bzip2 cifs-utils console-setup console-setup-linux cpp debconf-i18n dmidecode dosfstools
    dpkg-dev ed gcc gcc-4.6-base gcc-4.7-base gcc-4.8-base gcc-4.9-base gcc-5-base gcc-6 gdb
    geoip-database gettext-base groff-base hardlink htop info install-info iptables iputils-ping
    isc-dhcp-client isc-dhcp-common kbd keyboard-configuration less libc-l10n libglib2.0-data
    liblocale-gettext-perl libtext-charwidth-perl libtext-iconv-perl libtext-wrapi18n-perl locales
    logrotate luajit make manpages manpages-dev mime-support mountall ncdu netcat-openbsd
    netcat-traditional net-tools nfs-common perl plymouth python rpcbind rsync rsyslog samba-common
    sgml-base shared-mime-info strace tasksel tasksel-data tcpd traceroute triggerhappy unzip
    usb-modeswitch usb-modeswitch-data usbutils v4l-utils vim-common vim-tiny wget xauth
    xdg-user-dirs xxd xz-utils zlib1g-dev
    EOF

    Remove all packages that were automatically installed and are no longer required.

  23. @hhromic hhromic revised this gist Nov 14, 2017. 1 changed file with 5 additions and 5 deletions.
    10 changes: 5 additions & 5 deletions raspbian-stretch-slimdown.md
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,7 @@
    # Slimming Down Raspbian Stretch

    Notes for slimming down a fresh installation of Raspbian Stretch.
    This guide does not strip Raspbian of basic functionality such as Bluetooth.

    ## Instructions

    @@ -33,16 +34,15 @@ Configure apt so that it does not install additional packages ([source][3]).
    APT::Install-Suggests "0";
    EOF

    Update Raspbian in the fresh installed system.
    Update Raspbian in the freshly installed system.

    $ apt-get update
    $ apt-get dist-upgrade
    $ reboot

    Mark all libraries as autoinstalled, so they are autoremoved when no longer required.

    $ dpkg-query -Wf '${Package;-40}\n' | grep ^lib | \
    grep -v libraspberrypi-bin | xargs apt-mark auto
    $ dpkg-query -Wf '${binary:Package}\n' 'lib*[!libraspberrypi-bin]' | xargs apt-mark auto

    Remove non-critical packages.

    @@ -93,8 +93,8 @@ Configure dpkg so that it does not install documentation in packages ([source][4

    Remove documentation from already installed packages ([source][4]):

    $ find /usr/share/doc -depth -type f ! -name copyright|xargs rm || true
    $ find /usr/share/doc -empty|xargs rmdir || true
    $ find /usr/share/doc -depth -type f ! -name copyright | xargs rm
    $ find /usr/share/doc -empty | xargs rmdir
    $ rm -rf /usr/share/man/* /usr/share/groff/* /usr/share/info/*
    $ rm -rf /usr/share/lintian/* /usr/share/linda/* /var/cache/man/*

  24. @hhromic hhromic revised this gist Nov 14, 2017. 1 changed file with 5 additions and 5 deletions.
    10 changes: 5 additions & 5 deletions raspbian-stretch-slimdown.md
    Original file line number Diff line number Diff line change
    @@ -39,6 +39,11 @@ Update Raspbian in the fresh installed system.
    $ apt-get dist-upgrade
    $ reboot

    Mark all libraries as autoinstalled, so they are autoremoved when no longer required.

    $ dpkg-query -Wf '${Package;-40}\n' | grep ^lib | \
    grep -v libraspberrypi-bin | xargs apt-mark auto

    Remove non-critical packages.

    aptitude aptitude-common apt-listchanges apt-utils
    @@ -68,11 +73,6 @@ Remove non-critical packages.
    net-tools traceroute usbutils xauth
    usb-modeswitch usb-modeswitch-data

    Mark libraries as automatically installed, so they are autoremoved as appropiate.

    $ dpkg-query -Wf '${Package;-40}\n' | grep ^lib | \
    grep -v libraspberrypi-bin | xargs apt-mark auto

    Remove all packages that were automatically installed and are no longer required.

    $ apt-get autoremove --purge
  25. @hhromic hhromic revised this gist Nov 14, 2017. 1 changed file with 9 additions and 4 deletions.
    13 changes: 9 additions & 4 deletions raspbian-stretch-slimdown.md
    Original file line number Diff line number Diff line change
    @@ -54,10 +54,10 @@ Remove non-critical packages.
    libraspberrypi-doc libraspberrypi-dev
    libsigc++-1.2-5c2 libsigc++-2.0-0v5
    libudev0 libusb-0.1-4 libglib2.0-data
    luajit dc ed info install-info htop ncdu
    manpages manpages-dev xxd xz-utils
    vim-tiny vim-common perl bzip2 unzip
    v4l-utils build-essential strace wget
    luajit dc ed info install-info htop ncdu hardlink
    manpages manpages-dev xxd xz-utils iputils-ping
    vim-tiny vim-common perl bzip2 unzip less
    v4l-utils build-essential strace wget iptables
    tasksel tasksel-data triggerhappy
    console-setup console-setup-linux
    rpcbind nfs-common rsync rsyslog tcpd
    @@ -68,6 +68,11 @@ Remove non-critical packages.
    net-tools traceroute usbutils xauth
    usb-modeswitch usb-modeswitch-data

    Mark libraries as automatically installed, so they are autoremoved as appropiate.

    $ dpkg-query -Wf '${Package;-40}\n' | grep ^lib | \
    grep -v libraspberrypi-bin | xargs apt-mark auto

    Remove all packages that were automatically installed and are no longer required.

    $ apt-get autoremove --purge
  26. @hhromic hhromic revised this gist Nov 14, 2017. 1 changed file with 28 additions and 12 deletions.
    40 changes: 28 additions & 12 deletions raspbian-stretch-slimdown.md
    Original file line number Diff line number Diff line change
    @@ -42,24 +42,35 @@ Update Raspbian in the fresh installed system.
    Remove non-critical packages.

    aptitude aptitude-common apt-listchanges apt-utils
    bash-completion blends-tasks
    debconf-i18n dmidecode
    bash-completion blends-tasks plymouth mountall
    debconf-i18n dpkg-dev dmidecode locales
    gcc-4.6-base gcc-4.7-base gcc-4.8-base gcc-4.9-base gcc-5-base
    cpp gcc gcc-6
    geoip-database
    isc-dhcp-client isc-dhcp-common
    make cpp gcc gcc-6 gdb gettext-base groff-base sgml-base
    geoip-database kbd keyboard-configuration
    isc-dhcp-client isc-dhcp-common dosfstools
    libboost-iostreams1.58.0 libboost-iostreams1.60.0
    libc6-dbg
    libc6-dbg logrotate netcat-openbsd netcat-traditional
    libfreetype6-dev libpng-dev libmnl-dev zlib1g-dev
    libraspberrypi-doc libraspberrypi-dev
    libsigc++-1.2-5c2 libsigc++-2.0-0v5
    libudev0 libusb-0.1-4
    luajit
    manpages manpages-dev
    vim-tiny vim-common
    v4l-utils build-essential
    tasksel tasksel-data
    libudev0 libusb-0.1-4 libglib2.0-data
    luajit dc ed info install-info htop ncdu
    manpages manpages-dev xxd xz-utils
    vim-tiny vim-common perl bzip2 unzip
    v4l-utils build-essential strace wget
    tasksel tasksel-data triggerhappy
    console-setup console-setup-linux
    rpcbind nfs-common rsync rsyslog tcpd
    python mime-support shared-mime-info
    samba-common cifs-utils xdg-user-dirs
    liblocale-gettext-perl libtext-charwidth-perl
    libtext-iconv-perl libtext-wrapi18n-perl
    net-tools traceroute usbutils xauth
    usb-modeswitch usb-modeswitch-data

    Remove all packages that were automatically installed and are no longer required.

    $ apt-get autoremove --purge

    ## Optionals

    @@ -82,6 +93,11 @@ Remove documentation from already installed packages ([source][4]):
    $ rm -rf /usr/share/man/* /usr/share/groff/* /usr/share/info/*
    $ rm -rf /usr/share/lintian/* /usr/share/linda/* /var/cache/man/*

    Remove log files:

    $ rm -f /var/log/{auth,boot,bootstrap,daemon,kern}.log
    $ rm -f /var/log/{debug,messages,syslog}

    ## References

    [1]: https://www.raspberrypi.org/documentation/installation/installing-images/linux.md
  27. @hhromic hhromic revised this gist Nov 14, 2017. 1 changed file with 18 additions and 13 deletions.
    31 changes: 18 additions & 13 deletions raspbian-stretch-slimdown.md
    Original file line number Diff line number Diff line change
    @@ -33,18 +33,6 @@ Configure apt so that it does not install additional packages ([source][3]).
    APT::Install-Suggests "0";
    EOF

    Configure dpkg so that it does not install documentation in packages ([source][4]).

    $ cat > /etc/dpkg/dpkg.cfg.d/nodoc << EOF
    path-exclude /usr/share/doc/*
    path-include /usr/share/doc/*/copyright
    path-exclude /usr/share/man/*
    path-exclude /usr/share/groff/*
    path-exclude /usr/share/info/*
    path-exclude /usr/share/lintian/*
    path-exclude /usr/share/linda/*
    EOF

    Update Raspbian in the fresh installed system.

    $ apt-get update
    @@ -57,6 +45,7 @@ Remove non-critical packages.
    bash-completion blends-tasks
    debconf-i18n dmidecode
    gcc-4.6-base gcc-4.7-base gcc-4.8-base gcc-4.9-base gcc-5-base
    cpp gcc gcc-6
    geoip-database
    isc-dhcp-client isc-dhcp-common
    libboost-iostreams1.58.0 libboost-iostreams1.60.0
    @@ -68,7 +57,23 @@ Remove non-critical packages.
    luajit
    manpages manpages-dev
    vim-tiny vim-common
    v4l-utils
    v4l-utils build-essential
    tasksel tasksel-data
    console-setup console-setup-linux

    ## Optionals

    Configure dpkg so that it does not install documentation in packages ([source][4]).

    $ cat > /etc/dpkg/dpkg.cfg.d/nodoc << EOF
    path-exclude /usr/share/doc/*
    path-include /usr/share/doc/*/copyright
    path-exclude /usr/share/man/*
    path-exclude /usr/share/groff/*
    path-exclude /usr/share/info/*
    path-exclude /usr/share/lintian/*
    path-exclude /usr/share/linda/*
    EOF

    Remove documentation from already installed packages ([source][4]):

  28. @hhromic hhromic revised this gist Nov 14, 2017. 1 changed file with 27 additions and 6 deletions.
    33 changes: 27 additions & 6 deletions raspbian-stretch-slimdown.md
    Original file line number Diff line number Diff line change
    @@ -4,12 +4,12 @@ Notes for slimming down a fresh installation of Raspbian Stretch.

    ## Instructions

    Install a fresh Raspbian Stretch image into the SD card ([source][2]).
    Install a fresh Raspbian Stretch image into the SD card ([source][1]).

    $ unzip -p 2017-09-07-raspbian-stretch.zip | dd bs=4M of=/dev/sdX conv=fsync
    $ sync

    Configure headless SSH and Wi-Fi (if necessary) before starting the SD card ([source][3]).
    Configure headless SSH and Wi-Fi (if necessary) before starting the SD card ([source][2]).

    $ mount /dev/sdX /media
    $ :> /media/ssh
    @@ -26,13 +26,25 @@ Configure headless SSH and Wi-Fi (if necessary) before starting the SD card ([so
    $ umount /media
    $ sync

    Reconfigure apt so that it does not install additional packages ([source][1]).
    Configure apt so that it does not install additional packages ([source][3]).

    $ cat > /etc/apt/apt.conf.d/80noadditional <<EOF
    APT::Install-Recommends "0";
    APT::Install-Suggests "0";
    EOF

    Configure dpkg so that it does not install documentation in packages ([source][4]).

    $ cat > /etc/dpkg/dpkg.cfg.d/nodoc << EOF
    path-exclude /usr/share/doc/*
    path-include /usr/share/doc/*/copyright
    path-exclude /usr/share/man/*
    path-exclude /usr/share/groff/*
    path-exclude /usr/share/info/*
    path-exclude /usr/share/lintian/*
    path-exclude /usr/share/linda/*
    EOF

    Update Raspbian in the fresh installed system.

    $ apt-get update
    @@ -54,11 +66,20 @@ Remove non-critical packages.
    libsigc++-1.2-5c2 libsigc++-2.0-0v5
    libudev0 libusb-0.1-4
    luajit
    manpages manpages-dev
    vim-tiny vim-common
    v4l-utils

    Remove documentation from already installed packages ([source][4]):

    $ find /usr/share/doc -depth -type f ! -name copyright|xargs rm || true
    $ find /usr/share/doc -empty|xargs rmdir || true
    $ rm -rf /usr/share/man/* /usr/share/groff/* /usr/share/info/*
    $ rm -rf /usr/share/lintian/* /usr/share/linda/* /var/cache/man/*

    ## References

    [1]: https://wiki.debian.org/ReduceDebian
    [2]: https://www.raspberrypi.org/documentation/installation/installing-images/linux.md
    [3]: https://www.raspberrypi.org/forums/viewtopic.php?t=191252
    [1]: https://www.raspberrypi.org/documentation/installation/installing-images/linux.md
    [2]: https://www.raspberrypi.org/forums/viewtopic.php?t=191252
    [3]: https://wiki.debian.org/ReduceDebian
    [4]: https://askubuntu.com/a/401144
  29. @hhromic hhromic revised this gist Nov 10, 2017. 1 changed file with 20 additions and 2 deletions.
    22 changes: 20 additions & 2 deletions raspbian-stretch-slimdown.md
    Original file line number Diff line number Diff line change
    @@ -9,7 +9,7 @@ Install a fresh Raspbian Stretch image into the SD card ([source][2]).
    $ unzip -p 2017-09-07-raspbian-stretch.zip | dd bs=4M of=/dev/sdX conv=fsync
    $ sync

    Configure headless ssh and Wi-Fi if necessary before starting the SD card ([source][3]).
    Configure headless SSH and Wi-Fi (if necessary) before starting the SD card ([source][3]).

    $ mount /dev/sdX /media
    $ :> /media/ssh
    @@ -33,12 +33,30 @@ Reconfigure apt so that it does not install additional packages ([source][1]).
    APT::Install-Suggests "0";
    EOF

    Update the fresh installed system.
    Update Raspbian in the fresh installed system.

    $ apt-get update
    $ apt-get dist-upgrade
    $ reboot

    Remove non-critical packages.

    aptitude aptitude-common apt-listchanges apt-utils
    bash-completion blends-tasks
    debconf-i18n dmidecode
    gcc-4.6-base gcc-4.7-base gcc-4.8-base gcc-4.9-base gcc-5-base
    geoip-database
    isc-dhcp-client isc-dhcp-common
    libboost-iostreams1.58.0 libboost-iostreams1.60.0
    libc6-dbg
    libfreetype6-dev libpng-dev libmnl-dev zlib1g-dev
    libraspberrypi-doc libraspberrypi-dev
    libsigc++-1.2-5c2 libsigc++-2.0-0v5
    libudev0 libusb-0.1-4
    luajit
    vim-tiny vim-common
    v4l-utils

    ## References

    [1]: https://wiki.debian.org/ReduceDebian
  30. @hhromic hhromic revised this gist Nov 10, 2017. 1 changed file with 6 additions and 4 deletions.
    10 changes: 6 additions & 4 deletions raspbian-stretch-slimdown.md
    Original file line number Diff line number Diff line change
    @@ -1,13 +1,15 @@
    # Slimming Down Raspbian Stretch

    After installation of a fresh Raspbian Stretch, follow the instructions below.
    Notes for slimming down a fresh installation of Raspbian Stretch.

    Install a fresh Raspbian Stretch image into the SD card [2].
    ## Instructions

    Install a fresh Raspbian Stretch image into the SD card ([source][2]).

    $ unzip -p 2017-09-07-raspbian-stretch.zip | dd bs=4M of=/dev/sdX conv=fsync
    $ sync

    Configure headless ssh and Wi-Fi if necessary before starting the SD card [3].
    Configure headless ssh and Wi-Fi if necessary before starting the SD card ([source][3]).

    $ mount /dev/sdX /media
    $ :> /media/ssh
    @@ -24,7 +26,7 @@ Configure headless ssh and Wi-Fi if necessary before starting the SD card [3].
    $ umount /media
    $ sync

    Reconfigure apt so that it does not install additional packages [1].
    Reconfigure apt so that it does not install additional packages ([source][1]).

    $ cat > /etc/apt/apt.conf.d/80noadditional <<EOF
    APT::Install-Recommends "0";