Setup the Raspberry Pi Zero Wireless

Today I got myself the RaspberryPi Zero Wireless edition.

In todays post I will show you how to setup the Pi with Raspbian using Linux and how to connect it to your wireless network in a headless setup.

Raspbian Image

The latest raspbian can be found from the link below:
- https://www.raspberrypi.org/downloads/raspbian/

Get Raspbian

Download the latest Raspbian from the link provided above to the local disk:

$ wget https://downloads.raspberrypi.org/raspbian_lite/images/raspbian_lite-2018-06-29/2018-06-27-raspbian-stretch-lite.zip

Unzip the package that you downloaded:

$ unzip 2018-06-27-raspbian-stretch-lite.zip

Formatting your Pi

As we are using Linux for this demonstration, insert your SD Card into your PC/Laptop, then have a list the block devices, to determine the SD Card's device name:

$ lsblk
NAME        MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT  
sda           8:0    0 931.5G  0 disk  
├─sda2        8:2    0     1K  0 part 
├─sda5        8:5    0  15.9G  0 part [SWAP]
└─sda1        8:1    0 915.7G  0 part /
mmcblk0     179:0    0  14.9G  0 disk  
├─mmcblk0p2 179:2    0  14.8G  0 part /media/ruan/rootfs
└─mmcblk0p1 179:1    0  43.2M  0 part /media/ruan/boot

As you can see the SD Card has 2 partitions and is mounted as /dev/mmcblk0p1 and /dev/mmcblk0p2.

Unmount them:

$ sudo umount /dev/mmcblk0p2
$ sudo umount /dev/mmcblk0p1

Verify, to see if the mountpoint's were removed:

$ lsblk
NAME        MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT  
sda           8:0    0 931.5G  0 disk  
├─sda2        8:2    0     1K  0 part 
├─sda5        8:5    0  15.9G  0 part [SWAP]
└─sda1        8:1    0 915.7G  0 part /
mmcblk0     179:0    0  14.9G  0 disk  
├─mmcblk0p2 179:2    0  14.8G  0 part 
└─mmcblk0p1 179:1    0  43.2M  0 part 

Now format the SD Card with Raspbian using dd:

$ sudo dd bs=4M if=2018-06-27-raspbian-stretch-lite.img of=/dev/mmcblk0 conv=fsync
444+0 records in  
444+0 records out  
1862270976 bytes (1.9 GB, 1.7 GiB) copied, 132.357 s, 14.1 MB/s  

Eject the SD Card and re-insert to mount the disk so that we can access the filesystem to configure ssh and wifi.

Configure SSH and WiFi

In order to have the RaspberryPi connecting to your Wifi Network and have SSH enabled, we need to do 2 things:

1 . For SSH: Create a empty file in the boot directory named ssh.

$ touch /media/ruan/boot/ssh

2 . For Wifi: Create a wpa_supplicant.conf in the boot directory and configure your wifi details.

Change country, ssid and psk:

$ sudo vi /media/ruan/boot/wpa_supplicant.conf

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev  
update_config=1  
country=ZA

network={  
    ssid="your-wifi-name"
    psk="your-wifi-password"
    key_mgmt=WPA-PSK
}

When the device reboots the files will be copied to the relevant paths.

Reboot and Enjoy

Reboot your Raspberry Pi and access it via the following details:

Hostname: raspberrypi  
Username: pi  
Password: raspberry  

As a best practice from a security perspective, logon to your device and reset your password:

$ passwd pi