Find the answer to your Linux question:
Results 1 to 8 of 8
A detachable device like eSATA,USB can be abruptly removed (by simply pulling the plug). Then, if there are open file handles on a partition , then the partitions wont unmount. ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Sep 2011
    Posts
    3

    Unhappy Unmounting Detachable devices(eSATA,USB storage) in linux


    A detachable device like eSATA,USB can be abruptly removed (by simply pulling the plug).
    Then, if there are open file handles on a partition , then the partitions wont unmount. i.e. the Linux "umount" command will fail, even AFTER the drive is physically detached.
    And if the unmount fails, then on reattachment of the device the mount will fail. So we will have to find out which processes are using the drive and kill them or close all the handles. And if you cannot do either , then you will have to reboot the box to see your drive mounted. And I can definitely not kill the process using it.
    I see no force unmount option , there is a -f option but it is only for NFS.

    This sounds very strange,doesn't Linux
    accommodate for this scenario where a user simply yanks a drive? Does anyone know how to handle this scenario gracefully in Linux?

    Is there any way to find out what file handles are open on a particular partition/device or selectively flush and close all file handles only for a particular device ?



    lsof is not available in the embedded linux that I am using. lsof is not available in busybox.
    Last edited by solid_state; 09-07-2011 at 12:19 PM. Reason: Adding additional info

  2. #2
    Just Joined!
    Join Date
    Aug 2011
    Location
    London, UK
    Posts
    19
    'lsof' will do what you want. It's great for when you want to unmount an external drive but it is reported as being 'busy' because one of your users has a file open (even if they opened it weeks ago and have forgotten about it). Run lsof to discover the file and, just as importantly, the user.

  3. #3
    Just Joined!
    Join Date
    Sep 2011
    Posts
    3
    Thanks for the response. Actually lsof is not available in the embedded linux that I am using. lsof is not available in busybox.

  4. $spacer_open
    $spacer_close
  5. #4
    Linux Newbie BoDiddley's Avatar
    Join Date
    Oct 2010
    Location
    Plainfield, New Jersey
    Posts
    137
    I simply use File Manager and right click to unmount a drive. It should do a force close on any open files, sometimes I have to unmount twice. However, I have a plug-and-play hdd. When I connect it I get the usual options on how to utilize it. When I am finished I unmount it in file manager. I have never had to unmount using command line.

  6. #5
    Just Joined!
    Join Date
    Jul 2008
    Posts
    93
    Quote Originally Posted by solid_state View Post
    A detachable device like eSATA,USB can be abruptly removed (by simply pulling the plug).

    This sounds very strange,doesn't Linux
    accommodate for this scenario where a user simply yanks a drive? Does anyone know how to handle this scenario gracefully in Linux?
    This sounds like a social problem not a Linux problem. You have to educate or yank the user who does things like this.

  7. #6
    Just Joined!
    Join Date
    May 2006
    Posts
    6
    Quote Originally Posted by clowenstein View Post
    This sounds like a social problem not a Linux problem. You have to educate or yank the user who does things like this.
    Agreed, but now it HAS happened. You are in a vicious circle: the device is physically reattached, but it can neither be unmounted nor re-mounted. How do you recover? Of course you could reboot, like in W

  8. #7
    Just Joined!
    Join Date
    Sep 2011
    Posts
    3
    Quote Originally Posted by jjge View Post
    Agreed, but now it HAS happened. You are in a vicious circle: the device is physically reattached, but it can neither be unmounted nor re-mounted. How do you recover? Of course you could reboot, like in W
    Yes thats the problem, if it has happened what to do next.

    It seems if I have mounted the device on say /mnt/abc and if I disconnect the drive and then reconnect, Linux seems to re-attach the device's file system to the same mount point "/mnt/abc", without us doing any unmount or mount. And then the same old open file handles seems to start working after reattachment (atleast for file read operation). This is my observation. I am not sure if this is the expected behavior.. However, this also does not seem to be working consistently.

    I had an open file handle for reading ("tail -f") which I left open, then I detached and reattached and then modified the file being tailed and I saw the "tail -f" output getting updated with the changes.
    However, if I try to modify a file after the device was gone( it gives error as expected) and then I reattach, the device's file system does not get properly re-attached to the same mount point. In case of a file write (while the device was not there) it does not seem to be working.

    Is there any standard/consistent behavior that Linux follows when a drive is removed abruptly without closing all handles and properly unmounting all partitions ?

  9. #8
    Linux Newbie BoDiddley's Avatar
    Join Date
    Oct 2010
    Location
    Plainfield, New Jersey
    Posts
    137
    To me this sounds like a file system problem, not a device problem. I would run fsck from a rescue disk on both the drive and the file system. Fsck of course depends on your file system. For me it would be Reiserfsck.

    Basically, your pointers/directory locations are bad. This is consistent across any platform, or device.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •