Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Set up a Raspberry Pi Zero (with only a USB cable) via OS X
  1. Download the Raspbian Lite image from https://downloads.raspberrypi.org/raspbian_lite_latest (add .torrent to get a torrent)
  2. Unzip the download to extract the .img file
  3. Insert a FAT32-formatted SD card, and copy the image over:
    • diskutil list to identify the disk number, e.g. /dev/disk2
    • diskutil unmountDisk /dev/disk2
    • sudo dd bs=1m if=image.img of=/dev/rdisk2
  4. Before unmounting, edit a couple of files to activate internet-over-USB. The image mounted for me at /Volumes/boot.
    • In config.txt, add this as the last line of the file: dtoverlay=dwc2
    • In cmdline.txt, add this as a parameter, just after the rootwait parameter: modules-load=dwc2,g_ether
  5. Unmount the SD card (via Finder) and stick it in the Raspberry Pi.
  6. Attach a USB cable from your Mac to the RPi via the "USB" port on the RPi. This should power the RPi, and it will start to boot up.
  7. Give it a few minutes to boot. Open the Network preference panel (System Preferences -> Network) on your Mac, and you should see a new networking device called something like "RNDIS/Ethernet Gadget". For now it should be set to "Configure via DHCP" - it will have a link-local address.
  8. Once the RPi boots, you should be able to SSH to it with ssh pi@raspberrypi.local. The password is raspberry.
  9. Over SSH, edit /etc/network/interfaces to add a USB interface - add the following lines:
  allow-hotplug usb0
  iface usb0 inet static
      address 192.168.2.2
      netmask 255.255.255.0
      gateway 192.168.2.1
  1. Next, set up resolv.conf to use 192.168.2.1 for name resolution - edit /etc/resolvconf.conf, and uncomment/edit the nameservers line to read nameservers=192.168.2.1.
  2. Finally, on your Mac, configure the RNDIS/Ethernet Gadget interface with the following parameters: - Configure IPV4: Manually - IP Address: 192.168.2.1 - Subnet Mask: 255.255.255.0 - Router: (none) - Under Advanced -> DNS, add your favorite DNS server, like 8.8.8.8 or your home router.
  3. Under the "Sharing" preferences pane, turn on Internet Sharing, and share your Mac's active network connection with the RNDIS/Ethernet Gadget interface.
  4. Reboot the RPi. After it comes back up, you should still be able to connect via ssh pi@raspberrypi.local, and the device should now have the IP address 192.168.2.2 and access to the Internet!
@rricharz

This comment has been minimized.

Copy link

@rricharz rricharz commented Mar 26, 2017

Works nicely, except under step 4, create an empty file called ssh in the boot directory, because ssh is disabled in the newest Jessie image for safety reasons. This enables ssh.

@fronbasal

This comment has been minimized.

Copy link

@fronbasal fronbasal commented Dec 13, 2020

It's easier to just set up "sharing options" -> "internet sharing", it will auto-update the DNS and use the .local resolver, for example raspberrypi.local will then resolve to 192.168.2.2 in my case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment