So there’s two main ways of “removing” a USB device. And which option is used depends on what file manager is used!
The first is a “soft eject”. This is what the eject
command does, and also appears to be what “pcmanfm” does. In this scenario, eject -t
will cause the partitions to reappear. This works because the device is still connected to the bus (and still shows in /dev/) and so the OS can control it.
The other is more “hard”. This is what udiskctl power-off
and Nautilus does. Here the device is effectively removed from the bus and so disappears from /dev/
(This example done on a Debian machine, but it should apply to Rocky8).
# /usr/bin/udisksctl power-off -b /dev/sdg
# dmesg | tail -1
[179677.977567] usb 1-2.2: USB disconnect, device number 10
We can see the kernel has reported the USB device has been disconnected. It no longer shows up in lsusb
as a result.
So how do we tell the OS the disk has been re-inserted?
That “usb 1-2.2” becomes important. This means USB bus 1-2, port 2.
We can use uhubctl to re-enabled it, by turning it off and on:
# /usr/sbin/uhubctl -l 1-2 -p 2 -a off
Current status for hub 1-2 [0bda:5411 Generic 4-Port USB 2.0 Hub, USB 2.10, 4 ports]
Port 2: 0101 power connect []
Sent power off request
New status for hub 1-2 [0bda:5411 Generic 4-Port USB 2.0 Hub, USB 2.10, 4 ports]
Port 2: 0000 off
# uhubctl -l 1-2 -p 2 -a on
Current status for hub 1-2 [0bda:5411 Generic 4-Port USB 2.0 Hub, USB 2.10, 4 ports]
Port 2: 0000 off
Sent power on request
New status for hub 1-2 [0bda:5411 Generic 4-Port USB 2.0 Hub, USB 2.10, 4 ports]
Port 2: 0101 power connect []
And it’s re-appeared again!
[179834.775058] usb 1-2.2: new high-speed USB device number 11 using ehci-pci
[179834.888056] usb 1-2.2: New USB device found, idVendor=0781, idProduct=5567, bcdDevice= 1.00
[179834.888063] usb 1-2.2: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[179834.888067] usb 1-2.2: Product: Cruzer Blade
[179834.888070] usb 1-2.2: Manufacturer: SanDisk
[179834.888074] usb 1-2.2: SerialNumber: 4C530000260115213093
(And the partitions mounted)
Note that not all hubs can be controlled this way.
uhubctl
is available in EPEL.
(Again, that was done on Debian, but it should work the same on RHEL).