This tutorial walks you through getting the Raspbian OS installed and configured on a Raspberry Pi with wireless networking. This is how I first set up almost any Raspberry Pi that I use.
1. Obtain a Raspbian Linux Image
Begin by downloading the Raspbian Lite image. I typically prefer the "Lite" image, which doesn't have a bunch of pre-installed desktop (Xorg) software packages that I do not use.
Linux
If your system automounts the SD card, then it's easy to find what it's called:
larz@amnesiac:~$ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sdb5 11G 11G 0 100% /
/dev/mmcblk0p1 30G 16K 30G 1% /media/larz/B378-2F33
In this case, we want to write to the entire device /dev/mmcblk0
. Appending p1
addresses the first partition; we want to overwrite the boot blocks and partition table, though, so we address the whole device node.
If it's still mounted, umount /dev/mmcblk0p1
. If you haven't extracted the image from the ZIP archive, run unzip
as well.
larz@amnesiac:~$ sudo dd bs=4M if=2018-06-27-raspbian-stretch.img of=/dev/mmcblk0 status=progress oflag=sync
2600468480 bytes (2.6 GB, 2.4 GiB) copied, 205.147 s, 12.7 MB/s
This command writes the image in 4 Mb chunks, synchronizing the write cache in real time, and showing progress of the actual device writing. Here's what it looks like when it's finished:
1150+0 records in
1150+0 records out
4823449600 bytes (4.8 GB, 4.5 GiB) copied, 380.294 s, 12.7 MB/s
larz@amnesiac:~$
Windows
Use Win32 Disk Imager to write the image to the card.
2. Essential Configuration
Boot and login with user pi
and password raspberry
. Now run sudo raspi-config
and complete the following steps with the configuration tool:
- Expand the filesystem.
- Update the locale, timezone, and keyboard layout.
- Enable sshd.
Exit the configuration tool.
3. Wireless Network Configuration
If you want to use WiFi on a network with a WPA2 pre-shared key (typical modern WiFi security), run sudo sh -c 'wpa_passphrase myssid mypass >> /etc/wpa_supplicant/wpa_supplicant.conf'
, replacing "myssid" with your own SSID and "mypass" with the network's shared passphrase key.
Next, edit /etc/network/interfaces
to make it resemble this:
auto lo
iface lo inet loopback
allow-hotplug wlan0
auto wlan0
iface wlan0 inet dhcp
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
Steps for Ethernet configuration are slightly different. If you're using Ethernet with DHCP, simply replace "wlan0" with "eth0" everywhere, and omit the last line for WPA2 security.
4. Additional Network Configuration
I run a DHCP server on which I configure my known hosts. I create an entry for each of my hosts, which specifies the MAC address of the network adapter, a unique hostname for that host to use, and a matching IP address. The host then receives its hostname and IP address from the DHCP server and uses them. My DNS server maps these hostnames to their respective IP addresses. This way, the configuration on each Raspberry Pi is identical, and I can just make copies of a base SD image.
Your wireless router may allow such configuration. If you're running a DHCP server and DNS server on OpenBSD, check out my tutorial Dynamic Host Configuration on OpenBSD.
Otherwise, if you can't send your Raspberry Pi a hostname from your DHCP server and resolve that name back to its IP address, I suggest you follow these steps:
- Run
sudo raspi-config
and choose a unique hostname. - After exiting the configuration tool, run
sudo nano /etc/hosts
and addmyname
to the end of the first two lines.
5. User Account
Wouldn't you like to use your own user account instead of the built-in pi
user? Then run sudo adduser larz
(choosing your own username instead of "larz," of course!). To give your new account sudo access, run sudo visudo
, and add a line that reads larz ALL=(ALL) NOPASSWD: ALL
. Notice that one of the last lines does this for user pi
--if you're using nano
as your editor, cut that line with Ctrl+K and paste it back twice with Ctrl+U twice, and alter one of them to give your user access.
Now is a great time to reboot. Run sudo reboot
.
Login with your new user account. Like to keep a clean house? Then run sudo deluser pi
followed by rm -rf /home/pi
. Now that default user account is gone.
6. Software update
To discover updates to all of the software packages installed on your Raspbian OS, run sudo apt-get update
. This may take some time, as sources are downloaded over the Internet and unpacked. Now run sudo apt-get dist-upgrade
to actually install the updates.
You now have a Raspberry Pi that is ready for whatever you throw at it! Enjoy!
NOTES
doc version b
- write raspbian lite image to sd card
- open gvim
- new file; leave empty; save as g:\ssh
- new file; paste contents using Shift + Ins; save as g:\wpa_supplicant.conf
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=us
network={
ssid="myssid"
psk="mypass"
key_mgmt=WPA-PSK
}
- boot. login as pi:raspberry
- change password
- sudo apt-get update
- sudo apt-get install vim
- edit /etc/hostname to contain "localhost" --- this will lead the dhcp client to set the hostname to whatever the dhcp server says.
installing motioneye
- follow https://github.com/ccrisan/motioneye/wiki/Install-On-Debian, and use commands from http://www.deb-multimedia.org/ when it doesn't work.[1]
[1] see https://raspberrypi.stackexchange.com/questions/10251/prepare-sd-card-for-wifi-on-headless-pi