Skip to content

Instantly share code, notes, and snippets.

@ryanjohnston
Last active September 10, 2018 14:35
Show Gist options
  • Save ryanjohnston/7afdd58dbe92484f9de1a854eadcdadc to your computer and use it in GitHub Desktop.
Save ryanjohnston/7afdd58dbe92484f9de1a854eadcdadc to your computer and use it in GitHub Desktop.
[๐Ÿ›  Raspbian - Snippets] Collected notes and scripts during RaspberryPi setup (2016) #config

Change hostname in Raspbian

Configuration

  • Change hostname file.
sudo vi /etc/hostname
  • Append /etc/hosts with:
127.0.0.1 [YOUR NEW HOSTNAME]

Reboot

  • Reboot for changes to take effect.
sudo reboot now

Delete Largest Packages

I needed to free up diskspace.

  • Identify largest installed packages
apt-list-packages
  • I removed the following large packages:
    • wolfram-engine
    • sonic-pi
    • libreoffice
    • scratch
    • nuscratch
    • greenfoot
  • Clean up.
apt-get autoremove

Dynamic Hostname with CloudFlare

Table of Contents

Update System

sudo apt-get install ddclient libjson-any-perl

Configuration

I hit escape through the wizard that comes up on the console. Need to configure manually.

wget http://downloads.sourceforge.net/project/ddclient/ddclient/ddclient-3.8.3.tar.bz2
tar -jxvf ddclient-3.8.3.tar.bz2
sudo cp -f ddclient-3.8.3/ddclient /usr/sbin/ddclient
sudo mkdir /etc/ddclient
sudo mv /etc/ddclient.conf /etc/ddclient/.
sudo vi /etc/ddclient/ddclient.conf
sudo service ddclient restart

Verification

After about 10 minutes, the dynamic hostname updated. I read that it's great to also force an update once a day in the middle of the night.

sudo crontab -e

Add the following to the crontab

45 04 * * * /usr/sbin/ddclient --force

This will update the dynamic hostname daily at 4:45AM server time.

LVM with 2 USB Drives

Example of setting up simple LVM striped array. No redundancy and not recommended.

First Boot

After the first boot...

sudo su

apt-get install lvm2

apt-get update --fix-missing

cd /media/pi

umount 5c40181f-38e9-426a-8a0e-f311bd45f58e/

umount ADATA\ HD650

umount WD\ Unlocker

mkdir -p /mnt/usbstorage

vi /etc/fstab

chown -R pi:pi /mnt

chmod -R 775 /mnt

setfacl -Rdm g:pi:rwx /mnt

setfacl -Rm g:pi:rwx /mnt

vgcreate datavg /dev/sdb1 /dev/sda2

lvcreate -l 100%FREE datavg

mkfs.ext4 /dev/datavg/lvol0

mount /dev/datavg/lvol0 /mnt/usbstorage

cp fstab fstab.bak

echo '/dev/datavg/lvol0 /mnt/usbstorage ext4 defaults 0 2' >> /etc/fstab

Smartmon

Setting up smartmon tools to watch the new LVM drive. My commands are below and the full details of each change are listed here

sudo su

apt-get install smartmontools gsmartcontrol smart-notifier

smartctl -a /dev/sda -d sat

smartctl -a /dev/sdb -d sat

vi /etc/default/smartmontools

vi /etc/smartd.conf

/etc/init.d/smartmontools restart

Find Headless RaspberryPi

  • For setup, I plugged an ethernet cord directly from my Mac straight to the Pi. I ran the following command to find the pi:
sudo arp-scan --interface=en1 --localnet
  • The Raspberry pi system showed up as:
10.76.16.5	b1:23:ec:41:29:62	Raspberry Pi Foundation
  • Logging in to the pi:
ssh pi@10.76.16.5

The default password is 'raspberry'

Headless GUI

Replace RealVNC that ships with Rasbian with TightVNC Server. Install XRDP.

$> sudo apt install -y tightvncserver
$> sudo apt install -y xrdp

Install Node on Raspbian

  • Confirm that we have armv7 CPU
$> uname -m
  • Add the Nodesource repo for Raspbery pi 3 Node.JS
$> curl -sL https://deb.nodesource.com/setup_7.x | sudo -E bash -
$> sudo apt-get install nodejs

Network Time Protocol

The instructions in this document are not actually recommended.

  • Disable ntp daemon and update clock hourly instead via cron.
$> sudo /etc/init.d/ntp stop
$> sudo systemctl disable ntp
$> sudo apt-get install ntpdate
$> vi /etc/cron.hourly/synctime
  • The contents of synctime should be.
#!/bin/sh
/usr/sbin/ntpdate -s 0.ca.pool.ntp.org
  • Setup cron to update time hourly.
$> sudo chmod 755 /etc/cron.hourly/synctime
  • Configure BlueTooth
$> sudo /etc/init.d/bluetooth stop
$> sudo systemctl disable bluetooth
  • Configure AVAHI
$> sudo /etc/init.d/avahi-daemon stop
$> sudo systemctl disable avahi-daemon
$> sudo systemctl disable avahi-daemon.socket

Setup Unattended Upgrades

Use these commands to setup automated updates for your Raspbian system.

sudo apt install unattended-upgrades
sudo vi /etc/apt/apt.conf.d/50unattended-upgrades
sudo apt install apticron
sudo vi /etc/apticron/apticron.conf

Update Rasbian

Update firmware

sudo apt-get install rpi-update

sudo rpi-update

sudo reboot now

Update Kernel and Userland

sudo apt-get update

sudo apt-get dist-upgrade

Update VIM on Raspbian

  • Install Vim
$> sudo apt-get install vim vim-doc
  • Setup apt-vim
$> curl -sL https://raw.githubusercontent.com/egalpin/apt-vim/master/install.sh | sh
$> . ~/.zshrc
$> apt-vim init

Force Raspbian to use DHCP by default.

This may have changed in new versions and may be the default now.

  • Open the network config file
sudo vi /etc/network/interfaces
  • Change the line from:
iface eth0 inet static
  • To
iface eth0 inet dhcp

Use Gmail for System Mail

HowTo

Full details on what to put in the config files is http://www.howtogeek.com/51819/how-to-setup-email-alerts-on-linux-using-gmail/

apt-get install ssmtp

vi /etc/ssmtp/ssmtp.conf

vi /etc/ssmtp/revaliases

Warning

I had to change a setting in my Google Account to allow less secure applications. This may or may not be a good thing and Google provides a link that describes what this change means.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment