topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Tuesday April 16, 2024, 7:00 pm
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: "Safely" Remove USB Devices in *N*X  (Read 4265 times)

ewemoa

  • Honorary Member
  • Joined in 2008
  • **
  • Posts: 2,922
    • View Profile
    • Donate to Member
"Safely" Remove USB Devices in *N*X
« on: June 09, 2012, 07:18 PM »
Recently I came across the "Safe Removal" feature in palimpsest (aka Gnome Disk Utility) and I've started using it before detaching some of my USB devices.  I'm not quite sure what it does, but LEDs seem to turn off so I get the sense that using the feature may be better than not.

I'd like to be able to do this or something comparable from the command line though.

Anyone know how that might be done?

The local context is various Debian-based things -- so I guess I'm looking for a GNU/Linux-ish answer :)

40hz

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 11,858
    • View Profile
    • Donate to Member
Re: "Safely" Remove USB Devices in *N*X
« Reply #1 on: June 10, 2012, 06:51 AM »
The umount Command

The umount command is used to manually unmount filesystems on Linux and other Unix-like operating systems.

A filesystem in this context is a hierarchy of directories that is located on a single partition (logically independent section of a hard disk drive) or other device, such as a CDROM, DVD, floppy disk or USB key drive, and has a single filesystem type (i.e., method for organizing data).

See the man pages for full syntax (i.e. $man unmount) or here for a complete how-to in normal understandable English.
 :)

ewemoa

  • Honorary Member
  • Joined in 2008
  • **
  • Posts: 2,922
    • View Profile
    • Donate to Member
Re: "Safely" Remove USB Devices in *N*X
« Reply #2 on: June 10, 2012, 08:55 PM »
Thanks for the feedback.

As near as I can tell in this environment, even after performing umount on all the partitions on a device (so df doesn't show anything mounted for the drive), the physical device's LED is on.  So as far as I can tell, "Safely Remove" is not the same thing as umount.  IIRC, palimpsest's UI has a button per partition for unmounting and a single button for "Safely Remove" for the whole device.



Came across this too:

Safely remove an USB hard drive in Linux
« Last Edit: June 10, 2012, 09:14 PM by ewemoa »

MilesAhead

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 7,736
    • View Profile
    • Donate to Member
Re: "Safely" Remove USB Devices in *N*X
« Reply #3 on: June 10, 2012, 09:51 PM »
http://linux.about.c...cmd/blcmdl8_sync.htm

At least buffers would be flushed to disk. As for all the rest of it, suspending the USB port etc.. I don't know if they have all that perfected yet. Half the time it doesn't work in Windows either. If the eject works for a drive I'll use it. But most of the time it just hangs. Usually I just run sync.exe to flush buffers to disk then pull the drive or shut it off if it has a power switch. It's been some time since I ran Linux. I'm just going by the link you posted.


40hz

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 11,858
    • View Profile
    • Donate to Member
Re: "Safely" Remove USB Devices in *N*X
« Reply #4 on: June 10, 2012, 10:56 PM »
1. FWIW I've never had a issue or experienced data loss using unmount with any mainstream Linux distro since about the era of Ubuntu 8.0.4.  Although in day to day practice I tend to use the eject menu option from the graphic environment since that is the preferred "safe" eject procedure in most distros. YMMV.

2. There is an eject command available in many distros as well. Syntax can be found here.

3. Supposedly this command accomplishes the same thing as the eject menu command does:

      sudo echo 1>/sys/bus/usb/devices/usb1/remove

Can't vouch for it however, since it comes to me by way of another Nix user and I've never used it personally. It's an interesting approach and you could always script it to make your own command(s). Requires root access.

Luck!  8)


ewemoa

  • Honorary Member
  • Joined in 2008
  • **
  • Posts: 2,922
    • View Profile
    • Donate to Member
Re: "Safely" Remove USB Devices in *N*X
« Reply #5 on: June 11, 2012, 06:39 AM »
There are some claims that suggest that umount will lead to a sync (at least in recent *NIXes) without having to do so manually.  In any case, sync doesn't appear to lead to the device's LED turning off.

eject looked promising, so I gave it a try -- the results of sudo eject -v sdb were:

eject: device name is `sdb'
eject: expanded name is `/dev/sdb'
eject: `/dev/sdb' is not mounted
eject: `/dev/sdb' is not a mount point
eject: `/dev/sdb' is a multipartition device
eject: using device name `/dev/sdb' for ioctls
eject: trying to eject `/dev/sdb' using CD-ROM eject command
eject: CD-ROM eject command failed
eject: trying to eject `/dev/sdb' using SCSI commands
eject: SCSI eject failed
eject: trying to eject `/dev/sdb' using floppy eject command
eject: floppy eject command failed
eject: trying to eject `/dev/sdb' using tape offline command
eject: tape offline command failed
eject: unable to eject, last error: Invalid argument

FWIW, sdb does show up via dmesg and sudo blkid shows some /dev/sdb* lines.  The syntax of the command looks right as one of the examples from the man page was: eject sda

I tried the sudo echo 1 thing, but no luck (Permission denied) -- may be I chose the wrong thing for what comes between devices/ and /remove...

Perhaps some day there'll be a straight-forward easy way to do this :)

Thanks all for your help.