Community discussions

MikroTik App
 
jack14
just joined
Topic Author
Posts: 11
Joined: Thu Oct 10, 2019 12:26 pm

RB5009, RouterOS 7.9.1, USB slot keeps changing

Mon Jun 05, 2023 2:13 pm

Hi,
I have a problem with my brand new RB5009. I have a USB 3 flash drive plugged in it, but every time I reboot the RB, the slot name changes from usb1 to usb2 and vice versa. Also, the interface keeps changing between USB 2 and USB 3.
I tried to manually rename the slot with a custom name, format the USB key from the router and also from a PC, tried fat32 and ext4, but with no luck.
What can I do to retain the slot name?
 
jack14
just joined
Topic Author
Posts: 11
Joined: Thu Oct 10, 2019 12:26 pm

Re: RB5009, RouterOS 7.9.1, USB slot keeps changing

Thu Jun 08, 2023 12:50 pm

Just an update: I tried different USB sticks (USB2 and USB3) and the problem didn't show anymore even after multiple reboots. Maybe there was something wrong with the first USB3 stick that avoid ROS to correctly detect the interface speed, thus resulting in renaming slot.
 
intania
just joined
Posts: 2
Joined: Mon Jul 31, 2023 8:41 am

Re: RB5009, RouterOS 7.9.1, USB slot keeps changing

Wed Aug 16, 2023 6:57 am

I got the same problem with Sandisk flash drive. Slot keeps changing from usb1 and usb2 when reboot.
I will try different brand later to see if the problem is still there.
 
alimnette
just joined
Posts: 1
Joined: Wed Sep 06, 2023 12:51 pm

Re: RB5009, RouterOS 7.9.1, USB slot keeps changing

Wed Sep 06, 2023 12:55 pm

hello,

i have a same issue
my version is 7.11
Last edited by alimnette on Wed Sep 06, 2023 12:58 pm, edited 1 time in total.
 
cwm9
just joined
Posts: 18
Joined: Sun Mar 12, 2023 7:35 pm

Re: RB5009, RouterOS 7.9.1, USB slot keeps changing

Thu Sep 28, 2023 8:53 am

I believe this only happens with USB3 capable thumb drives.

As far as I can tell this is what's happening: Router OS is assigning a drive slot name to each USB device reported by the xhci-hcd driver. xhci-hcd reports two USB devices for each physical USB port (/system/resource/usb):
  • "Device: 1-0", a "USB Version: 2.0" device with "speed: 480"
    • Assigned the USB interface name "USB 2.10 480Mbps"
    • Assigned the disk slot name "usb2")
  • "Device: 2-0", a "USB Version: 3.0" device with "speed: 5000"
    • Assigned the USB interface name "USB 3.00 5000Mbps"
    • Assigned the disk slot name "usb1")
When a thumb drive is DETECTED as USB 3, it appears on the xhci-hcd USB 3 interface and the drive's partition is mounted to "/usb1" (the disk slot assigned to that device); likewise, when the drive is DETECTED as USB 2, it appears on the xhci-hcd USB 2 interface and the drive's partition is mounted to "/usb2" (the disk slot assigned to that device).

The problem appears to be that USB3 thumb drives are alternately recognized as either USB2 or USB3, changing state (almost) every reboot cycle. Possible causes for this include not cycling the USB's power during the reboot (or having too short a cycle) so that the thumb drive is in an state unanticipated by the driver (e.g., thumb drive is already enabled and ready to run as a drive, but driver queries the capabilities of the thumb drive as if it were already reset), insufficient delay after a reboot before identifying the device, or a software bug in the driver code. Since the problem seems generally to flip once per reboot, I tend to think it is either a hardware state problem or a driver software bug rather than a hardware defect.

This means the problem is actually two-fold: your partition is mounted at the wrong location AND your USB 3.0 drive is running at USB 2.1 speeds.

The fix is fairly simple: if the device was incorrectly detected, reboot the router.

