Introduction :-
Raspberry Pi is a low cost, tiny, single board computer to which you can connect a monitor, a keyboard and a mouse and it will work like your PC. It comes in different variants according to its RAM size (2GB, 4GB or 8GB). An external micro SD card (at least 8GB, 16/32GB is recommended) needs to be connected to it which acts as its memory disk.
In this blog I will be covering steps to boot a Raspberry Pi 4B without separate monitor (headless) and keyboard and access its command terminal.
NOTE :- At some places, you might see that the process or the command is stuck. In such case keep patience if something doesn't show up on the screen. Some commands might take some time to execute.
Things Used :-
1. Raspberry Pi 4B
2. Ethernet Cable
3. 32GB Micro SD Card
4. Memory Card Reader
5. Official Raspberry Pi 4 Power Supply
NOTE :- I have used a windows PC in this tutorial, if any other operating system is installed on your PC, you will need to find the corresponding commands for it.
Getting Started :-
In this section we will be flashing our micro SD card with the Raspbian OS, enabling SSH, booting up the PI and accessing its terminal. We will need the Raspbian OS, the official Raspberry PI Imager software and the puTTY software.
1. Downloading the softwares :
-
- Go to the official Raspberry Pi Downloads page and download the Raspberry Pi Imager and the Raspbian operating system.
- Leave the Raspbian zip file as it is. You don't need to extract it.
- For this tutorial I have used the Raspberry Pi OS with desktop (without recommended software).
-
- After downloading, install the imager.
- The imager window will look like this:
2. Flashing the SD Card :
-
- Insert the card in the card reader and connect it to your PC.
- First, we need to format the card to delete the previous content. It can be done with any software. Here, I am using the imager itself to format the card.
- Go to 'CHOOSE OS', then click on 'Erase'.
-
- Now, click on 'CHOOSE STORAGE'.
- It will show the list of external storage devices connected to your PC.
- Select the appropriate card from the list.
- Now click on .
-
- After the card gets formatted, again click on 'CHOOSE OS'.
- Then click on 'Use custom'. This will let you browse for a custom OS on your PC.
- Browse the Raspbian image that you downloaded earlier and select that.
- Then, again select the card from the Storage list.
- Now, click on 'WRITE'.
- The flashing will now start. After the flashing process gets completed, a file verification process will start. Let it complete.
- If the process gets completed without any error, then you are ready for the next step. Remove the card from the card reader.
3. Enabling SSH :
The SSH (Secure Shell) protocol is a method for secure remote login from one computer to another. We will use SSH to login to the PI using our PC.
-
- Now, again insert the SD Card into the card reader.
- The flashing process creates two partitions in the card. One of them is the 'boot' partition which stores all the files necessary for booting up the PI.
- To enable SSH, create an empty file with name 'ssh' without any extension as shown below:
-
- Remove the card from the reader. Now you are ready to start the PI
Upon boot up, the PI will search for the ssh file in the boot directory and if it is present, the PI will enable the SSH and automatically delete this file.
4. Booting up the PI :
-
- Now, insert the card into the PI and connect to the power supply.
- Connect the PI to your PC using the ethernet cable.
- Now, turn on the power.
-
- The red LED shows that the board is getting power.
- The green LED indicates SD Card activity.
5. Getting the ipv4 address of PI :
In this section we will try to reach our PI using the ping command. Ping is a command which is used to troubleshoot connectivity and
reachability of a device.
-
- Now, open the command prompt on your PC.
- Then type the following command and hit enter:
ping raspberrypi.local
-
- It will check the connectivity with your PI and give you the ipv6 address of the PI.
- Then type the following command and hit enter:
ping raspberrypi -4
-
- This will show you the ipv4 address (note it down) of your PI as shown below:
6. Connecting to the PI terminal via SSH :
We will use puTTY to emulate our PI terminal.
-
- Go to the puTTY official page and install the latest version.
- Now open puTTY and enter the ip address of your PI as shown below:
-
- Now click on 'Open'.
- A warning might displayed on the screen as given below. Just read it and then click on 'Yes'.
-
- Now, you will be asked for your username and password.
- The default username and password for raspberry pi are: 'pi' and 'raspberry', respectively.
- Type the username and password and hit enter.
- The first login might take some time. Be patient.
- You will have logged into your PI successfully.
- Now, you can work on the PI terminal.
NOTE :- If you are typing your password and it doesn't seem getting typed, then don't worry. On linux systems, nothing is shown when you type your password on the terminal. Just keep typing the password and then hit enter.
7. Changing the default password :
-
- To change the password for your PI, enter the following command and hit enter:
passwd
- To change the password for your PI, enter the following command and hit enter:
-
- You will be asked to enter your current password which is 'raspberry'. Just type it and hit enter.
- Now, you will be asked to enter your new password. Enter it.
- Then, retype the password and hit enter.
- Now, your password has been changed.
8. Reboot and Shutdown :
-
- To reboot:
sudo reboot
- To reboot:
-
- To shutdown:
sudo poweroff
- To shutdown:
Upgrading your PI :-
In this section, we will see how to upgrade your PI. It is something you should do everytime you start your PI.
The 'raspi-config' is a configuration tool in Raspbian. It enables you to configure various settings of your OS. Use the arrow keys to navigate through the window. After finishing your configuration, it will ask to reboot your PI.
1. Connecting to WiFi network :
-
- Turn on wireless hotspot from your mobile phone.
- Now, in the PI terminal, type the following command:
sudo raspi-config
-
- It will open a window with various settings as shown below:
-
- Enter the 'System Options' menu.
-
- Now, enter the 'Wireless LAN' menu.
- Select your country from the list.
- Then, enter your SSID and Password.
- After hitting enter, your PI will get connected to your mobile hotspot within few seconds.
- You don't need to reboot your PI after doing this setting.
- After doing the above setting, everytime you turn on your PI and your mobile hotspot, the PI should automatically get connected to it in few seconds.
2. Upgrading the PI :
-
- Enter the following command to update your PI:
sudo apt update
- This command will download the list of all the latest packages and from where to download them from.
- Now, enter the following command to upgrade your PI:
sudo apt full-upgrade
- Enter the following command to update your PI:
-
- This command will download all the latest packages and upgrade the OS.
- This will take a few minutes to complete.
NOTE :- If any command fails to download some packages or you see any kind of error, again try both the commands till the PI gets upgraded successfully.
Viewing Raspberry PI Desktop on your PC :
Till now we have seen the steps to access the PI terminal. Terminal is sufficient to get most of the work done.
Now, we will look into the steps of viewing the Raspbian Desktop on our PC. We will need a separate software to achieve this. But first lets make some changes to our PI.
1. Changing boot option and resolution:
-
- Open raspi-config.
- Go to 'System Options ---> Boot/Auto Login'.
- Select 'Desktop Autologin' and hit enter.
-
- Now, go to 'Display Options ---> Screen Resolution'.
- Select the 1080p resolution and hit enter.
- Now, reboot your PI to apply the changes.
2. Enabling SSH on PI:
There are two ways to enable ssh on the PI. The first one is by creating a file as we did above. The second is given below. You need to do these steps only if ssh is not already enabled.
-
- Open raspi-config.
- Go to 'Interface Options ---> SSH'.
- Hit enter to enable ssh.
3. Viewing PI Desktop on VNC viewer:
We will be using the VNC (virtual network computing) viewer to view the PI Desktop. VNC is a graphical-desktop sharing system which enables us to control any remote computer. The latest Raspbian packages come preinstalled with VNC server, we just need to activate it and download a viewer on our PC.
-
- Open 'raspi-config' on the PI terminal.
- Go to 'Interface Options ---> VNC' and enable it.
- Now, you can log out of your puTTY SSH terminal by typing 'exit' and entering.
- Download and install the VNC Viewer from this page on your PC.
- Enter 'raspberrypi.local' in the search bar and hit enter as shown below:
-
- After some time it will ask for the PI username and password. Enter them and you are ready to go.
- The PI Desktop will look like this:
Some common errors and their solutions :-
In this section, we will deal with some of the common errors which you might face while using your PI. You can find many other issues on this forum.
1. Input/Output Error :-
It indicates that there was some error either in reading from or writing to your SD card. This might be due to a faulty SD Card or a faulty card reader.
I got this error when I was trying to upgrade my PI. Soon, I realized that it was my card reader's fault, so I changed my card reader and re-flashed the SD Card.
In case of such error, it is advised to follow the following steps:
- Try rebooting and then repeating that operation again. If the problem still exists then,
- Change your card reader and re-flash your SD Card. If the problem still exists then,
- Try changing your SD Card.
2. The green led blinks seven times :-
It means there is no bootable image connected to the SD Card. It might be caused by abruptly removing the power supply from PI while it is still writing to the SD Card. This might corrupt the SD card.
Follow the following steps:
- Try rebooting your PI. If the problem still exists then,
- Try reflashing your SD Card. If the problem still exists then,
- Try changing your SD Card.
3. Error - 'Cannot currently show the desktop on VNC viewer' shows upon up connecting to the PI through the VNC viewer :-
You will get this error if you haven't changed the boot option and the resolution as explained above. Remember to reboot the system after doing these settings otherwise the above error will be shown.
Conclusion :-
In this blog, I have tried to list down the steps for headless boot up of the Raspberry Pi, to view the Raspberry Pi Desktop using VNC viewer and dealt with some commons errors. Please comment down if your have any suggestions regarding the blog.
Top Comments