Install Raspbian on Raspberry Pi

There are probably thousands, if not more, articles on the internet about how to install an OS on your Raspberry Pi. This article will largely repeat a lot of those, but I wanted to capture what I needed to do.

If you do not care to read (or about) all the words and explanations, feel free to skip to the SHORT VERSION

BACKGROUND

I ordered my Raspberry Pi very early on. I mean really early. I was on some sort of waitlist to get the thing, so keep in mind that I’m talking about the most basic version here. So basic that I quickly lost interest in the thing because, while it was neat and pretty cheap…it just was capable of doing very much. Incredibly underpowered for anything I found useful. So it sat collecting dust for a long time.

Now, many years later, I thought I’d give it a shot at some pretty rudimentary tasks (more details to come) and found that I had no idea what was on the thing and had forgotten how to get an OS on it.  I did some research and it appears that Raspbian is somewhat officialized as the OS of choice.  Here are the steps I took to install Raspbian on my original Raspberry Pi:

01 Download the latest version of Raspbian

This is pretty straightforward.  I will create a directory for the download and get the latest version. This will take a bit so be patient. Then unzip it:

mkdir ~/pi;
cd ~/pi;
wget http://downloads.raspberrypi.org/raspbian_latest;
unzip raspbian_latest;

NOTE:  the unzip above will create a .img file whose name is potentially different than mine depending on when these instructions are followed, however, we will work around that with some wildcards below

02 Identify your SD card

As you may know, Linux can be confusing when it comes to naming devices.  By running a command PRIOR to inserting the SD card (via your method of choice) and comparing that output to the output of the same command AFTER the card is inserted, you can identify the card and save the name in a variable (I am currently using Fedora so I use lsblk, but there is likely something comparable if you are using a different version of Linux):

BEFORE INSERTING SD CARD:

lsblk;

INSERT THE CARD AND RUN THE COMMAND AGAIN:

lsblk;

You should notice a new device has been added. It may have partitions on it depending on how the card was used previously, but we’ll be writing over everything with a disk image so those should not matter.  It is important to use your own device (not a partition on the device) for the next command.  We will put our device name in a variable to ease future instructions (USE YOUR DEVICE NAME, MINE HAPPENS TO BE /dev/sdb:

card="/dev/sdb";

NOTE: my system did not automount the card upon insertion, but if yours did, it is important to unmount it (umount $card) prior to moving on

03 Copy the image to the SD card

Now using the variable we just created and a wildcard in a command substitution, we will copy the image to the SD card using the dd utility (which I think is Linux-flavor agnostic).  This will take a while, so be patient:
sudo dd if=$(ls *.img) of=$card bs=4M;

NOTE: a block size (bs) of 4MB is used because most SD cards have an erase block size of 4MB and if you do not include this parameter, the image will be copied even slower

04 Power on the Raspberry Pi

At this point the SD card has the latest Raspbian build on it.  Insert it into your Raspberry Pi, connect a network cable to your Raspberry Pi, and power it on by supplying it with power.

05 Identify the IP of your Raspberry Pi and log in

Once you given it a chance to boot up, you can find the IP of your newly installed Raspberry Pi using nmap.  In order to do so, you must be familiar enough with your network to know what DHCP range is relevant.  In the example below, DHCP addresses are assigned in the 10.10.10.1/24 range, so that is what is scanned with nmap.

sudo dnf install -y nmap;
RASPIP=$(sudo nmap -sn 10.10.10.1/24 | grep -B2 Raspberry | awk '/report/ {print $NF}');

You can now log into your Raspberry Pi using the “pi” user and default credentials easily found with an internet search:

ssh pi@$RASPIP

NOTE: you can also use nmap to find the MAC address of your Pi and reserve an IP for it on whatever serves your network’s DHCP. You know, for consistency…


NEXT STEPS

You will want to log in and continue to configure you Raspberry Pi (by running sudo raspi-config for example). You can even configure it further using Ansible!

WHAT I LEARNED

  • Linux is fun!

REFERENCES:


SHORT VERSION:

To avoid tl;dr enjoy this instead:

## 01 Download the latest version of Raspbian
mkdir ~/pi;
cd ~/pi;
wget http://downloads.raspberrypi.org/raspbian_latest;
unzip raspbian_latest;
## 02 Identify your SD card
#  BEFORE INSERTING SD CARD:
lsblk;
#  INSERT THE CARD AND RUN THE COMMAND AGAIN:
lsblk;
#  Assign YOUR value to a variable, mine was /dev/sdb:
card="/dev/sdb";
## 03 Copy the image to the SD card
sudo dd if=$(ls *.img) of=$card bs=4M;
## 04 Power on the Raspberry Pi
#  Insert your SD card, network, and power
## 05 Identify the IP of your Raspberry Pi and log in
sudo dnf install -y nmap;
RASPIP=$(sudo nmap -sn 10.10.10.1/24 | grep -B2 Raspberry | awk '/report/ {print $NF}');
ssh pi@$RASPIP

[return to top of page]

Leave a Reply

Your email address will not be published. Required fields are marked *