Due to a lot of requests, we’re introducing the ‘IoT Basics’ to our Explainer series covering all the important things you need to know to get started with a Raspberry Pi, aimed at newbies. We will be covering topics like – using a breadboard, the use of resistors, GPIO pins, among others. Let us look at how to install an OS on Raspberry Pi.
We all start pretty much in the same place; Buy a Raspberry Pi, unpack it, connect it to the power cable, install an Operating System and then may be start brainstorming for things to do with the Rpi, or start playing minecraft. (If you’re curious about the game, check pi store after installing the OS)
So, let’s begin with installing the OS.
First, select the Operating System. You can find the list of supported OS on ‘downloads’ page on the Raspberry pi website. You can download the OS from here.
IMPORTANT: Please note that the ‘dd’ tool can write over pretty much any partition on your machine, including the linux partition. So, please be careful when you specify the device name for writing over.
Preparing the SD card:
Run $ df -h to list all the currently mounted devices. Then insert the SD card and run the same command again. The newly appeared device on the list in the SD card that we are going to be writing the disk image to, so note the device id of the same. The device id on my machine is /dev/sdb
If your device id has a suffix like ‘p1’ or ‘1’ then it is referring to the partition. But remember that we need to write to the whole disk and not just the partition, so wherever we use the device id, drop the partition suffix and write unless specifically mentioned. For example, if the device id is /dev/mmcblk0p1 or /dev/sdb1, drop the last part ‘p1’ or ‘1’ respectively.
Now unmount the SD card, so that files can’t be read in or copied to the card while the image is being copied to the card.
Run $ sudo umount /dev/sdb1 including the partition number. If the list of devices showed up more than one device due to multiple partitions, unmount all of them. The command requires root permissions, so if you are not logged in as root, prefix all commands with sudo.
Now, run $ sudo dd bs=4M if=2016-05-27-raspbian-jessie.img of=/dev/sdb command to write the OS image to the card
Make sure you replace the ’if’ parameter value with the path to the OS image that needs to be written, and the ‘of’ parameter value needs to be replaced with the device id of the SD card. Please make sure to be careful to specify the right name for the device name, as mentioned earlier. The device name should be specified without the partition number.
This will roughly take up to 3 to 4 minutes and the terminal would look like the process is frozen. If you are using an SD card reader, then the LED on it would blink continuously. Otherwise just run $ sudo pkill -USR1 -n -x dd on another terminal, and the progress would be displayed in the original terminal window.
Note: The block size is mentioned as ‘4M’ in the command. If it does not work, then change it to as less as ‘1M’ but remember that this will slow down the process quite a bit.
$ sudo dd bs=4M if=2016-05-27-raspbian-jessie.img of=/dev/sdb
958+1 records in
958+1 records out
4019191808 bytes (4.0 GB) copied, 405.585 s, 9.9 MB/s
Finally, use $ sync to ensure that the write cache is flushed and it is safe to unmount the SD card.
If you are using windows, then check out Win32DiskImager utility. Okay now that we’re done prepping the memory card, what next?
Booting for the first time:
For this you would require a USB keyboard, USB mouse, 5V USB power supply, HDMI monitor (I just connect the pi to my television), and of course the Raspberry Pi.
Connect power and you should see the boot sequence on the TV. After first boot, the Raspberry Pi boots up in setup mode and if not, you can type the following command to get there:
$ sudo raspi-config
First things that need to be done are, resizing the file system to use the entire SD card, in my case it is 32GB. Check the first option on the setup menu. Then change the location and timezone to match yours. By default it is set to United Kingdom.
Now on rebooting the Raspberry Pi, it boots with the new configuration. The setup is now done and ready to use for any projects you’d like. For getting started with your first ever DIY project on the Raspberry Pi, check out this project.