Setting up a minimal Raspberrian on a Raspberry Pi2

After resetting my previous installation of Observium on a Raspberry Pi I will move forward and install a LibreNMS instead. My first steps are:
- Zapping the old installation
- Downloading the 2016-05-27-raspbian-jessie-lite.zip
- Installing that image
- Booting the first time
- Setting up initial networking
- Updates
- Installation of necessary toolset
- Setup backup
- Hook the system into my OpenVPN cloud
- Setting up email sending and root mail forward
- Getting SNMPd up and running

Zapping old installation
On my Mac I do:
sudo bash diskutil list # Use the correct disk or you delete your own installation dd if=/dev/zero of=/dev/disk5 bs=1024k
Downloading image
Get your latest image of the Raspberian Lite here.
Installing the image
# See what we got and unpack it shasum -a1 2016-05-27-raspbian-jessie-lite.zip 03b6ea33efc3bb4d475f528421d554fc1ef91944 2016-05-27-raspbian-jessie-lite.zip # Compare with the SHA-1 on the website!!! unzip -l 2016-05-27-raspbian-jessie-lite.zip Archive: 2016-05-27-raspbian-jessie-lite.zip Length Date Time Name -------- ---- ---- ---- 1387266048 05-27-16 13:41 2016-05-27-raspbian-jessie-lite.img -------- ------- 1387266048 1 file unzip 2016-05-27-raspbian-jessie-lite.zip Archive: 2016-05-27-raspbian-jessie-lite.zip inflating: 2016-05-27-raspbian-jessie-lite.img 2016-05-27-raspbian-jessie-lite.img -rw-r--r--@ 1 root staff 1,3G 27 Mai 13:41 2016-05-27-raspbian-jessie-lite.img # And now install it dd if=2016-05-27-raspbian-jessie-lite.img of=/dev/disk5 bs=1024k 1323+0 records in 1323+0 records out 1387266048 bytes transferred in 529.211209 secs (2621384 bytes/sec)
First boot
Setting up initial network
As the system is setup to boot via DHCP, just give it a new name. I choose UniMatrixOne
Updates
sudo bash aptitude update aptitude safe-upgrade aptitude clean reboot
Installing necessary tools
I install my normal tool set and the part for borgbackup
aptitude install vim-nox htop screen tcpdump tshark iotop lvm2 rsync \ python3 python3-dev python3-pip python-virtualenv \ libssl-dev openssl \ libacl1-dev libacl1 \ liblz4-dev liblz4-1 \ build-essential pip3 install borgbackup
Setup Backup
I use borg backup on an external 3.5″ disk, which is hooked via SATA2USB Adapter.
To setup the backup disk I use lvm:
# I assume the disk is at /dev/sdb # Add one primary partition and give it all the space # as ext2 fdisk /dev/sdb # Create the physical volume pvcreate /dev/sdb1 # Create the volume group vgcreate vg_backup /dev/sb1 # Create the logical volume lvcreate -n v_backup -l 100%FREE vg_backup # Create filesystem mkfs.ext4 -m0 /dev/mapper/vg_backup-lv_backup mkdir /backup mount /dev/mapper/vg_backup-lv_backup /backup
And initialize the borg backup
/usr/local/sbin/borg init -e repokey /backup/`hostname`
After installing this /usr/local/sbin/makeLocalBackup.sh script
#!/bin/bash if [ ! -d /backup/`hostname` ] then echo "Mounting target /backup/" /sbin/vgchange -a y vg_backup mount /dev/mapper/vg_backup-lv_backup /backup echo "done" fi if [ -d /backup/`hostname` ] then /usr/local/bin/borg create -C zlib,9 -x /backup/{hostname}::{now:%Y%m%d-%H%M} / /boot /usr/local/bin/borg prune --keep-hourly 6 --keep-daily 7 --keep-weekly 4 --keep-monthly 6 /backup/{hostname} else echo "Backup of `hostname` (/, /boot) failed as target was not mounted" exit 1 fi
and this /usr/local/sbin/showLocalBackup.sh
#!/bin/bash if [ ! -d /backup/`hostname` ] then /sbin/vgchange -a y vg_backup mount /dev/mapper/vg_backup-lv_backup /backup fi if [ -d /backup/`hostname` ] then echo "/backup/`hostname`" /usr/local/bin/borg list /backup/{hostname} /usr/local/bin/borg info /backup/{hostname}::`/usr/local/bin/borg list /backup/{hostname}|tail -n1|cut -d" " -f1` du -sch /backup/`hostname` else echo "/backup/`hostname` not mounted" exit 1 fi
We need to check this once a week with this script:
#!/bin/bash if [ ! -d /backup/`hostname` ] then echo "Mounting target /backup/" /sbin/vgchange -a y vg_backup mount /dev/mapper/vg_backup-lv_backup /backup echo "done" fi if [ -d /backup/`hostname` ] then /usr/local/bin/borg check /backup/{hostname} else echo "Check of Backup of `hostname` failed as target was not mounted" exit 1 fi
I can add it to the cron system. Voila backup done.
chmod 700 /usr/local/sbin/????LocalBackup.sh echo "0 * * * * root /usr/local/sbin/makeLocalBackup.sh" >/etc/cron.d/makeLocalBackup echo '30 0 * * 0 root /usr/local/sbin/checkLocalBackup.sh' >/etc/cron.d/checkLocalBackup
Hooking it up to OpenVPN
I added the openvpn package and installed my certs.
Mail support
I also install exim4 and mutt to do basic emailing with forwarding all root mail to my personal account.
aptitude install exim4 mutt dpkg-reconfigure exim4-config
Adding SNMPd
Next step is to install the SNMPd and setting it up:
aptitude install snmpd cat <<EOM >/etc/snmp/snmpd.conf > rocommunity PleaseSetYourOwn > sysLocation UniMatrixOne > sysContact info@linuxpinguin.de > disk / 5% > disk /backup 5% > disk /boot 5% > EOM systemctl restart snmpd systemctl enable snmpd
And now we have the minimal system running:
pstree systemd─┬─2*[agetty] ├─avahi-daemon───avahi-daemon ├─cron ├─dbus-daemon ├─exim4 ├─ntpd ├─openvpn ├─rsyslogd─┬─{in:imklog} │ ├─{in:imuxsock} │ └─{rs:main Q:Reg} ├─snmpd ├─sshd───sshd───bash─┬─pstree │ └─tail ├─systemd-journal ├─systemd-logind ├─systemd-udevd └─thd df -h Filesystem Size Used Avail Use% Mounted on /dev/root 30G 1.3G 27G 5% / devtmpfs 483M 0 483M 0% /dev tmpfs 487M 0 487M 0% /dev/shm tmpfs 487M 6.5M 481M 2% /run tmpfs 5.0M 4.0K 5.0M 1% /run/lock tmpfs 487M 0 487M 0% /sys/fs/cgroup /dev/mmcblk0p1 63M 21M 43M 33% /boot /dev/mapper/vg_backup-lv_backup 2.7T 45G 2.7T 2% /backup free -h total used free shared buffers cached Mem: 973M 407M 565M 6.4M 55M 269M -/+ buffers/cache: 82M 890M Swap: 99M 0B 99M
That’s it!
We use this install for the various projects, which are coming soon.