🛠 Le tour de passe-passe « clé USB Linux » : Ethernet sur USB (g_ether)

Raspberry Pi Zero 2 W (2021) — Board Sheet · intermediaire · Schéma : IMG-zero-2w-intermediaire-2-ethernet-gadget-usb.svg — Zero 2 W branchée directement sur le port USB d'un ordinateur portable via son port données, interface réseau « Remote-ECM » apparaissant sur le portable, SSH par-dessus.

Objectives

Turn the Zero 2 W into "Linux on a USB stick": the data port is an OTG port, and the Zero line leaves the OTGID floating — without an SD card, the board actually boots in USB device mode. By loading the g_ether modules, the port presents itself as a USB network card. Result: one laptop, one data cable + one power cable, and direct SSH without a screen, keyboard, or router.

Hardware

Complete code

# 1) /boot/firmware/config.txt — activer le contrôleur USB en mode périphérique :
dtoverlay=dwc2

# 2) /boot/firmware/cmdline.txt — AJOUTER À LA FIN DE L'UNIQUE LIGNE du fichier :
modules-load=dwc2,g_ether

# 3) /etc/network/interfaces — IP statique côté gadget :
auto usb0
allow-hotplug usb0
iface usb0 inet static
    address 10.0.0.1
    netmask 255.255.255.0

# 4) Activer SSH :
sudo systemctl enable --now ssh

Then reboot, plug the data port into the laptop: ssh pi@10.0.0.1. On Linux/macOS, the laptop detects an "USB Ethernet" interface (you may need to enable connection sharing or set a static IP 10.0.0.2 on the laptop side).

Expected verification

The laptop detects a new USB network interface (on Linux: ip a shows a new usb0/enX interface). ping 10.0.0.1 responds and SSH works — without Wi-Fi or a screen. Bonus: with NO SD card, the Zero 2 W plugged into the PC enumerates a USB device 0a5c: — this is recovery mode (see the usbboot tutorial).

Common errors

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials