# Unmounting USB Causes Reboot.



## Leveret (Oct 11, 2022)

Does anyone know why a 13.1 ZFS system reboots or freezes whenever I unmount a usb camcorder? This happens in Dolphin on KDE5 or command line. Is there anyone who has experienced this? I can unmount usb drives in Dolphin as long as no window is accessing the drive. I can also unmount usb drives from command line easily. The problem with sudden reboots or freezes only occur with the camcorder.


----------



## T-Daemon (Oct 11, 2022)

Leveret said:


> I can unmount usb drives in Dolphin as long as no window is accessing the drive. I can also unmount usb drives from command line easily.


How is the file system of the memory disk of the camcorder mounted, automatic or manual? And what file system has the memory disk?


----------



## ralphbsz (Oct 11, 2022)

Console messages? Crash or reboot?


----------



## Leveret (Oct 11, 2022)

T-Daemon said:


> How is the file system of the memory disk of the camcorder mounted, automatic or manual? And what file system has the memory disk?


It is mounted manually. I see it listed in Kubuntu's KDE Partition Manager as Five Star Gadget.


----------



## Leveret (Oct 12, 2022)

Actually it is mounted by bsdisks automatically. It appears to be msdos file system on the disk. From what I read Five Star Gadget posts mentioned Android.


----------



## T-Daemon (Oct 12, 2022)

When the system froze, did you tried to change into a virtual console (i.e. Ctrl + Alt + F5)? Or tried from a second system to ssh(1).

As ralphbsz suggested, check if there are messages regarding the reboots or freeze. Open a xterminal, execute `less  /var/log/messages` and scroll through the messages.

Look if there are multiple files stored in /var/crash.



Leveret said:


> I see it listed in Kubuntu's KDE Partition Manager as *Five Star Gadget*.





Leveret said:


> *Five Star Gadget* posts mentioned Android


I don't use KDE,  what is a "Five Star Gadget". A web search doesn't return anything.

For the problem, if you didn't find something conclusive in /var/log/messages, please open a xterminal in KDE, execute following command before plugging in the camcorder:

`tail -f /var/log/messages`

Press the Enter key a few times to create space for following messages. Plug in the camcorder, copy and post the printed messages.

Execute Ctrl + C to terminate tail(1).

Execute `mount`, copy and post the printed information.

Don't umount(8) the camcorder, not from Dolphin or command line, power off the system, then plug it out.


----------



## Leveret (Oct 13, 2022)

T-Daemon said:


> When the system froze, did you tried to change into a virtual console (i.e. Ctrl + Alt + F5)? Or tried from a second system to ssh(1).
> 
> As ralphbsz suggested, check if there are messages regarding the reboots or freeze. Open a xterminal, execute `less  /var/log/messages` and scroll through the messages.
> 
> ...


Sorry T-Daemon, I mistyped: It is actually File-Stor Gadget.  Tiny print on the screen was difficult to read. Also, my keyboard was unresponsive when the system froze.
This is what I got using your instructions:

Oct 12 19:11:45 myfreebsd ntpd[958]: corporation.  Support and training for ntp-4 are
Oct 12 19:11:45 myfreebsd ntpd[958]: available at https://www.nwtime.org/support
Oct 12 19:11:45 myfreebsd ntpd[958]: ----------------------------------------------------
Oct 12 19:11:45 myfreebsd ntpd[959]: leapsecond file ('/var/db/ntpd.leap-seconds.list'): good hash signature
Oct 12 19:11:45 myfreebsd ntpd[959]: leapsecond file ('/var/db/ntpd.leap-seconds.list'): loaded, expire=2022-12-28T00:00:00Z last=2017-01-01T00:00:00Z ofs=37
Oct 12 19:11:46 myfreebsd ntpd[959]: error resolving pool 0.freebsd.pool.ntp.org: Name does not resolve (8)
Oct 12 19:12:30 myfreebsd dbus-daemon[898]: [system] Rejected send message, 2 matched rules; type="method_call", sender=":1.13" (uid=1001 pid=1122 comm="") interface="org.freedesktop.ConsoleKit.Manager" member="CanSuspendThenHibernate" error name="(unset)" requested_reply="0" destination="org.freedesktop.ConsoleKit" (uid=0 pid=1040 comm="")
Oct 12 19:12:31 myfreebsd pulseaudio[1144]: [(null)] oss-util.c: '/dev/dsp0' doesn't support full duplex
Oct 12 19:12:31 myfreebsd pulseaudio[1144]: [(null)] oss-util.c: '/dev/dsp3' doesn't support full duplex
Oct 12 19:12:53 myfreebsd ntpd[959]: error resolving pool 0.freebsd.pool.ntp.org: Name does not resolve (8)
Oct 12 19:13:48 myfreebsd kernel: usb_msc_auto_quirk: UQ_MSC_NO_GETMAXLUN set for USB mass storage device Android product 0x1002 (0x18d1:0x1002)
Oct 12 19:13:48 myfreebsd kernel: usb_msc_auto_quirk: UQ_MSC_NO_TEST_UNIT_READY set for USB mass storage device Android product 0x1002 (0x18d1:0x1002)
Oct 12 19:13:48 myfreebsd kernel: usb_msc_auto_quirk: UQ_MSC_NO_SYNC_CACHE set for USB mass storage device Android product 0x1002 (0x18d1:0x1002)
Oct 12 19:13:48 myfreebsd kernel: usb_msc_auto_quirk: UQ_MSC_NO_START_STOP set for USB mass storage device Android product 0x1002 (0x18d1:0x1002)
Oct 12 19:13:48 myfreebsd kernel: ugen0.3: <Android product 0x1002> at usbus0
Oct 12 19:13:48 myfreebsd kernel: umass0 on uhub8
Oct 12 19:13:48 myfreebsd kernel: umass0: <Mass Storage> on usbus0
Oct 12 19:13:48 myfreebsd kernel: umass0:  SCSI over Bulk-Only; quirks = 0x4105
Oct 12 19:13:48 myfreebsd kernel: umass0:6:0: Attached to scbus6
Oct 12 19:13:48 myfreebsd kernel: da0 at umass-sim0 bus 0 scbus6 target 0 lun 0
Oct 12 19:13:48 myfreebsd kernel: da0: <Linux File-Stor Gadget 0409> Removable Direct Access SCSI-2 device
Oct 12 19:13:48 myfreebsd kernel: da0: 40.000MB/s transfers
Oct 12 19:13:48 myfreebsd kernel: da0: Attempt to query device size failed: NOT READY, Medium not present
Oct 12 19:13:48 myfreebsd kernel: da0: quirks=0x2<NO_6_BYTE>
Oct 12 19:13:49 myfreebsd kernel: ugen0.3: <Android product 0x1002> at usbus0 (disconnected)
Oct 12 19:13:49 myfreebsd kernel: umass0: at uhub8, port 2, addr 2 (disconnected)
Oct 12 19:13:49 myfreebsd kernel: da0 at umass-sim0 bus 0 scbus6 target 0 lun 0
Oct 12 19:13:49 myfreebsd kernel: da0: <Linux File-Stor Gadget 0409>  detached
Oct 12 19:13:49 myfreebsd kernel: (da0:umass-sim0:0:0:0): Periph destroyed
Oct 12 19:13:49 myfreebsd kernel: umass0: detached
Oct 12 19:13:54 myfreebsd kernel: ugen0.3: <Android product 0x0002> at usbus0
Oct 12 19:13:54 myfreebsd webcamd[1190]: webcamd: Cannot find USB device
Oct 12 19:13:59 myfreebsd kernel: ugen0.3: <Android product 0x0002> at usbus0 (disconnected)
Oct 12 19:14:00 myfreebsd ntpd[959]: error resolving pool 0.freebsd.pool.ntp.org: Name does not resolve (8)
Oct 12 19:14:01 myfreebsd kernel: usb_msc_auto_quirk: UQ_MSC_NO_GETMAXLUN set for USB mass storage device Android product 0x100f (0x18d1:0x100f)
Oct 12 19:14:01 myfreebsd kernel: usb_msc_auto_quirk: UQ_MSC_NO_TEST_UNIT_READY set for USB mass storage device Android product 0x100f (0x18d1:0x100f)
Oct 12 19:14:01 myfreebsd kernel: ugen0.3: <Android product 0x100f> at usbus0
Oct 12 19:14:01 myfreebsd kernel: umass0 on uhub8
Oct 12 19:14:01 myfreebsd kernel: umass0: <Mass Storage> on usbus0
Oct 12 19:14:01 myfreebsd kernel: umass0:  SCSI over Bulk-Only; quirks = 0x0101
Oct 12 19:14:01 myfreebsd kernel: umass0:6:0: Attached to scbus6
Oct 12 19:14:01 myfreebsd kernel: da0 at umass-sim0 bus 0 scbus6 target 0 lun 0
Oct 12 19:14:01 myfreebsd kernel: da0: <Linux File-Stor Gadget 0409> Removable Direct Access SCSI-2 device
Oct 12 19:14:01 myfreebsd kernel: da0: 40.000MB/s transfers
Oct 12 19:14:01 myfreebsd kernel: da0: 30436MB (62333952 512 byte sectors)
Oct 12 19:14:01 myfreebsd kernel: da0: quirks=0x2<NO_6_BYTE>


