collapse

Welcome!



Welcome to Robot Rebels, an online robot maker community.

Register today to post your projects, ask questions, share knowledge and meet like-minded people from around the world.


The RobotRebel.org Community

Author Topic: Headless Arch Linux on Raspberry Pi Zero W  (Read 978 times)

Ladvien

  • Alabtu-ian Refugee
  • Member
  • *
  • Posts: 57
Headless Arch Linux on Raspberry Pi Zero W
« on: March 30, 2018, 09:28:37 PM »

Disclaimer:  The _easiest_ way to setup an SD card with Arch Linux for the Raspberry Pi Zero W (rp0w) is using Linux--and the following guide will assume you have access to Linux somewhere.  For Mac and Windows users, it is possible to setup an SD card using Linux inside of a virtual machine.  The interwebs will have more on the subject.

The hardest part of setting up Arch Linux for the rp0w is getting the WiFi working on boot.  This allows accessing the OS through ssh immediately.  This is known as a "headless setup."  I've created instructions on doing something similar in Kali.  However, I was lucky when I hit Arch--as there is a fine fellow who has already written a script to setup the WPA Supplicant needed for a headless build.

* Stasiana's instructions script for setting up wpa_supplicant

1. Create an SD Card by following the Arch Linux instructions
Really, the only piece of information not provided by Arch Linux community is which ARM architecture you need for the rp0w.  It's armv6. 

* Raspberry Pi 1 / Zero / Zero W
* Raspberry Pi 2
* Raspberry Pi 3

A few notes on using the installation instructions.
* I had to run most of the commands as root (sudo)
* We are going to insert a step afte the SD card is setup and before we boot our rp0w
* MOST IMPORTANT NOTE: If you accidently select a different device instead of your SD card bad poop will happen.  For real.  To know which device is your card make heavy use of fdisk -l which will provide a list of all devices.  Your SD card is approximately the same size as the card states.  For example, this is the output I get when I run  fdisk -l on my PC with the SD card in.

Code: [Select]
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: gpt

Device         Start       End   Sectors   Size Type
/dev/sda1         40    409639    409600   200M EFI S
/dev/sda2     409640 578929663 578520024 275.9G unkno
/dev/sda3  578929664 586480023   7550360   3.6G Micro
/dev/sda4  586480024 586742167    262144   128M Apple
/dev/sda5  586743808 976842751 390098944   186G Linux
/dev/sda6  976842880 977105023    262144   128M Apple

Mounting
Unmounting
Cleaning up

Disk /dev/sdb: 7.5 GiB, 8053063680 bytes, 15728640 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xd0ca12f8

Device     Boot  Start      End  Sectors  Size Id Type
/dev/sdb1         2048   206847   204800  100M  c W95
/dev/sdb2       206848 15728639 15521792  7.4G 83 Linu
So, the main device path for my SD card is /dev/sdb.  And to the first partition it's /dev/sdb1


2. Create Script to Enable WiFi on Boot
We are going to need to create a script on the Linux OS you used to setup the SD card.  This script will access the rp0w's Arch Linux files and inject our WiFi information.  This will allow the rp0w to automatically connect to your WiFi router when it boots, thus, giving you immediate access to it via SSH.

At the command prompt (of your PC, not the rp0w)
Code: [Select]
nano al-wpa-setup.shThis will open a blank nano editor.  Inside, paste the following, then save the file.

Code: [Select]
#!/bin/sh

set -e