Add this /system/scheduler script as "Reboot_if_USB3_detected_as_USB2" and schedule it to run when the router boots. It simply detects if the drive has been incorrectly identified as a USB 2.1 device and, if so, logs an errors, waits 60 seconds, and then reboots the router. It attempts to do this no more than 5 times and then gives up. Remember, you can't stop a running script once it starts, so don't remove the delay: if a change to this script or to the router firmware causes this script to reboot every time and there is no delay, you will have effectively bricked your machine and will need to do a NetInstall! Be VERY careful modifying this script...

Also, check the code for yourself, as I am NEW to Mikrotik Scripting. This is literally my second script!
#log as an error because auto rebooting after we just booted can be pretty confusing and a pretty big deal.
:log error "Waiting 20 seconds before testing for USB3 recognized as USB2 and possibly rebooting... (not an error)"
:delay 20s

:log error "Testing for USB3 recognized as USB2 (not an error)"
:local attempts 0

# Check if the file exists and read the attempts
:if ([/file find name="USB_Fix_Attempts"] != "") do={
  :set attempts [/file get [find name="USB_Fix_Attempts"] contents]
} else {
  # Create the file if it doesn't exist and set initial value to 0
  /file add name="USB_Fix_Attempts" contents="0"
}
:if ($attempts < 5) do={
  :foreach disk in=[/disk find] do={
    :if (([:pick [/disk get $disk interface] 0 5] = "USB 2") && [:len [/disk get $disk model]] > 0 && [:len [/disk get $disk serial]] > 0) do={
      :log error ("USB3 Drive incorrectly recognized as USB2, have attempted " . $attempts)
      :log error ("times to reboot so far; rebooting in 60 seconds!")
      :log error ("Disable the /system/scheduler entry Reboot_if_USB3_detected_as_USB2 to prevent more reboots!")

      :set attempts ($attempts + 1)
      # Update the file with the new attempts count
      /file set USB_Fix_Attempts contents=$attempts

      :delay 60s
      :log error ("Rebooting")
      /system reboot
      :error "USB3 device incorrectly recognized as USB2, rebooting now."
    } 
  }
  # Success! It might be messed up again next time, so reset counter to repeat the process.
  :log error "Everything looks good, no reboot required."
} else {
  :log error "Ran out of attempts (5) trying to fix USB 3 seen as USB 2... maybe it really is USB 2?  Booting anyway...."
}
# We're keeping this boot.  No matter what, test again next time.
:set attempts 0
/file set USB_Fix_Attempts contents=$attempts


Last edited by cwm9 on Thu Sep 28, 2023 10:26 am, edited 2 times in total.
 
holvoetn
Forum Guru
Forum Guru
Posts: 6637
Joined: Tue Apr 13, 2021 2:14 am
Location: Belgium

Re: RB5009, RouterOS 7.9.1, USB slot keeps changing

Thu Sep 28, 2023 9:19 am

Correlates more or less with my findings.
Yesterday morning I created a support ticket for it, clearly indicating the observation of USB3/USB2 toggle after reboots.
No response yet.

Personally I wouldn't schedule such a script.
But nicely crafted ! Didn't test, though :lol:
 
holvoetn
Forum Guru
Forum Guru
Posts: 6637
Joined: Tue Apr 13, 2021 2:14 am
Location: Belgium

Re: RB5009, RouterOS 7.9.1, USB slot keeps changing

Thu Sep 28, 2023 10:55 am

Idea:

wouldn't USB Power reset be a better approach for your script ?
https://wiki.mikrotik.com/wiki/Manual:USB_Features
 
cwm9
just joined
Posts: 18
Joined: Sun Mar 12, 2023 7:35 pm

Re: RB5009, RouterOS 7.9.1, USB slot keeps changing

Fri Sep 29, 2023 1:56 am

Wouldn't USB Power reset be a better approach for your script ?
https://wiki.mikrotik.com/wiki/Manual:USB_Features
The problem is that some features, such as containers, run on startup and rely on having the USB drive present and properly mounted. They will fail to start if the USB is mounted in the wrong slot.

