Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I find that in order to re-mount a USB stick, I have to physically disconnect it, and then re-connect it. How can I do this without such tiring physical action?

share|improve this question
2  
The USB device is logically disconnected (there should be a message to that effect your kernel logs). It won't have a /dev entry any more, and IIRC won't show up in lsusb either. I don't know if there's a way to reconnect it. –  Gilles Feb 9 '11 at 22:49

2 Answers 2

up vote 5 down vote accepted

From my experience in Ubuntu, when you "eject" a USB stick from within Nautilus, the device actually disappears from the system. I'm not sure why this is, but neither Nautilus nor the command line can get it back. I guess the logic is that once you eject a USB stick you don't want it back, but are going to disconnect it.

The way I work around this (when needed), is by using umount instead of Nautilus. You could also just call sync to flush the filesystem buffers to the disk.

Just found a thread which has more info : http://ubuntuforums.org/showthread.php?t=1477247

So basically either a) Rebuild nautilus from source without that patch (and keep it up to date when you update your system...) or b) use another file manager (at least when unmounting ^^).

share|improve this answer
2  
Check /dev/disk/by-id and see if the device is truly gone. I'll bet it's not, and can be remounted from there with a mount command. –  ultrasawblade Feb 9 '11 at 22:55
1  
@ultrasawblade /dev/disk/by-id contains symlinks to device files in /dev, for example /dev/disk/by-id/usb-Kingston_DT_100_G2_001CC0C60DBDFC90D32923CE-0:0 -> ../../sdb. When the device is gone after udisks --eject (which I assume happens here), the symlink is stale and cannot be used for re-mounting. –  PointedEars Jan 30 at 10:58

This is the behavior I have on my Ubuntu Lucid system:

When I plug in my USB flash/thumbdrive which has two partitions, the system reports:

$ ls /dev/sdb*
/dev/sdb  /dev/sdb1  /dev/sdb2

$ udisks --show-info /dev/sdb | grep -A2 'partition table\|by-id'
    by-id:                     /dev/disk/by-id/usb-takeMS_USB_Mini_AA07013000010057-0:0
    by-path:                   /dev/disk/by-path/pci-0000:00:1d.7-usb-0:2:1.0-scsi-0:0:0:0
  detected at:                 Mon 29 Apr 2013 02:16:50 PM CEST
--
  partition table:
    scheme:                    mbr
    count:                     2

$ udisks --show-info /dev/sdb1 | grep -A2 'partition table\|by-id'
    by-id:                     /dev/disk/by-id/usb-takeMS_USB_Mini_AA07013000010057-0:0-part1
    by-id:                     /dev/disk/by-uuid/581E-EE0B
    by-path:                   /dev/disk/by-path/pci-0000:00:1d.7-usb-0:2:1.0-scsi-0:0:0:0-part1
  detected at:                 Mon 29 Apr 2013 04:24:25 PM CEST

$ udisks --show-info /dev/sdb2 | grep -A2 'partition table\|by-id'
    by-id:                     /dev/disk/by-id/usb-takeMS_USB_Mini_AA07013000010057-0:0-part2
    by-id:                     /dev/disk/by-uuid/4A0E-A166
    by-path:                   /dev/disk/by-path/pci-0000:00:1d.7-usb-0:2:1.0-scsi-0:0:0:0-part2
  detected at:                 Mon 29 Apr 2013 04:24:25 PM CEST

$ udevadm info --query=all --name=/dev/sdb | grep DEVPATH
E: DEVPATH=/devices/pci0000:00/0000:00:1d.7/usb1/1-2/1-2:1.0/host13/target13:0:0/13:0:0:0/block/sdb    
$ udevadm info --query=all --name=/dev/sdb1 | grep DEVPATH
E: DEVPATH=/devices/pci0000:00/0000:00:1d.7/usb1/1-2/1-2:1.0/host13/target13:0:0/13:0:0:0/block/sdb/sdb1
$ udevadm info --query=all --name=/dev/sdb2 | grep DEVPATH
E: DEVPATH=/devices/pci0000:00/0000:00:1d.7/usb1/1-2/1-2:1.0/host13/target13:0:0/13:0:0:0/block/sdb/sdb2
$ sudo partprobe /dev/sdb
$

So, only partitions have /dev/disk/by-uuid; while both disk and partitions have (different) /dev/disk/by-id.

