Getting started with Raspberry Pi
If you are using raspberry pi for the first time; then this post might be helpful to setup the device.
In this post I’ll cover
- installing raspbian/ubuntu on the sd card for raspberry pi.
- configuring ssh.
- configuring wifi to connect to the network automatically.
Installing Raspbian/Ubuntu on the SD card
First of all download the image of the os you want to install on the SD card from raspberrypi.org/downloads.
If the file that you have downloaded is a zip file; then extract the contents of that file and find the .img file in it. this is the file we are going to install on the SD card.
Run following command to get the block device for SD card.
$ df Filesystem 1K-blocks Used Available Use% Mounted on udev 4032932 0 4032932 0% /dev /dev/sda5 39240312 19431624 17792332 53% / /dev/sda6 78611376 73607668 987376 99% /home /dev/mmcblk0 15542944 8 15542936 1% /media/x-dev/3CAC-7C20
Here in the last line it says /dev/mmcblk0 this is the device file for SD card.
You will see that this device is mounted at /media/user/some-directory if you are working on ubuntu
or at /run/media/user/some-directory if you are working on Fedora.
You need to unmount these partitions before you proceed by running:
# umount </path/to/device> # for example on ubuntu you have to run $ umount /media/x-dev/3CAC-7C20 # on fedora the command will be something like $ umount /run/media/<user>/partition
Now you can install the .img that you have downloaded on to the SD card by using:
$ sudo dd bs=4M if="OS-Image-file.img" of=/dev/mmcblk0 status=progress
The dd command will take a while to complete. Once it is done you can insert the SD card in RaspberryPi and start using it.
However if you don’t have a monitor you will need to configure the ssh and wifi connection to use the device.
Connecting the device to wifi network
Keep the memory card inserted; make sure that the partitions are mounted.
also keep in mind whatever changes we are making should be on the files in /etc in the memory card and not in the files in /etc on your computer.
$ cd /media/user/root-of-rpi-os $ vim etc/network/interfaces
add the following code to this file under wlan0 block
auto wlan0 allow-hotplug wlan0 iface wlan0 inet manual wpa-ssid "your-ssid" wpa-psk "your-password" wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
after this your device should connect to the wifi network automatically once it is started.
Enable ssh on the raspberry pi
$ cd /media/user/root-of-rpi-os $ touch etc/SSHFLAG $ vim etc/rc.local
Now add the following code just before exit 0 line
if [ -e /etc/SSHFLAG ]; then /usr/sbin/update-rc.d -f ssh defaults /bin/rm /etc/SSHFLAG /sbin/shutdown -r now fi sudo /etc/init.d/ssh start
this will enable the ssh on your raspberry pi.
Now insert the SD card in to raspberry pi and you are good to go.
you can check the ip address of your raspberry pi in the router’s connected device and start using Raspberry pi over ssh.