Formatting USB keys and Floppy Drives



I've been tasked with building a floppy disk and USB flash drive formatter. I'm using a raspberry pi with a USB floppy drive connected. The device will be headless. My co-worker is writing the python required to interact with the GPIO pins on the board but I'm in charge of the bash script that will perform the formatting.
Here's what I need to know:
How do I format a USB drive that is plugged into a specific USB port? I don't think I want to rely on sda or sdb, I want to direct the command specifically to the USB port. Is this possible?

The floppy drive is a USB drive. It shows up as /dev/sdc... can I use the same method for this drive?

Also, the machine will be completely headless so I'm going to use the GPIO pins to light up a green LED when the format is complete. Does the format command return a value that I can use to trigger this?



This will give you the most recently added disk to the /dev direcory. So you could use it immediately after plugging in the device.
DEVICE=$(ls -t /dev/sd* | head -n1)

But if you have information about the specific device, you could be even more certain by using the /dev/disk directory. It has four subdirectories with symlinks to the real device name. e.g.:
/dev/disk/by-uuid/b99f0425-e58d-45df-668f-8f2334690f08 -> /dev/sdb1
$100 Digital Ocean Credit
Get a free VM to test out Linux! Hosting Donations
Consider making a donation

Members online