{"id":1057,"date":"2017-04-17T00:01:20","date_gmt":"2017-04-16T22:01:20","guid":{"rendered":"http:\/\/hobbykeller.spdns.de\/?p=1057"},"modified":"2021-01-19T21:13:23","modified_gmt":"2021-01-19T20:13:23","slug":"getting-started-with-the-raspberry-pi-zero-w","status":"publish","type":"post","link":"https:\/\/hobbykeller.spdns.de\/?p=1057","title":{"rendered":"Getting Started with the Raspberry Pi Zero W"},"content":{"rendered":"<p>I recently bought one of the new Raspberry Pi Zero W boards to build a wireless CCTV camera. This article shows how to get the Raspbian Operating System installed and connected to your local WLAN network.<\/p>\n<p><!--more--><\/p>\n<h1>1. The Shopping List<\/h1>\n<p>What I bought was the following:<\/p>\n<ol>\n<li>A <a href=\"https:\/\/buyzero.de\/collections\/raspberry-pi-zero-kits\/products\/pi-zero-w-gehause-bundle\" target=\"_blank\" rel=\"noopener noreferrer\" class=\"broken_link\">Raspberry Pi Zero W Kit<\/a> with a plastic case and the camera adapter cable (approx. 20 EUR)<\/li>\n<li>A <a href=\"https:\/\/buyzero.de\/collections\/raspberry-pi-zero-und-zubehor\/products\/raspberry-pi-kameramodul-v2-noir\" target=\"_blank\" rel=\"noopener noreferrer\">PiNoIR v2 camera<\/a> module (approx. 30 EUR)<\/li>\n<li>An 8 GB SanDisk MicroSDHC class 10 memory card (approx. 7 EUR)<\/li>\n<\/ol>\n<p>As for the power supply, you can take any 5V charger from an Android phone with a micro USB connector.<\/p>\n<h2>2. The Operating System<\/h2>\n<p>I opted for the most recent Raspbian Jessie Lite version, as I wanted as little overhead as possible for the smooth operation of the camera (and maybe later a nextCloud service). Download the ZIP from this site and unzip the resulting image file to the hard disk of your local machine.<\/p>\n<h2>2.1 Preparing the SDHC memory card<\/h2>\n<p>Then insert the microSDHC card into the card reader of your local machine and check if it has a single partition which is formatted to fat32. Normally these cards are shipped pre-formatted and you do not have to do anything. The features should look as follows:<\/p>\n<figure id=\"attachment_1058\" aria-describedby=\"caption-attachment-1058\" style=\"width: 465px\" class=\"wp-caption alignnone\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-1058\" src=\"http:\/\/hobbykeller.spdns.de\/wp-content\/uploads\/2017\/04\/gparted_shdc.png\" alt=\"\" width=\"465\" height=\"395\" srcset=\"https:\/\/hobbykeller.spdns.de\/wp-content\/uploads\/2017\/04\/gparted_shdc.png 465w, https:\/\/hobbykeller.spdns.de\/wp-content\/uploads\/2017\/04\/gparted_shdc-300x255.png 300w, https:\/\/hobbykeller.spdns.de\/wp-content\/uploads\/2017\/04\/gparted_shdc-353x300.png 353w\" sizes=\"auto, (max-width: 465px) 100vw, 465px\" \/><figcaption id=\"caption-attachment-1058\" class=\"wp-caption-text\">Freshly formatted SDHC card as shipped from SanDisk<\/figcaption><\/figure>\n<p>Remember the path of the microSDHC card which is <code>\/dev\/mmcblk0p1<\/code>. You will need part of this path in the next step when you copy the image you downloaded to the memory card.<\/p>\n<h2>2.2 Copying the image to the card<\/h2>\n<p>Before you copy the image, make sure that you unmount the card. Depending on your OS, the card may be mounted under <code>\/media\/335-3432\/<\/code> (Ubuntu), <code>\/media\/user_id\/335-3432\/<\/code> or <code>\/run\/media\/user_id\/335-3432\/<\/code> (Manjaro). You can find this mount point by opening your file explorer, clicking on the link to the SDHC card and looking at the address bar in the top. The numbers at the end of the path may of course vary.<\/p>\n<p>[alert type=&#8221;warning&#8221; icon-size=&#8221;normal&#8221;]Keep in mind that the mount point and the path of the card are not identical. You must unmount the card from the mount point and not from its <code>\/dev<\/code> path.[\/alert]<\/p>\n<p>After unmounting copy the image file you unzipped to your card using the <code>dd<\/code> command from the terminal. The <code>of=<\/code> path should be the path of the card you retained at the end of section 2.1 <strong>without the partition indication<\/strong>. If the path was is <code>\/dev\/mmcblk0p1<\/code>, the corresponding out file parameter in the dd command should be: <code>of=\/dev\/mmcblk0<\/code>.<\/p>\n<p>[alert type=&#8221;danger&#8221; icon-size=&#8221;normal&#8221;]Think twice before you apply <code>dd<\/code>. Make sure you have the right <code>\/dev\/mmblk...<\/code> device in case you have more than one card connected to your machine. And &#8211; above all &#8211; do not confuse <code>if<\/code> and <code>of<\/code> parameters or you will risk fucking up your data or even your OS. <code>dd<\/code> is nick named &#8220;disk destroyer&#8221; for a reason.[\/alert]<\/p>\n<p>Here is how my card gets flashed with Raspbian:<\/p>\n<pre class=\"lang:default decode:true \" title=\"Falshing Raspbian image to your SDHC card\">[ilek@nordic ~]$ sudo unmount \/dev\/mmcblk0p1\r\n[ilek@nordic ~]$ dd bs=4M if=2017-04-10-raspbian-jessie-lite.img of=\/dev\/mmcblk0<\/pre>\n<p>After a while, your card should be flashed.<\/p>\n<h1>3. Preparing your image<\/h1>\n<p>Many of the tuorials on getting your Raspberry started recommend connecting your device to a monitor and a keyboard and setting up the remaining parameters. Apart from the fact that I newver liked fiddling around with cables on a Raspberry board which is intended to run as a standalone computer, this does not work for a Raspberry Zero. The reason is that there is only a micro USB plug while cable keyboards will have a &#8220;grown out&#8221; standard USB connector. The better way is to pre-edit the image before booting. The following description is based on <a href=\"https:\/\/web.archive.org\/web\/20170531064322\/https:\/\/davidmaitland.me\/2015\/12\/raspberry-pi-zero-headless-setup\/\" target=\"_blank\" rel=\"noopener noreferrer\" class=\"broken_link\">David Maitland&#8217;s tutorial on the Pi Zero headless setup (no longer online, archived version) <\/a>.<\/p>\n<h2>3.1 Add network key<\/h2>\n<p>Remount the SDHC card with the image flashed. After running the <code>sync<\/code> command from your terminal you can just eject and reinsert the card to get it mounted. Open your file explorer and you should see two mount points referring to the card: one is labeled boot, the other one comes up as a 1.3 GB volume &#8211; which suggests that a cheaper 4 GB card probably would have been sufficient. Click on the &#8220;non-boot&#8221; partition and copy the path in the address field to your clipboard.<\/p>\n<figure id=\"attachment_1060\" aria-describedby=\"caption-attachment-1060\" style=\"width: 642px\" class=\"wp-caption alignnone\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-1060\" src=\"http:\/\/hobbykeller.spdns.de\/wp-content\/uploads\/2017\/04\/in_situ_edit_of_raspbian_image.png\" alt=\"\" width=\"642\" height=\"407\" srcset=\"https:\/\/hobbykeller.spdns.de\/wp-content\/uploads\/2017\/04\/in_situ_edit_of_raspbian_image.png 642w, https:\/\/hobbykeller.spdns.de\/wp-content\/uploads\/2017\/04\/in_situ_edit_of_raspbian_image-300x190.png 300w, https:\/\/hobbykeller.spdns.de\/wp-content\/uploads\/2017\/04\/in_situ_edit_of_raspbian_image-473x300.png 473w\" sizes=\"auto, (max-width: 642px) 100vw, 642px\" \/><figcaption id=\"caption-attachment-1060\" class=\"wp-caption-text\">Finding the path to the Raspbian System on your SDHC card<\/figcaption><\/figure>\n<p>Then in the terminal window, <code>cd<\/code> to that directory, and afterwards <code>cd<\/code> to <code>etc\/wpa_supplicant\/<\/code>. Use <code>sudo vim<\/code> to edit the <code>wpa_supplicant.conf<\/code> file:<\/p>\n<pre class=\"lang:default decode:true\" title=\"Adding the WLAN access data to your Raspberry image\">[ilek@nordic ilek]$ cd \/run\/media\/ilek\/f2100b2f-ed84-4647-b5ae-089280112716\/\r\n[ilek@nordic f2100b2f-ed84-4647-b5ae-089280112716]$ cd etc\/wpa_supplicant\/\r\n[ilek@nordic wpa_supplicant]$ sudo vim wpa_supplicant.conf<\/pre>\n<p>Your <code>wpa_supplicant.conf<\/code> should look as follows:<\/p>\n<pre class=\"lang:default decode:true\" title=\"wpa_supplicant.conf in Raspbian image\">country=DE\r\nctrl_interface=DIR=\/var\/run\/wpa_supplicant GROUP=netdev\r\nupdate_config=1\r\n\r\nnetwork={\r\n\tssid=\"___Name_of_your_WIFI_network\"\r\n\tpsk=\"___your wifi password\"\r\n        key_mgmt=WPA-PSK\r\n}\r\n<\/pre>\n<p>[alert type=&#8221;warning&#8221; icon-size=&#8221;normal&#8221;]Raspbian is extremely picky with the syntax. Even a space before and after the equals sign can enough to derail the parsing of the wpa_supplicant.conf file at boot time.[\/alert]<\/p>\n<h2>3.2 Setup static IP<\/h2>\n<h3>New Raspbian Stretch Lite Edition<\/h3>\n<p>[alert type=&#8221;info&#8221; icon-size=&#8221;normal&#8221;]Since Raspian Stretch static IPs are no longer set up in <code>\/etc\/network\/interfaces<\/code> but in <code>\/etc\/dhcpcd.conf<\/code>[\/alert]<\/p>\n<p>There is no need to edit\u00a0<code>\/etc\/dhcpcd.conf<\/code> to set up name servers, either. The only file you need to edit is the\u00a0<code>\/etc\/dhcpcd.conf<\/code> file as follows:<\/p>\n<pre class=\"lang:default decode:true\" title=\"\/etc\/dhcpcd.conf file to configure static IP\"># Example static IP configuration:\r\n\r\n#interface eth0 \r\n#static ip_address=192.168.1.72\/24 \r\n#static routers=192.168.1.1 \r\n#static domain_name_servers=192.168.1.1 \r\n \r\ninterface wlan0 \r\nstatic ip_address=192.168.1.62\/24 \r\nstatic routers=192.168.1.1 \r\nstatic domain_name_servers=192.168.1.1 8.8.8.8 \r\n<\/pre>\n<h3>PreVious Raspbian Jessie Lite Edition<\/h3>\n<p>Unless you are very good at setting up network discovery services, it is a good idea to configure your Raspberry device with a static IP so that you can always be sure about the address under which you can access the device on your network.<\/p>\n<p>Setting the IP address and other related stuff is done by editing <code>etc\/network\/interfaces<\/code> with <code>sudo vim<\/code>. At the end of your edit, your interfaces file should look like this (where the IP address and the gateway may of course differ depending on the setup of your network):<\/p>\n<pre class=\"lang:default decode:true\" title=\"Adapting the IP address configuration\"># Include files from \/etc\/network\/interfaces.d:\r\nsource-directory \/etc\/network\/interfaces.d\r\n\r\nauto lo\r\niface lo inet loopback\r\n\r\niface eth0 inet manual\r\n\r\nallow-hotplug wlan0\r\niface wlan0 inet\r\n    address 192.168.1.8\r\n    netmask 255.255.255.0\r\n    gateway 192.168.1.1 \r\n    wpa-conf \/etc\/wpa_supplicant\/wpa_supplicant.conf\r\n\r\nallow-hotplug wlan1\r\niface wlan1 inet manual\r\n    wpa-conf \/etc\/wpa_supplicant\/wpa_supplicant.conf<\/pre>\n<p>As the Raspbian image is already pre-configured to use the iconic <code>8.8.8.8<\/code> and <code>8.8.8.4<\/code> DNS servers from Google, this step is rather optional. Skip it if you are fine with Google logging your DNS queries, or &#8211; if you are paranoid &#8211; edit <code>etc\/resolv.conf<\/code> and replace the DNS IPs by a pair of servers you think you can trust more. You can choose such a server from <a href=\"http:\/\/www.bestdns.org\/\" target=\"_blank\" rel=\"noopener noreferrer\">here<\/a>.<\/p>\n<h2>3.3 Activate SSH<\/h2>\n<p>Raspberry ships their Raspbian images with <code>ssh<\/code> deactivated by default. This of course is bad news if you want to run a headless confiuration from scratch. You have to be sure that you can access your Pi zero by <code>ssh<\/code> over the network.<\/p>\n<p>Now comes the moment where we have to work on the <code>boot<\/code> partition of the image. Again, the easiest way to find the address of boot is to open your file browser and click on the <code>boot<\/code> partition of the SDHC card in the Devices section. Then copy the path to the clipboard as before und run <code>cd<\/code> + paste in your terminal.<\/p>\n<pre class=\"lang:default decode:true\" title=\"Activating ssh on the Raspberry image\">[ilek@nordic etc]$ cd \/run\/media\/ilek\/boot\/\r\n[ilek@nordic boot]$ touch ssh<\/pre>\n<h1>4. Boot your Pi<\/h1>\n<p>Your Pi is now ready for booting. Unmount the SDHC card and remove it from your workstation and plug it into your pi. Connect it to the power cable of an Android USB charger and wait ~ 45 sec until it has completely booted.<\/p>\n<p>Then ssh into the Pi using the IP address you assigned it in the <code>etc\/network\/interfaces<\/code> of section 3.2. The default password for the Pi is.. guess what? Yes, it&#8217;s <strong>raspberry<\/strong>.<\/p>\n<p>[alert type=&#8221;warning&#8221; icon-size=&#8221;normal&#8221;]Do not forget to change the password using the <code>passwd<\/code> comand once you have logged into your pi.[\/alert]<\/p>\n<h1>5. Adding authorized keys<\/h1>\n<p>Instead of password authentication it is usually more convenient to set up a key based authentication. As the Pi0W will normally only be passively involved in remote log in procedures &#8211; i.e. the Pi0W will be the host on which someone remotely logs in but nobody will remotely log in from the Pi0W onto another host &#8211; we do not even need to create the key-pair but just set up the\u00a0<code>.ssh<\/code> directory:<\/p>\n<pre class=\"lang:default decode:true\">pi@pi0:~ $ mkdir .ssh\r\npi@pi0:~ $ chmod 700 .ssh\r\npi@pi0:~ $ vim .ssh\/authorized_keys\r\n<\/pre>\n<p>Copy the\u00a0<code>id_rsa.pub<\/code> public key of the <strong>client machine<\/strong> into the <code>authorized_keys<\/code> file on the Pi0W.<\/p>\n<p>Set the access rights for the <code>authorized_keys<\/code> file to 600:<\/p>\n<pre class=\"lang:default decode:true\" title=\"chmnodding authorized_keys file to rw only for user\">chmod 600 .ssh\/authorized_keys<\/pre>\n<p>Log out from your Pi0W and check if relogging in from the client machine can be done by public key authentication. If this is the case, you may want to switch off password authentication completely by uncommenting the <code>PasswordAuthentication<\/code>flag in the\u00a0<code>\/etc\/ssh\/sshd_config<\/code> file and setting it to <code>no<\/code> on the Pi0w:<\/p>\n<pre class=\"lang:default decode:true\" title=\"Enforcing Public Key Authentication in SSH\"># To disable tunneled clear text passwords, change to no here! \r\nPasswordAuthentication no  \r\n#PermitEmptyPasswords no<\/pre>\n<p>Reboot the Pi0w to activate the new configuration.<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I recently bought one of the new Raspberry Pi Zero W boards to build a wireless CCTV camera. This article shows how to get the Raspbian Operating System installed and<span class=\"more-button\"><a href=\"https:\/\/hobbykeller.spdns.de\/?p=1057\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\">Getting Started with the Raspberry Pi Zero W<\/span><\/a><\/span><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[64,237],"tags":[240,239,242,238,241],"class_list":["post-1057","post","type-post","status-publish","format-standard","hentry","category-linux","category-raspberry","tag-headless-configuration","tag-pi-zero-w","tag-ramdisk","tag-raspberry","tag-wpa_supplicant"],"_links":{"self":[{"href":"https:\/\/hobbykeller.spdns.de\/index.php?rest_route=\/wp\/v2\/posts\/1057","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hobbykeller.spdns.de\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hobbykeller.spdns.de\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hobbykeller.spdns.de\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/hobbykeller.spdns.de\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1057"}],"version-history":[{"count":13,"href":"https:\/\/hobbykeller.spdns.de\/index.php?rest_route=\/wp\/v2\/posts\/1057\/revisions"}],"predecessor-version":[{"id":1347,"href":"https:\/\/hobbykeller.spdns.de\/index.php?rest_route=\/wp\/v2\/posts\/1057\/revisions\/1347"}],"wp:attachment":[{"href":"https:\/\/hobbykeller.spdns.de\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1057"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hobbykeller.spdns.de\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1057"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hobbykeller.spdns.de\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1057"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}