Care and feeding of the USB gadget
There are a few more things you may want to do once you’ve got the Pi installed.
Shutting down the Pi
To turn off the Pi, you want to do a clean shutdown. You could just unplug it, but that risks corrupting the SD card. Open the SSH client (Termius), add a New Host (usbgadget.local), and log in as pi
with the password silverseams
. Type ./cleanstop
(tip: you can type ./c
and then tab will finish typing it for you). and press enter.
It’ll give you a quick warning and boot you out of the session. After a second or so, the little green light will stop blinking and you can unplug the Pi safely. Plugging it back in will turn it on, and it will restart everything and be ready to serve files again.
You can use ./cleanstop
whenever Pi instructions tell you to sudo shutdown now
or something similar – cleanstop ends with a shutdown
, but also shuts the USB emulation down in a smoother order first. You should probably be fine with the default command, but cleanstop plays it safe. sudo shutdown -r
is a restart, so if you use cleanstop instead you’ll need to power your Pi off and back on to get it to do the restart part.
Changing the password
This is super-easy: just open Termius, log in as pi
, and type passwd
. It’ll prompt you for your old password and a new password (twice). Record the new one in your password manager (1Password, Lastpass, etc.)
Level up: Maybe you have an ssh key you’d like to use?
nano .ssh/authorized_keys
and put your public key in. Ctrl-X, Y, enter. Next time you log in, it’ll ask for your ssh passphrase instead of your password.
Changing the hostname
If you want your Pi to be named something other than usbgadget
(for instance, if you have more than one on the same network), there are three places you’ll need to change it. You can edit it by mounting the SD card on your PC like you did to give it your wifi password, in which case these files are all in the rootfs partition, or you can log in with Termius and edit it with the Pi running, using sudo nano
.
- /etc/hosts
- /etc/hostname
- /etc/avahi/avahi-daemon.conf
Each of these will have usbgadget
in one place. Make sure you’re picking a valid hostname. If you’re editing it on the Pi, do a ./cleanstop
to shut it down, then restart it so the new name takes effect. (It may express some confusion about its identity while shutting down, but it should recover.)
Backing up the Pi
If you have the space on your PC, you can take an image of your Pi. Then if something happens to corrupt it, you can just restore the image.
Restoring the image will completely overwrite everything on the card, so it will fix anything that happens to break in the meantime (though it will also wipe out any embroidery files you had on the virtual usb stick – never put your only copy on a usb of any kind!)
Changing the virtual USB stick’s size
TBA!
Securing Samba
Maybe you don’t want your Samba share to be visible to your whole network. Lock it down!
Fixing a corrupted usb_share
Sometimes despite the watchdog’s best efforts, two things try to write to the usb stick at the same time and things get confused. If you backed up your Pi you can just restore the image to fix it. It takes awhile, but it’s simple.
If you haven’t backed it up, or you’re a little more impatient/adventurous, you can just rebuild the virtual USB stick. Open up Termius, log in, and type:
1
./newusb
It will take awhile… don’t panic, and don’t interrupt it. When it finishes, it will kick you out of the SSH client, restart itself, and it should be all ready to go again. If this happens frequently, you should probably stop writing to the directory on your PC while the embroidery machine is using it!
More tricks
Despite its absurdly small size, the Pi is an entire little server, and playing USB stick is really not making it work too hard. You’ve got plenty of room to do other things with it.
- Install Pi-hole, and let it block ads for your entire network.
- Install Icecast, and stream music to your entire network.
- Install nginx, and have your own private web server.
- There are a lot more projects, though of course you are limited in that the Pi’s USB port is occupied, and being tethered to your embroidery machine will limit its usefulness in (other) robotics. But hey! Now that you have one going, why not get more?