If you want to identify each script/container that relies on the USB to be present and rerun/restart them after you reset the USB and verify it comes back correctly, then sure, you could use the USB reset feature instead.

Also, there is another bug in RouterOS: when you reset the USB, the drive moves to the new slot, but the old slot continues to show up in /disk as if it was still mounted. I doubt this would harm anything, as the drive shows up correctly remounted in a "/file print", and very few things (my script!) rely on what /disk reports. It appears to just be a UI bug in (terminal) /disk and (winbox) /system/disks.
 
kusterh
just joined
Posts: 20
Joined: Sun Dec 31, 2023 10:39 am

Re: RB5009, RouterOS 7.9.1, USB slot keeps changing

Sun Dec 31, 2023 10:44 am

I'm suffering from the same problem, using a Sandisk ultrafit USB3 drive on my RB5009 router, is there perhaps a real fix for this in the meantime ?
I'm very reluctant to put an 'auto-reboot' script on my router, so now I'm faced with half of the reboots of my router resulting in a non-working system due to usb-drive not being mounted on the right path.
 
holvoetn
Forum Guru
Forum Guru
Posts: 6637
Joined: Tue Apr 13, 2021 2:14 am
Location: Belgium

Re: RB5009, RouterOS 7.9.1, USB slot keeps changing

Sun Dec 31, 2023 2:27 pm

Not 100% sure but for me it seems to be fixed since 7.13
 
kusterh
just joined
Posts: 20
Joined: Sun Dec 31, 2023 10:39 am

Re: RB5009, RouterOS 7.9.1, USB slot keeps changing

Wed Jan 03, 2024 8:22 am

Can you indicate which usb drive you're using?
Maybe the issue is related to the SanDisk ultrafit drive that I'm using.
I've installed 7.13 ros and firmware on all my devices and still see the issue.
 
RealQuaker
just joined
Posts: 6
Joined: Sat Nov 04, 2023 2:15 am
Location: Ukraine

Re: RB5009, RouterOS 7.9.1, USB slot keeps changing

Fri Jan 19, 2024 11:27 pm

I can confirm it is still flapping after reboot.
Tested on hAP ax3 with ROS 7.13.2 today.
 
kusterh
just joined
Posts: 20
Joined: Sun Dec 31, 2023 10:39 am

Re: RB5009, RouterOS 7.9.1, USB slot keeps changing

Sat Jan 20, 2024 9:52 am

I just bought another usb drive (Kingston) and this one doesn't switch anymore between usb1/usb2, so in my case it seems to be related to my previos usb-disk from Sandisk.
 
4L3xN3t
newbie
Posts: 25
Joined: Mon Feb 07, 2022 3:11 pm

Re: RB5009, RouterOS 7.9.1, USB slot keeps changing

Tue Jan 23, 2024 12:13 pm

it's 3days I'm struggling to understand why randomly the container didn't boot...and I have exactly a SanDisk UltraFit with the same exact behaviour.
I'm going to test the script (and maybe buying another usb stick!)

UPDATE: just to help...the Kingston DataTraveler Micro works perfectly
 
atillaeyice
just joined
Posts: 8
Joined: Mon Oct 31, 2016 8:57 pm

Re: RB5009, RouterOS 7.9.1, USB slot keeps changing

Thu Apr 18, 2024 8:16 am

I have the same issue with the Sandisk. however, USB power reset fixes it so If you use containers run this at startup then its should fix it.

:delay delay-time=5s
:local containerStatus [/container get 0 value-name=status]
:log warning message=$containerStatus
:if ($containerStatus = "stopped") do={
:system routerboard usb power-reset duration=1s
:delay delay-time=3s
:container start number=0
:log warning message="starting container."
}

Who is online

Users browsing this forum: andydz, BillyVan, druidgtx, Guscht, infabo, jhbarrantes, pantelinoux, Renfrew, wispmikrotik and 117 guests