Now, if I left-click on either of the partition entries in the Disk Mounter applet in the Gnome2 desktop in Lucid, I get only two entries: "Open" or "Eject" (as mentioned in the [SOLVED] How do you remount a usb drive with nautilus in lynx?, from @Thomas' answer, referring to a 16_hide_unmount.patch). Also, palimpsest here shows two partitions for the disk.

When I click on the Eject on either one of the partitions - they both dissapear; at this point, palimpsest shows the disk, but no partitions, and a "No medium found" message instead; also:

$ ls /dev/sdb*
/dev/sdb

$ udisks --show-info /dev/sdb | grep -A2 'partition table\|by-id'
    by-id:                     /dev/disk/by-id/usb-takeMS_USB_Mini_AA07013000010057-0:0
    by-path:                   /dev/disk/by-path/pci-0000:00:1d.7-usb-0:2:1.0-scsi-0:0:0:0
  detected at:                 Mon 29 Apr 2013 02:16:50 PM CEST

$ udisks --show-info /dev/sdb1 | grep -A2 'partition table\|by-id'
$

$ udevadm info --query=all --name=/dev/sdb | grep DEVPATH
E: DEVPATH=/devices/pci0000:00/0000:00:1d.7/usb1/1-2/1-2:1.0/host13/target13:0:0/13:0:0:0/block/sdb
$ udevadm info --query=all --name=/dev/sdb1 | grep DEVPATH
device node not found

$ sudo partprobe /dev/sdb
Error: Error opening /dev/sdb: No medium found

So, as mentioned in comment by @ultrasawblade, indeed the disk is there, but not the partitions - although, I think I'd need the partitions as devices, in order to mount.

Also, the same behavior as left-click+"Eject" in desktop GUI, I can get in terminal with sudo eject /dev/sdb. Note that one can also open palimpsest, from there click on each of the two partitions, and click "Unmount Volume" - at that point, the icons for the partitions will still be shown in Disk Mounter applet, but will be noted as unmounted; and then one can do sudo udisks --detach /dev/sdb: this makes the icons disappear from Disk Mounter applet - but also the /dev/sdb device will not be present on the system anymore (however, lsusb will still show the device)!

After searching quite a bit for the answer (tried stuff from udevadm monitor --environment during plug and unplug, with replicating all actions via udevadm trigger, to looking into what the BLKRRPART ioctl does), without any success - I finally stumbled upon How To Remount A USB Stick Without Removing And Reinserting - Ubuntu/Debian, which has the answer:

sudo eject -t /dev/sdb

After this command is ran - the two partitions appear again in Disk Mounter applet - without unplugging/re-plugging the USB key!! This is all the stranger, because if you read man eject:

   -t   With  this  option the drive is given a CD-ROM tray close command.
        Not all devices support this command.

... you'd never expect it's applicable to USB Flash/Thumb drive! (And I even tried looking into sys-utils/eject.c, and I cannot see anything obvious :) )

Of course, if sudo udisks --detach /dev/sdb has been ran previously, then /dev/sdb won't exist, so eject -t /dev/sdb will fail with eject: unable to find or open device for: '/dev/sdb'. In that case, the USB power cycle as noted in #7457 How to reconnect a logically disconnected USB device? helped me recover:

$ sudo sh -c 'echo suspend > /sys/bus/usb/devices/1-2/power/level'
$ sudo sh -c 'echo auto > /sys/bus/usb/devices/1-2/power/level'

This made the partitions' icons show again in Disk Mounter applet, directly as mounted; to find the right address, try while the disk is mounted:

$ udevadm info --attribute-walk --name=/dev/sdb | grep "looking\|busnum\|devnum" | grep -B1 'busnum\|devnum'
  looking at parent device '/devices/pci0000:00/0000:00:1d.7/usb1/1-2':
    ATTRS{busnum}=="1"
    ATTRS{devnum}=="13"
  looking at parent device '/devices/pci0000:00/0000:00:1d.7/usb1':
    ATTRS{busnum}=="1"
    ATTRS{devnum}=="1"

# the first (.../usb1/1-2) should be the right one, check bus/devnum:
$ lsusb -s 1:13
Bus 001 Device 013: ID 090c:1000 Feiya Technology Corp. Flash Drive

# looks good; check for symlinks in `sys/bus/usb/devices` as per "parent device" .../usb1/1-2
$ ls -la /sys/bus/usb/devices/ | grep "usb1/1-2"
lrwxrwxrwx 1 root root 0 2013-04-29 17:17 1-2 -> ../../../devices/pci0000:00/0000:00:1d.7/usb1/1-2
lrwxrwxrwx 1 root root 0 2013-04-29 17:21 1-2:1.0 -> ../../../devices/pci0000:00/0000:00:1d.7/usb1/1-2/1-2:1.0

# so it should be /sys/bus/usb/devices/1-2; check if it has power/level:
$ ls /sys/bus/usb/devices/1-2/power/level 
/sys/bus/usb/devices/1-2/power/level

Well, hope this helps someone,
Cheers!

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.