Saturday, 25 February 2017

RPi Raspbian install with Mac

Updated 2018-03-22 !

When starting up a new project with Raspberry Pi I like to start up fresh and with a minimal OS. Therefore i always use Raspbian Lite. Doing it right You don't have to use an external display, keybord and mouse, just the ssh client from Your Mac

Connect the card reader, with the SD card inserted, to Your Mac and format the card with SD Formatter and use the "Owerwrite Formate" option. This will also check that the SD card is OK.

Download the latest OS(with or without Desktop/GUI), as image, from unzip it and put it in Your root directory. The same directory as the one You start in when using the program Terminal

Start the program Terminal, on Your Mac, and check Your SD cards name type

$ diskutil list

and You will have something like

/dev/disk0 (internal, physical):                                              
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        *121.3 GB   disk0     
   1:                        EFI EFI                     209.7 MB   disk0s1  
   2:          Apple_CoreStorage Macintosh HD            120.5 GB   disk0s2  
/dev/disk1 (internal, virtual):                                              
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:                            Macintosh HD           +120.1 GB   disk1    
                                 Logical Volume on disk0s2                  
/dev/disk2 (external, physical):                                            
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:     FDisk_partition_scheme                        *8.1 GB     disk2    

In this case "/dev/disk2" is the name

You now have to unmount the SD card.

$ diskutil unmountDisk /dev/disk2             
Unmount of all volumes on disk2 was successful

and then copy the OS to the SD card using the password to the Mac

sudo dd bs=1m if=2018-03-13-raspbian-stretch-lite.img of=/dev/disk2

1772+0 records in
1772+0 records out
1858076672 bytes transferred in 716.458666 secs (2593418 bytes/sec)

Check with Finder and You will see a nice structure of files and folders.

Create an empty file with the name "ssh", no extension, in the root of the SD card. This will enable ssh before it is actually configured.(See picture above)

Plug the SD card into Your RPi, connect the lan cable.

Connect the mouse, keyboard, screen and power. Log on and continue with the configuration below.


Use headless just connecting the power

It will boot, green led blinks, and after about 2 minutes it schould be visible in Your routers list over connected devices with the name "raspberrypi".

Or just check with a ping in the Terminal

$ ping raspberrypi
PING raspberrypi.lan ( 56 data bytes
64 bytes from icmp_seq=0 ttl=64 time=247.129 ms
64 bytes from icmp_seq=1 ttl=64 time=8.676 ms
64 bytes from icmp_seq=2 ttl=64 time=3.914 ms

64 bytes from icmp_seq=3 ttl=64 time=1.865 ms

Start Terminal and logon with "ssh" and default password "raspberry"

$ ssh pi@raspberrypi                                                        
The authenticity of host 'raspberrypi (' can't be established.
ECDSA key fingerprint is SHA256:lNY6d3pAK5TDO5XLma3k2w0IgOkGBcs1wa1T7QGaXjk.
Are you sure you want to continue connecting (yes/no)? yes                  
Warning: Permanently added 'raspberrypi' (ECDSA) to the list of known hosts.
Warning: the ECDSA host key for 'raspberrypi' differs from the key for the IP address ''                                                      
Offending key for IP in /Users/xxxxx/.ssh/known_hosts:5                    
Are you sure you want to continue connecting (yes/no)? yes                  
pi@raspberrypi's password:                                                  
The programs included with the Debian GNU/Linux system are free software;  
the exact distribution terms for each program are described in the          
individual files in /usr/share/doc/*/copyright.                            
Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent          
permitted by applicable law.                                                    
SSH is enabled and the default password for the 'pi' user has not been changed.  
This is a security risk - please login as the 'pi' user and type 'passwd' to set a new password.
pi@raspberrypi:~ $

If the name doesn't work with the ssh command use the IP from the routers devicelist instead.

As You see in the log I have used this RPi before and the router is assigning it the same IP but with a new fingerprint(New OS). The easiest way to solve the problem is just to empty the file  "known_hosts" on Your Mac.

And now over to the basic setup and pic the items below. Use up and down arrow to move, left right arrow to select and Enter to confirm

$ sudo raspi-config

And go through the following items

1/ Change User Password
2/ Network Options
   N1/ Hostname
   N2/ WiFi
4/ Localisations options
   I1/ Change locale (Swedish sv_SE ISO-8859-1)
   I2/ Change timezone
   I3/ Change Keyboard Layout
   I4/ Change Wi-fi Country
5/ Interfacing options
   P2/ SSH Enable/Disable remote command line access to your Pi using SSH
7/ Advanced Options
   A1/ Expand file system

then reboot 

$ sudo reboot

logon and update the installation with

$ sudo apt-get update
$ sudo apt-get upgrade
$ sudo apt-get clean

You schould also check Samba, RPi as a Windows fileserver, RPi as a Apache webserver with PHP and Rasbian lite with GUI, VNC, RDP.

1 comment:

  1. Pretty! This has been a really wonderful article.
    Thank you for supplying these details.