if [[ $# -ne 3 ]] ; then
   echo "Usage: $0 </dev/disk> <ssid> <passphase>"
   exit 1
fi

DISK="$1"
SSID="$2"
PASS="$3"

if [[ ! -b "${DISK}" ]] ; then
   echo "Not a block device: ${DISK}"
   exit 1
fi

if [[ "${USER}" != "root" ]] ; then
   echo "Must run as root."
   exit 1
fi

echo Mounting
mkdir root
mount "${DISK}2" root

cat << EOF >> root/etc/systemd/network/wlan0.network
[Match]
Name=wlan0

[Network]
DHCP=yes
EOF

wpa_passphrase "${SSID}" "${PASS}" > root/etc/wpa_supplicant/wpa_supplicant-wlan0.conf

ln -s \
   /usr/lib/systemd/system/wpa_supplicant@.service \
   root/etc/systemd/system/multi-user.target.wants/wpa_supplicant@wlan0.service

echo Unmounting
umount root

echo Cleaning up
rmdir root
For those curious or wary, this script takes three parameters

1. The location of SD card in the PC's device tree
2. SSID of your WiFi router
3. Password for the WiFi router

It then mounts the SD card, accesses the files needed to setup WiFi, and inserts the connection information appropriately.

Thanks again, Stasiana.

Let's keep going.

Before we can run the script it must be given executable permissions.

Code: [Select]
chmod +x al-wpa-setup.shNote:  If you execute the script in the same path as where you built the SD card then the script will complain

Code: [Select]
mkdir: cannot create directory ‘root’: File existsThat's because the Arch Linux instructions didn't mention removing the SD card paths.

To delete the paths root and boot which were required for setup run (make sure your not in the / path first).
Code: [Select]
sudo rm -R boot rootNow, let's execute it, passing /dev/sdX, your_wifi_name, and your_wifi_password.  Like so.

Code: [Select]
./al-wpa-setup.sh /dev/sdb wifi_name wifi_passwordIf all goes well, you should see.

Code: [Select]
Mounting
Unmounting
Cleaning up
Anything else, leave me a comment and I'll help troubleshoot.


3. Connecting
Ok! That's it.  Now, put the SD card into the rp0w and fire it up.  The green light should begin flashing. 

The last tricky part is knowing what IP address has been assigned to the rp0w on boot.  After waiting a few minutes for it to connect to the wifi, visit your router's admin page.  It's usually 192.168.1.1.  You'll need the router login information.  But once in there should ba a section like "Attached Devices".  In there you should see an entry for "alarm" (which stands for Arch Linux ARM).  This your rp0w. 

Now, at the command line type:
Code: [Select]
ssh alarm@192.168.1.xxxWhere the xxx is the address assigned to the Pi.  You should be prompted with an EDSCA warning (say yes).  Then, you will need to enter the password which is alarm.

Happy Arching.
« Last Edit: April 02, 2018, 09:59:43 AM by Ladvien »

 

* Search


* Recent Topics

Meowth Abandoned by Nemesis
[April 11, 2019, 11:08:00 AM]


Bench Power: Help a rebel out by jinx
[April 03, 2019, 04:20:10 AM]


Just a short intro... by MEgg
[March 18, 2019, 05:49:28 PM]


MKS GEN L Servo Issue by cmptrguy1
[March 14, 2019, 01:18:28 AM]


Yes I am alive! by jinx
[March 10, 2019, 04:38:53 AM]


CZ-1 2.0: problems, calibration and printing, part2 by MEgg
[February 26, 2019, 03:35:15 PM]


Hi, Mushroom glue here. by nschreiber0813
[February 25, 2019, 02:09:13 PM]


Arduino IK by BaldwinK
[February 25, 2019, 05:54:44 AM]


Raspberry Pi / Python eBook - free for the next 11 hours! by MEgg
[February 24, 2019, 09:49:43 AM]


MKS Gen L 1.0 by MasterDomino
[February 24, 2019, 06:34:24 AM]


Fun Fact by Impala
[February 13, 2019, 11:05:01 PM]


Animabot Rev3 - Advanced Hexapod Robot by Smashley
[February 05, 2019, 03:41:50 PM]


Finally tried out a Chinese PCB service by Bajdi
[February 02, 2019, 08:40:49 AM]


PLX-DAQ by BaldwinK
[January 16, 2019, 06:44:18 AM]


Four Motor Leg Module by BaldwinK
[January 09, 2019, 04:55:14 PM]

* Recent Posts

Re: Meowth Abandoned by Nemesis
[April 11, 2019, 11:08:00 AM]


Meowth Abandoned by BaldwinK
[April 10, 2019, 06:35:48 AM]


Re: Bench Power: Help a rebel out by jinx
[April 03, 2019, 04:20:10 AM]


Bench Power: Help a rebel out by ZeroMax
[March 27, 2019, 10:00:53 PM]


Re: Just a short intro... by MEgg
[March 18, 2019, 05:49:28 PM]


Re: Just a short intro... by Killer Angel
[March 18, 2019, 06:55:35 AM]


Re: Just a short intro... by jinx
[March 16, 2019, 04:36:13 AM]


Re: Just a short intro... by Bajdi
[March 15, 2019, 04:22:09 PM]


Just a short intro... by cybersamurai
[March 15, 2019, 04:19:22 PM]


Re: MKS GEN L Servo Issue by cmptrguy1
[March 14, 2019, 01:18:28 AM]


Re: Yes I am alive! by jinx
[March 10, 2019, 04:38:53 AM]


Re: Yes I am alive! by nschreiber0813
[March 09, 2019, 03:59:04 PM]


Re: CZ-1 2.0: problems, calibration and printing, part2 by MEgg
[February 26, 2019, 03:35:15 PM]


Re: Hi, Mushroom glue here. by nschreiber0813
[February 25, 2019, 02:09:13 PM]


Yes I am alive! by nschreiber0813
[February 25, 2019, 02:08:12 PM]