0.2 SD card
Writing the image to SD
If you did not get a preconfigured SD card, you can download the image of any OS and write it to the SD card you intend to use for your Pi. In this repo, I use the official Raspbian.
Windows
When using Windows, I recommend the win32diskimager tool to copy the image to the SD card.
Linux
When using Mac or Linux, you can use the dd
command. Start by figuring out exactly which disk is your SD card, so you don't accidentally overwrite the wrong disk.
fdisk -l
Next, when you are sure which disk it your SD card, write the image to it. Be sure to edit the paths and disks to the correct ones in the following example:
sudo dd if=/path/to/image/file.img of=/path/to/sdcard bs=1m
In my case, this looks something like this:
sudo dd if=~/Downloads/raspbian.img of=/dev/disk7 bs=1m
This command will take a while, and won't give you any feedback while it is running! Just be patient for ten minutes or so. To get a progress bar, you may want to pipe pv
inbetween (which can be installed with sudo apt-get install pv
on Linux or brew install pv
in Mac if you have Homebrew). The result will be similar to this:
sudo dd if=~/Downloads/raspbian.img | pv | sudo dd of=/dev/disk7 bs=1m
Or this, if you know you have a 5GB file:
sudo dd if=~/Downloads/raspbian.img | pv -s 5G | sudo dd of=/dev/disk7 bs=1m
Mac
The process on a Mac is similar to Linux. Instead of fdisk -l
you want to use the following to figure out which path leads to the SD card:
diskutil list
Before using the dd
command (see the steps above for Linux) you'll have to unmount the SD card, otherwise it will refuse operation because 'the disk is busy'. Instead of ejecting the SD card through Finder (which will make it unavailable for the dd
command as well), you need to unmount it like so:
- Use
diskutil list
to find the mounted partition. E.g. in Finder my SD card shows up as 'SDCARD', anddiskutil
will show this:
/dev/disk3 (external, physical):
#: TYPE NAME SIZE IDENTIFIER
0: FDisk_partition_scheme *15.5 GB disk3
1: DOS_FAT_32 SDCARD 15.5 GB disk3s1
- The path to the mounted partition is a combination of the IDENTIFIER and the path, like so:
/dev/disk3s1
. - Unmount the partition using the path you found:
diskutil unmount /dev/disk3s1
. - Now you can use the
dd
commands described above to flash the image file to the card.
Back-up
Note that you can do the reverse of the command above to create a backup image of your SD card, for example like so:
dd if=/dev/disk7 of=~/Desktop/rpi_backup.img
On Windows, you can use win32diskimage tool instead.
Modifying the SD card
If you want to set up your Pi without attaching a display (a.k.a. 'headless'), then it should automatically connect to the network on first boot and start listening to an incoming SSH connection.
Since November 2016, Raspbian does not have SSH enabled by default. You can enable it manually in non-headless mode, but there's an easier way: preparing the SD card before you put it in the Pi. The boot
partition on the SD card is accessible by any OS, and you can use it to prepare SSH and WiFi.
Enable SSH
Simply put a file on the boot partition called 'ssh'. That's it:
For headless setup, SSH can be enabled by placing a file named ssh, without any extension, onto the boot partition of the SD card. When the Pi boots, it looks for the ssh file. If it is found, SSH is enabled, and the file is deleted. The content of the file does not matter: it could contain text, or nothing at all. (source)
WiFi
Similar method for WiFi. You can set it up manually, or by simply putting a file on the boot partition (source):
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=US
network={
ssid="YourWifiNetwork"
psk="SuperSecretPassword"
key_mgmt=WPA-PSK
}
Or, when running an older version than Raspbian Stretch, the shorter version will do:
network={
ssid="YourWifiNetwork"
psk="SuperSecretPassword"
key_mgmt=WPA-PSK
}
Edit the country code and the WiFi credentials and save this in a file called wpa_supplicant
on the SD card. On first boot, this file will automatically be picked up to configure the network.