Setting up Raspberry Pi Zero to connect to Manjaro Linux laptop

Thanks to Andrew Mulholland @gbaman for the hard work over Christmas 2015 in getting this achieved and the live demo in June 2016 London Mozclub. Thanks also to Brian Linuxing @brianlinuxing for additional support and advice.

This article was originally posted as a Gist in Github, when I didn’t understand the gist of a Gist. Reposting here for greater accessibility. Due to the time that has since past it may need updating. Comment below if you spot anything that needs correcting.

What we’ll be doing:

* Getting a Raspberry Pi Zero (pi0) to connect to another computer simply using the USB. That’s right, no monitor required.

What I used:

* pi0 v1.2 (this was the first original public version from the cover mounted PiMag from December 2015)
* microUSB power supply
* microUSB to USB cable
* microSD card – PNY 16GB
* Dell Latitude E4300 Laptop – Intel Core2 Duo, 64 Bit, 8GB Ram, circa 2008, reconditioned (my computer gets hotter than yours!)
* Linux – Manjaro 4.4.15 (rolling release) x86_64 LXQt

Gotchas:

* SD Cards in Raspberry Pi’s can be relatively flakey.
I tried a WORKING card from a mobile phone. Despite many attempts to format this card, using GPARTED, I reluctantly ended up purchasing a new SD Card. This clean card had the pi0 boot first attempt when testing via a monitor. I only needed to use a monitor after having so many issues with my first card. If you run into problems the SD Card may be the first place to check for an alternative.

* The pi0 will NOT be able to connect to the outside world to run updates or WGET or GIT CLONE
Watch this space though! A good friend is hoping to help me achieve this. I will link to any progress via this page.

Overview of process:

1. Install Raspbian onto SD Card
2. Edit a couple of files
3. Transfer card to pi0
4. Edit Network Manager
5. Power up
6. Connect to laptop
7. SSH to pi0

Let’s get this party started!!!

Install Raspbian onto SD Card

1. Grab the latest Raspbian image direct from the [Raspberry Pi Downloads](https://www.raspberrypi.org/downloads/raspbian/). Do NOT unzip it. Tempting as that may be for some people this process works direct from the zip file. If you’re confused as to what is the difference between the TORRENT file and the ZIP file – torrents allow a decentralised method to share and download files.. the ZIP file is direct from Raspberry Pi servers. For the sake of security and how far down the rabbit hole I’m prepared to go within this tutorial just grab the ZIP file direct from the website.
2. Open terminal and run the command `df -h` This GNU utility is called ‘disk filesystem’ and invoking this with “-h” will list the drives in a Human-readable way. If you wish to see what else it’s capable of run “df –help”. For now just take a mental note of the drives listed. In a following step you’ll be wanting to note the allocated drive path on inserting your SD Card.
3. Insert SD Card into laptop. My SD Card came with a really cool USB adapter but you can also use a standard microSD to SD Card that often comes with your card.
4. In terminal: run `df -h` command again. This time you’ll see an additional path to your SD Card. Note this path – something similar to “/dev/sdb1” or “/dev/mmcblk0p1”
5. In terminal: change directory to the folder where you copy of Raspian was downloaded. On my laptop it’s “~/Downloads/”. The full command (in my case) to enter in terminal is `cd ~/Downloads/`
6. Here we go! This is the burning of the Raspbian image to the SD Card. That path you noted down in step 4 is what is required here. If you are using an SD card adapter your path was something like “/dev/mmcblk0p1” or if you were using a usb adapter it’s maybe like “/dev/sdb1”. What will be required is to drop the last character or so to work on the root of the SD Card. Using both those examples I would use “/dev/mmcblk0” or “/dev/sdb” Again in terminal: `sudo dd bs=4M if=2016-05-27-raspbian-jessie.img of=/dev/mmcblk0 && sync` or editing if the name of the file has changed since my writing or your card is in another location. This step will take a few minutes. If you’re the type of person who would feel much less anxious about the waiting you could also replace “dd” with “dcfldd” which will display the progress.

Edit a couple of files

1. All going well when you mount your SD Card you’ll find the 2 folders. Open the BOOT folder and look for the 2 files ‘config.txt’ and ‘cmdline.txt’.
2. Open ‘config.txt’ from inside the BOOT folder in your text editor. In Manjaro the default app is LEAFPAD, but consider the flexibility of Linux, you might be using one of dozens of others.
3. Right at the bottom of this file add the following text on a new line `dtoverlay=dwc2` and save the file
4. Open ‘cmdline.txt’ and look for the text ‘rootwait’. Pay close attention to spaces in this file and only have ONE space either side of text, or you’ll mess everything up and the universe will implode.
5. Directly after the ‘rootwait’ command in this file put the following `modules-load=dwc2,g_ether` What this is doing is calling the DesignWare and g_ether drivers. These handle ethernet and USB OTG (On The Go) required modules. Save the file and now *safely* eject the SD Card.

Transfer card to pi0

1. As simple as taking the card out of the adapter and placing into the SD Card slot in the pi0. Get into the habit of doing things like this with the POWER OFF on the pi0. You’ll earn tech points and friends this way. Just do it.

Edit Network Manager

1. I recently switched to Manjaro after years of using Debian (specifically Crunchbang and then Bunsen Labs). There are so many different methodologies to getting things done in Linux it’s what makes it magical. With this in mind I will be only explaining what I did to achieve the outcome. There may be better ways to achieve this result and your results may vary on your setup. I am therefore going to be editing Network Manager using the LXQt UI. Manjaro rather awesomely has the required AVAHI already installed by default.
2. Right click the Network Manager applet >> select EDIT CONNECTIONS >> select ADD >> in the ‘Choose a connection type’ window select ETHERNET >> name the connection as you wish >> in the ‘IPv4 Settings’ change the drop down menu to LINK-LOCAL ONLY >> select SAVE
3. Reboot the laptop.

Power up

1. Connect the pi0 to the usb cable that will connect to the laptop. This is the micro usb on the left hand side. DO NOT connect it to the laptop though as until it’s powered up Network Manager will NOT recognise it.
2. Connect the UNPLUGGED power supply to the pi0. It’s the micro usb port on the right hand side.
3. Plug in the power supply to the electric socket and switch on
4. The green led indicator will start flashing away and will stay solid on when booted. Wait around ONE MINUTE for Raspbian to boot on the pi0

Connect to the laptop

1. Connect the usb cable from the pi0 to the laptop
2. The Network Manager applet in the dock will indicate it is configuring the connection
3. Once it’s connected a notification will popup ‘NetworkManager.. Connection Established.. You are now connected to.. (your ethernet network connection you previously added)’

SSH into the pi0

1. In terminal: `ssh pi@raspberrypi.local`
2. The default password is “raspberry”. The user is ‘pi’ which in my case I had force via the initial ssh command
3. Yay! It should now be working. Well done. Little dance necessary.
4. As the pi0 is NOT connected to the outside world yet ‘sudo apt-get update’ etc WILL NOT WORK. Additional tutorial on how to achieve this TBD.
5. You can download files to your laptop and send over ssh to the pi0. An example command to achieve this would be: `scp ~/Documents/testfile.txt pi@raspberrypi.local:Documents/`

If you like this type of content, have a few ideas of your own and wish to support our work, or wish to correct any errors, please comment below or use the CONTACT tab in the top navigation menu.

Until next time, Happy Linuxing!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s