Build Raspberry Pi from scratch for Ubiquiti controller

Posted on Sat 09 June 2018 in misc

Find the SD card disk:

 ~  df -h
Filesystem      Size   Used  Avail Capacity iused               ifree %iused  Mounted on
/dev/disk1s1   931Gi  856Gi   73Gi    93% 5073102 9223372036849702705    0%   /
devfs          340Ki  340Ki    0Bi   100%    1176                   0  100%   /dev
/dev/disk1s4   931Gi  1.0Gi   73Gi     2%       1 9223372036854775806    0%   /private/var/vm
map -hosts       0Bi    0Bi    0Bi   100%       0                   0  100%   /net
map auto_home    0Bi    0Bi    0Bi   100%       0                   0  100%   /home
map -fstab       0Bi    0Bi    0Bi   100%       0                   0  100%   /Network/Servers
/dev/disk2s1    59Gi  8.8Mi   59Gi     1%      70              486922    0%   /Volumes/Untitled

Format as ExFat

 ~  sudo diskutil eraseDisk ExFat Rpi /dev/disk2
Password:
Started erase on disk2
Unmounting disk
Creating the partition map
Waiting for partitions to activate
Formatting disk2s2 as ExFAT with name Rpi
Volume name      : Rpi
Partition offset : 411648 sectors (210763776 bytes)
Volume size      : 124321792 sectors (63652757504 bytes)
Bytes per sector : 512
Bytes per cluster: 131072
FAT offset       : 2048 sectors (1048576 bytes)
# FAT sectors    : 4096
Number of FATs   : 1
Cluster offset   : 6144 sectors (3145728 bytes)
# Clusters       : 485608
Volume Serial #  : 5b1b931a
Bitmap start     : 2
Bitmap file size : 60701
Upcase start     : 3
Upcase file size : 5836
Root start       : 4
Mounting disk
Finished erase on disk2

Check its worked

 ~  df -h
Filesystem      Size   Used  Avail Capacity iused               ifree %iused  Mounted on
/dev/disk1s1   931Gi  856Gi   73Gi    93% 5073085 9223372036849702722    0%   /
devfs          341Ki  341Ki    0Bi   100%    1180                   0  100%   /dev
/dev/disk1s4   931Gi  1.0Gi   73Gi     2%       1 9223372036854775806    0%   /private/var/vm
map -hosts       0Bi    0Bi    0Bi   100%       0                   0  100%   /net
map auto_home    0Bi    0Bi    0Bi   100%       0                   0  100%   /home
map -fstab       0Bi    0Bi    0Bi   100%       0                   0  100%   /Network/Servers
/dev/disk2s2    59Gi  8.8Mi   59Gi     1%      70              485538    0%   /Volumes/Rpi

Unmount

 ~  sudo diskutil unmount /dev/disk2s2
Volume Rpi on disk2s2 unmounted

Download the latest version of Raspbian http://downloads.raspberrypi.org/raspbian_latest

Unzip

~  cd ~/Downloads ~/Downloads  unzip 2018-04-18-raspbian-stretch.zip Archive: 2018-04-18-raspbian-stretch.zip inflating: 2018-04-18-raspbian-stretch.img

Block copy the .img file to the rdisk not sdisk

~/Downloads  sudo dd bs=1m if=2018-04-18-raspbian-stretch.img of=/dev/rdisk2 Password: 4724+0 records in 4724+0 records out 4953473024 bytes transferred in 124.643039 secs (39741273 bytes/sec

You can watch the activity of this with Activity monitor if needs be. It will take a while, and the output for progress is non-existent.

Eject card, plug into RPi and boot. This should then appear on the network - you should be able to find it by using

Booting and it comes up fine, but no SSH enabled on this current image , aparently making a file called ssh on the Fat32 partition is all you need

Insert the card back into your card ready and:

cd /Volumes/boot
touch ssh

And eject the disk again

ssh pi@192.168.0.42
accept the key
enter the default password of raspberry

Now time to secure it a bit more

passwd

And change the default password

Now copy our ssh key accross

ssh-copy-id pi@192.168.0.42

Now update the OS

sudo apt-get update
sudo apt-get upgrade

Now to start installing the Ubiquiti stuff

sudo su

cd /tmp
wget https://raw.githubusercontent.com/Bobspadger/ubiquitiunificontroller/master/rpi-install.sh
bash rpi-install.sh

And follow through the instructions

I already have a controller set up so I'll export the configuration from my laptop, and import it to the RPI and let it take over / adopt all the AP's on the network.

On unifi controller
Settings >> Scroll to bottom and export 

echo 'deb http://www.ubnt.com/downloads/unifi/debian stable ubiquiti' | sudo tee /etc/apt/sources.list.d/ubnt-unifi.list sudo wget -O /etc/apt/trusted.gpg.d/unifi-repo.gpg https://dl.ubnt.com/unifi/unifi-repo.gpg sudo apt-get update && sudo apt-get dist-upgrade -y && sudo apt-get install unifi haveged -y