Hypriots Flash CLI Tool

Today I stumbled upon Hypriot's Flash CLI Tool to simplify flashing SD cards and especially Raspberry Pi's

What are we doing today

Today we will flash a Raspberry Pi Zero with Hypriot OS using Hypriot's Flash CLI

Get the CLI Tool

Get the flash binary, apply executable permissions and move it into your current path:

$ curl -O https://raw.githubusercontent.com/hypriot/flash/2.3.0/flash
$ chmod +x flash
$ sudo mv flash /usr/local/bin/flash

Get the Hypriot OS

Download the latest image from their Github Repo:

$ wget https://github.com/hypriot/image-builder-rpi/releases/download/v1.10.0/hypriotos-rpi-v1.10.0.img.zip
$ unzip hypriotos-rpi-v1.10.0.img.zip

Cloud Init Config

We will use a cloud-init config to bootstrap the provisioning process:

#cloud-config

hostname: docker-zero  
manage_etc_hosts: true  
apt_preserve_sources_list: true

users:  
  - name: pirate
    primary-group: users
    shell: /bin/bash
    sudo: ALL=(ALL) NOPASSWD:ALL
    groups: users,docker,adm,dialout,audio,plugdev,netdev,video
    ssh-import-id: None
    lock_passwd: true
    ssh-authorized-keys:
      - ssh-rsa AxxxxZ

package_upgrade: false

write_files:  
  - content: |
      allow-hotplug wlan0
      iface wlan0 inet dhcp
      wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
      iface default inet dhcp
    path: /etc/network/interfaces.d/wlan0
  - content: |
      country=de
      ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
      update_config=1
      network={
      ssid="xx"
      psk="xx"
      proto=RSN
      key_mgmt=WPA-PSK
      pairwise=CCMP
      auth_alg=OPEN
      }
    path: /etc/wpa_supplicant/wpa_supplicant.conf

# These commands will be ran once on first boot only
runcmd:  
  - 'systemctl restart avahi-daemon'
  - 'ifup wlan0'
  - 'sleep 10'
  - 'docker swarm init'

Flash Time

It's time to flash our sd card, first we need to detect the block device that we want to flash, if you are using linux you can use lsblk and on mac you can use diskutil list

Flash the device by passing the device name, cloud-init config and the hypriot os image:

$ flash --device /dev/disk2s2 --userdata config.yml ~/Downloads/hypriotos-rpi-v1.10.0.img

Is /dev/disk2s2 correct? y  
Unmounting /dev/disk2s2 ...  
Unmount of all volumes on disk2 was successful  
Flashing /Users/ruan/Downloads/hypriotos-rpi-v1.10.0.img to /dev/rdisk2s2 ...  
Password:  
1000+0 records in  
1000+0 records out  
1048576000 bytes transferred in 190.988041 secs (5490270 bytes/sec)  
Mounting Disk