Other Testing for presence of USB device

At most you'd be able to test(1) for the existence of the device file. But you need to know the device in advance. [ -c /dev/da0] for example. And the "USB device" needs to create a /dev/ device node, certainly not all "USB devices" do. Are you testing for a specific type of USB device? If it's any random type of "USB device" then usbconfig(8) is your best bet.
 
I'm just trying to write something to a USB stick.

This seems to do what I want.

sh:
if ! usbconfig | grep 'DISK USB' ; then                                                                                                                                                                                                                                   
     echo 'no usb disk attached, please insert'                                                                                                                                                                                                                               
exit
 
I'm just trying to write something to a USB stick.
If it's just a flashdrive, you don't need to do it that complicated.

Either the drive already has a partition scheme, and at least one partition (mostly FAT32 with MBR), then you can see it under what gpart show produces: da0 or any other number instead 0, if there are more than one.
If not, if it's not completely defective, but somehow unformatted, corrupted, contains a partition (scheme) FreeBSD does not recognize (which was uncommon), it's at least recognized anyway. You'll see it either under dmesg.
Or switch to TTY1 [CTRL]+[ALT]+[F1] (F9 is by default where the GUI lives [just for the case you don't know how to 'come back'😁]) and plug it in (or out.) The system produces some message lines telling you all you need to find the correct device.
Then simply mount it, or create a partition on it first.
Then write to it.
(Unmount it before you unplug it.)


:-/ To mee it seems you were way more efficient (quicker) when you simply stop asking AI for everything, and then again asking here in the forums for filling the gaps, still missing understanding, but instead simply try to learn some things the "traditional way", e.g. read the handbook. 🥸
I'm pretty sure you already read way more text AI and the forums produced compared to what was to read in the HB for the same things; and you had way more experience by now that way... 🧐🤓
 
I have come across many USB sticks which are not partitioned so gpart is not a great way of checking for their presence.
 
which are not partitioned so gpart is not a great way of checking for their presence.
No. Of course not.
gpart only detects existing partitions. That's why I started with "Either the drive already has a partition [...], then you can see it under what gpart show produces"
But the system recognizes if there is a device at all anyway - as described several ways from others (and me) above - if the drive ain't completely toast, or something very exotic.

Once you know (for sure) it's for example /dev/da4 you can address it, and use gpart to create first a partition scheme, then partition(s), then mount it, then write to it, and finally umount it.
 
Back
Top