Skip to main content

How did I setup a Rasberry Pi 3 without any peripherals

I am an absolute beginner in this Raspberry Pi (I'll be using "RPi" for short) world and this post shows how I started up the RPi without using external keyboard or mouse (for RPi) and still managed to get a graphical desktop environment of Raspbian on my Debian workstation (and controlled my RPi remotely).


Step 1: I downloaded 'Raspbian Stretch with Desktop' (here). I got a ZIP file. I unzipped it and ended up with a .img which was roughly 4.6 GB.

Step 2: Now, to create a bootable media (a memory card perhaps) by copying the .img file onto it, I used dd command.

sudo dd if=<path to img> of=/dev/<sdb,sdc..>

Be particularly careful with using dd command. You can mess up a lot of things. Using dd command on your memory card will wipe out all contents in it. Using dd command on your hard disk, umm.. not a good idea. To know the disk path of your memory card, use sudo fdisk -l  (el in small caps). Your hard disk will probably be /dev/sda. Your memory card will be something other than that. Mine was /dev/sdb. Also, you don't have to use sdb1, sdb2 etc. So, the command that I used was
sudo dd if=~/2018-03-13-raspbian-stretch.img of=/dev/sdb
This may take about 10 mins.

Step 3: I ended up getting two partitions on my memory card. One was "boot" and the other was "rootfs".
To enable ssh in my RPi, I opened the "boot" partition and created an empty file with the name "ssh".



Step 4: Now the question is, how do we connect the RPi to the internet? We don't have a keyboard or mouse or even a display monitor to operate it. If you search on the internet, you will find many solutions like these which tell you how to connect RPi to WiFi. Unfortunately, they didn't work for me for some reason :( So, I had to take a long path to get to the point where I will end up getting connected to the WiFi and eventually connect the RPi to the internet.

So, what I did was, I inserted the memory card into my RPi and booted it up. Now, I connected the RPi and my laptop with an ethernet cable. I found that the IP of my eth0 interface on laptop was 192.168.0.3 and the broadcast IP was 192.168.0.255 (using ifconfig command).

I had nmap already installed on my laptop. So, to find out the IP of the RPi, I scanned for the active hosts using this command:

sudo nmap -n -sP 192.168.0.255/24

The output was something like:




So, now I know that the IP of my RPi is 192.168.0.47.
SSH is already enabled. So, to connect to my RPi I used: 

ssh -Y pi@192.168.0.47

The default password for SSH (on RPi) is raspberry

Now, the consequence of this step was this:


I am successfully logged into RPi using SSH! Next step is to connect RPi to the WiFi so that I can SSH into RPi through the WiFi network and also use the internet from the WiFi in RPi.

Step 5: From the RPi terminal, I modified the wpa_supplicant.conf file ( full path was /etc/wpa_supplicant/wpa_supplicant.conf ) using nano command line editor. vi was behaving really weird.

sudo nano /etc/wpa_supplicant/wpa_supplicant.conf

The contents that I added was this:

network={
       ssid="Name_of_your_wifi"
       psk="your_weak_password"
}

Of course, you change the obvious things. Now, to test which WiFi networks are visible to the RPi, I used

sudo iwlist wlan0 scan

And my WiFi was visible to my RPi. To reconfigure the wlan0 interface (of RPi) and connect to my WiFi network, I used

wpa_cli -i wlan0 reconfigure

To check if the RPi had connected to my WiFi, I did a quick ifconfig wlan0 and yes, the inet field was set which means, RPi was connected to the WiFi!

Step 6: I unplugged the ethernet connection between the RPi and my laptop, and connected my laptop to the same WiFi network that my RPi was connected to. I did an ifconfig in my laptop which told me that the wlan0 (of my laptop) had 192.168.43.111 IP and broadcast IP was 192.168.43.255.

To know the IP of my RPi (which was then connected to the WiFi), I again used nmap on my laptop.

sudo nmap -n -sP 192.168.43.255/24

which told me that the IP of my RPi was 192.168.43.175.

Then to SSH into my RPi again,

ssh -Y pi@192.168.43.175

And yes! I was again on the RPi terminal but this time, it was through WiFi. Now I could successfully execute sudo apt-get update and some other stuff as I was connected to the internet!

I could have avoided using nmap again in this step to know the IP of the RPi because I had already done an ifconfig wlan0 in SSHed RPi in the previous step when it was connected with the ethernet and knew the IP of the wlan0 (WiFi) interface, but I wanted to double check if the RPi is visible on the WiFi network and it is reachable from my laptop. So, that's why I unplugged the ethernet connection immediately after the RPi got connected to the WiFi and proceeded with using nmap from my laptop (as explained in the current step).

Step 7: Now, I wanted the graphical desktop environment of RPi on my laptop screen so that working with RPi will be quicker (only in some cases. Otherwise, I prefer command-line).
To do this, I used RealVNC server and client (this software lets you share the desktop of one computer with several other computers remotely!), RPi acting as the VNC server, and my laptop acting as a client. The great news was, RPi comes with a preinstalled version of VNC server and client. I needed to start VNC server on my RPi so, through my SSHed RPi terminal, I used

vncserver :1 -geometry 1024x600 -depth 16 -pixelformat rgb565

and boom! The server was on!

Last step: To finally connect my laptop to RPi and operate it through a remote desktop view, I downloaded the VNC client, called "VNC Viewer" from here. It was an executable. After executing it, I entered the IP of the RPi (which was 192.168.43.175) along with the 'display number' of the VNC server (which was 1). So, in VNC Viewer, I entered 192.168.43.175:1 and done! I ended up with this in a window on my laptop screen:


So, yeah! This is what I, the noob of RPi did. If you have a shortcut way of doing this, or any other "headless approach to Raspberry Pi" is working for you, please leave a comment about it below.



UPDATE:

I just realised that I did take a useless long path for this. I could have started VNC server (on RPi) when I was connected to the ssh via ethernet and then use VNC client on Debian to get the UI of RPi and then in that UI window, I could have connected to WiFi by clicking on the icon in the top-right corner. In that way, eth0 and wlan0 interfaces on RPi are used separately. We'll still use eth0 for ssh (although we can use the RPi terminal directly in VNC client) and wlan0 for internet.

But it was a great experience and a dumb move as well.


Thanks for reading!

References:

Comments

Popular posts from this blog

My-Cloud-IDE - a SaaS built using Docker

I always wanted to know about how services like Codenvy  and Heroku  internally worked. The only way to understand that was to build a similar project. The main component of this project is Docker. Docker  Docker is a software that performs OS-level virtualisation and is developed for Linux. More information about it can be found here . About My-Cloud-IDE: My-Cloud-IDE is a proof-of-concept for a Software as a Service (SaaS). It   can be used to perform software development on cloud without worrying about resolving software dependencies, software installations etc. The user gets a fully functional IDE in his/her browser after registration. Each user has his/her own isolated software environment because My-Cloud-IDE uses Docker to perform OS-level virtualisation in the backend. Technical Details I divided the project into two modules. One module was for 'management' purpose. This includes user interfaces, user management and preparing some files that a...

Privacy Concerns in Android

Introduction       Android has a robust Access control system. If an Android app needs to use resources or information outside of its own scope, the app has to request the appropriate permission . It needs to get permissions before accessing critical resources like Camera, Location, Contacts etc. On Android 6.0 (Marshmallow) or higher, the app needs to request these permissions at runtime by showing a dialog box to the user. Also, the user will have an option to revoke these permissions for that app at any time in future.       But, in this article, I would like to point out a few resources that an app can access without any permission s and this might raise a serious privacy concern for the user. Privacy Concerns An app can fetch a list of all other apps installed on your phone. An app doesn't need to request any permissions from you to get a list of all the apps installed on your phone. For example, a Netflix app can get to know wh...