4

I used this to give a chrooted ftp user access to another area of the filesystem:

mount --bind /var/www/dev/ /home/ftp_user/www_dev

per this website here.

And, oops, I realized I gave the ftp user access to too many files.

How do I fix that? rmdir doesn't work:

rmdir: failed to remove `www_dev': Device or resource busy

And if it did, I'm afraid it would remove the mounted files.

Buttle Butkus
  • 343
  • 1
  • 6
  • 20

2 Answers2

11

try umount -l /home/ftp_user/www_dev.

this will detach the file system immediately, and clean up any leftover references when it's no longer busy.

source: http://linux.die.net/man/8/umount

Erich
  • 295
  • 2
  • 11
  • Great! thank you. This is your first ever answer on this site? I appreciate it. – Buttle Butkus Jan 19 '15 at 02:29
  • yep. originally stopped by to ask an excel question, but still/currently pondering how to ask it. came across your question somehow. glad to help! – Erich Jan 19 '15 at 02:40
  • Hmm, I know some stuff about excel. What is it about? – Buttle Butkus Jan 19 '15 at 03:27
  • it's programmatic, so i'm going to ask it over at stackoverflow. will link here when i've figured it out. tia – Erich Jan 19 '15 at 03:47
  • pedantic correction -- it's formulaic, not programmatic. here's my question: http://stackoverflow.com/questions/28018779/sorting-excel-data-formulaicly – Erich Jan 19 '15 at 06:10
  • Why the lazy umount? – Xen2050 Jan 19 '15 at 06:37
  • @Xen2050 why not? Wouldn't that help with the "resource busy" error? – Buttle Butkus Jan 19 '15 at 10:10
  • @ButtleButkus The "`Device or resource busy`" error comes up whenever you try to remove a directory that has something mounted to it. Try it yourself, a regular `umount` will work. I'm asking erich why a "lazy unmount" would be beneficial – Xen2050 Jan 19 '15 at 10:37
  • @Xen2050 I thought I got the same error when I tried `umount` as well... I think I tried `rm` only after I tried `umount`... – Buttle Butkus Jan 19 '15 at 23:43
  • mostly a "why not" situation. occasionally i run into cases where umount itself is causing the busy, let alone any open files/resources on that fs. – Erich Jan 19 '15 at 23:50
  • Why not? *"lazy unmount doesn't do anything at all to the filesystem until it's free -- it just fakes it. That is, it denies access to a mounted filesystem until everyone closes all references to it. That's pretty much the worst of both worlds: It's mounted, so you can't do a thing to the devices, but it acts like its offline and denies everyone access. If the administration couldn't quickly find whatever reference is plugging up the unmount, they really would have to reboot the machine, it's either that or send the people who need to use that partition home for the day."* – Xen2050 Jan 20 '15 at 10:06
  • That's from "Is umount -l dangerous?" http://www.unix.com/linux/119194-umount-l-dangerous.html?s=1ccd6ca7f7a315d4d6b7d8510bf560e8 If I can't `umount` something, a `lsof ` almost always tells what's keeping it busy – Xen2050 Jan 20 '15 at 10:06
  • why would you care if users are denied access to something you're trying to deny them access to in the first place? – Erich Jan 20 '15 at 23:29
1

I see this question has the "unmounting" tag, which is exactly right: this looks like exactly what needs to be done.

In general, the way to unmount something that was created with the mount command is to use umount. (Not "unmount". "umount".)

umount /home/ftp_user/www_dev

That will make the /home/ftp_user/www_dev stop containing the mounted data. And /home/ftp_user/www_dev will be an empty directory. And that point, you can rmdir the empty directory /home/ftp_user/www_dev directory if you want to, as it will have nothing to do with the previously-mounted source (which appears to be the /var/www/dev/ directory in your example).

Note that none of what I said is specific to the --bind command, but is just how mounts are handled in general.

Side note: Are you really sure that you gave "access to too many files" to "the ftp user"? Maybe /var/www/dev/ has files that the ftp user should not have access to, but the ftp user might not have permissions to access those files. You might have done things just fine, and could confirm this by verifying what actions are actually possible when you're actually logged in as the ftp user. Of course, with a thorough understanding of Unix permissions, you could do this without logging in, but logging in might be the simplest way to perform a fast test without needing some of the more advanced details about how permissions work.

Side note 2: Of course, on many Unix systems, you can learn more about the command by running "man umount", which you could find by typing "apropos mount" since you had reason to suspect these effects were caused by the earlier "mount" command. If you're not familiar with mount and umount, and do something like trying to rmdir a directory, then this indicates that you haven't become familiar with some very basic things about the operating system you're using. If you're running a system that is providing services to other users, and you're in a position to be able to handle permissions, then these types of basics (like the /etc/fstab file, as another rather related example) are things that are worthwhile to know, in order to reliably oversee the system used by multiple people. You may wish to seek out a tutorial or book or some other training material related to running Unix (or Linux or something technically similar). For example, mount and umount are part of Linux Professional Institute's LPIC-1 certification (which is very related to CompTIA's Linux+ certification), so training material for those certifications will likely provide such details and lots of other things you're likely to find useful.

TOOGAM
  • 15,243
  • 4
  • 41
  • 58
  • I gave the user access to all website files, but realized that all he really needs is access to one javascript folder. I preferred to give him the least access necessary. I actually tried running `umount` a few times and it told me the device was busy. Then finally it worked. I did not actually try erich's answer but it seems like it would take care of the `device busy` error message I was getting. – Buttle Butkus Jan 19 '15 at 02:36