----------



## T-Daemon (Oct 14, 2022)

What does the mount(8) command return after plugging in the camcorder?


----------



## ralphbsz (Oct 14, 2022)

Those messages from connecting the USB gadget look reasonable, except for the fact that it gets disconnected again within 1 second: Attached at 19:13:48. Then FreeBSD immediately finds out that "no medium is present", which means this USB storage device is unwilling or unable to read or write data. This leads to the device being immediately detached.

I see no crash, just a USB device that's unwilling to cooperate. Or maybe this is a protocol failure, where FreeBSD is too picky or communicates in a fashion that the device does not expect.  But the good news is that communications works, commands and messages are going back and forth to the device. The other good news is that there is no crash, just a clean detach.

Is there something that needs to be done on the device side to make it ready for IO?

If you connect the same camcorder to another computer and another OS (like Linux or Windows), does it work? If it works on Linux, can you look at all the debug messages you see there? Perhaps the device is partitioned, and speaking to /dev/da0 is a big mistake.


----------



## Leveret (Oct 15, 2022)

T-Daemon said:


> What does the mount(8) command return after plugging in the camcorder?


#ugen2.2: Android product 0x0002 at usbus2


ralphbsz said:


> Those messages from connecting the USB gadget look reasonable, except for the fact that it gets disconnected again within 1 second: Attached at 19:13:48. Then FreeBSD immediately finds out that "no medium is present", which means this USB storage device is unwilling or unable to read or write data. This leads to the device being immediately detached.
> 
> I see no crash, just a USB device that's unwilling to cooperate. Or maybe this is a protocol failure, where FreeBSD is too picky or communicates in a fashion that the device does not expect.  But the good news is that communications works, commands and messages are going back and forth to the device. The other good news is that there is no crash, just a clean detach.
> 
> ...


I don't use Windows. It works on Linux without issue. The memory card seems to be just one large partition.


----------



## ralphbsz (Oct 15, 2022)

If it works on Linux, the device is fundamentally functional, although perhaps not standard conforming. So perhaps the FreeBSD USB storage driver is just too picky (which is usually a good thing). It may be possible to work around this by setting USB quirks on FreeBSD, see usb_quirk(4), in particular the "no test unit ready" quirk. This may be a little bit difficult for a beginner.

Why do I suspect the "no test unit ready"? Because the device gets disconnected right after it says "no medium is present". This is one of the responses to the "test unit ready" command. In a nutshell, FreeBSD asks the device: "Are you ready?". The device responds with "No I am not, I don't have media". This response only makes sense for devices that have removable media, like flash card readers, floppy disks, or CDs. The quirk is a simply workaround: Simply don't ask the device whether it's ready, since it is going to lie about it anyway.


----------

