fusermount prepends /home to path when resource is busy

1

0

Problem:

I created a bash script for SSHFS mount/unmount using:

1|  dir=$(mktemp -d)
2|  sshfs user@server $dir
3|  cd $dir
4|  bash
5|  fusermount -u $dir
6|  rmdir $dir

Once these lines are executed, an error occurs on line 5 for fusermount -u $dir and gives this message:

fusermount: failed to unmount /home/tmp/tmp.xxxxxxxxxx: Device or resource busy

In the warning message, /home is prepended to the path instead of only /tmp/tmp.xxxxxxxxxx. Interestingly, rmdir then gives this message:

rmdir: failed to remove '/tmp/tmp.xxxxxxxxxx': Device or resource busy

... showing that $dir still has the value of /tmp/tmp.xxxxxxxxxx.

Question:

Why does fusermount prepend /home to the path when the resource is busy?

Majal

Posted 2019-10-20T15:02:57.370

Reputation: 223

1Why are you starting bash on the Line 4? – None – 2019-10-20T15:15:07.777

1So I can run commands in the directory. Once I exit this bash, then the unmounting and rmdir occurs. – Majal – 2019-10-20T15:23:04.937

Maybe the "Device or resource busy" Error Message is appearing just because of the "cd $dir" Command. The Directory referenced through the $dir Variable is still in use. Try adding a "cd .." Command just before the "fusermount -u $dir" Command and try again. – None – 2019-10-20T15:34:43.077

1Hi @DOBRESCU_Mihai! It worked! Thanks for the tip! :-) – Majal – 2019-10-20T22:55:35.483

For Great Success, @Majal. I shall add now an Exquisite Answer to this Question so that the whole Planet will be able to rejoice in ecstasy forever. – None – 2019-10-21T11:00:34.743

Interesting. I totally missed the fact that the shell is in the working directory. My attention was on the fact that the message had a prepended /home. I'll check with fusermount if this is a bug or something. – Majal – 2019-10-22T00:27:57.597

There is no fusermount Bug. It displays that Error Message because it attempts to work inside the $dir Directory. The same thing happens to the rmdir $dir Command. If they are run outside of it, then they are working. Either with my cd .. addition or with @Tom Yan's (cd $dir;bash) Trick, you are avoiding running them inside of it. – None – 2019-10-22T09:57:16.490

Answers

0

Apparently, this is the Correct Version that has solved this Problem:

1|  dir=$(mktemp -d)
2|  sshfs user@server $dir
3|  cd $dir
4|  bash
5|  cd ..
6|  fusermount -u $dir
7|  rmdir $dir

user1018743

Posted 2019-10-20T15:02:57.370

Reputation:

1Or you can group cd $dir and bash to (cd $dir; bash) – Tom Yan – 2019-10-21T11:19:11.637

Why? Does the group annihilate the changing of the directory to $dir after bash exists? – None – 2019-10-21T13:45:18.817

1

Try it and see. https://www.gnu.org/software/bash/manual/html_node/Command-Grouping.html

– Tom Yan – 2019-10-21T13:49:41.493

I cannot test right now. I understand that "each of the commands in list [are] to be executed in that subshell", which is extremely cool - quite freezing, actually. When the subshell terminates, the whole Planet explodes and the current directory is reverted back to the one that was present before the group got executed. This is too subtle for most people. I would not have started that bash command just like that, in the first place. – None – 2019-10-21T14:02:11.943

Funny. It does not work. As you can see here. Maybe you are using another Flavor of the Bourne-Again Shell-Scripting Environment. I am using CygWin's.

– None – 2019-10-21T14:28:21.580

Weird. I have just pressed the Control-D Key Combination in order to get out of the Terminal Window, as I am usually doing. And an exit Command has appeared! As you can see here. That means that the bash Session did not exit after the end of the Group Execution! The Second Control-D Key Combination has produced the Usual logout Command, as you can see here. Can you explain that?

– None – 2019-10-21T14:37:44.557

1Uhm, wasn't that the idea of the OP? He wanted an interactive shell in the middle of a script. – Tom Yan – 2019-10-21T15:15:49.003

You have not answered my previous questions. Related to the Interactive Shell - all that I can say it is that it is a very weird idea. It is basically mixing the Automated Non-Interactive Nature of a Shell-Script with the Manual Interactive Nature of an Interactive Shell. I can bet that it might be done in a different way. – None – 2019-10-21T15:26:02.630

1I mean, it worked in you tests as expected as that was the idea. The cd was to prepare for the / another interactive shell that you were going to start. The command group isn't finished until you manually exit the shell. – Tom Yan – 2019-10-21T15:36:06.057

1As for exit v.s. logout, it depends on whether the "current" shell is a "login shell". If you run bash -l in the group instead, you'll also see logout instead of exit the first time you control-D. – Tom Yan – 2019-10-21T15:40:29.273

1You were probably thinking of the result of (cd /; bash -c "pwd") instead btw. – Tom Yan – 2019-10-21T15:42:59.330

Nope. I was thinking exactly of your (cd $dir; bash) Version as another Solution for this Problem. As you can see in my Previous Tests that appear in those Three Screen-Shots, it does not work. The Current Directory stays / (the Root Directory) even after the Manual Exiting of the Secondary bash Shell. It should have reverted back to the /home/dobre/ Directory. But it does not. – None – 2019-10-21T15:53:15.137

On a second thought, I can see now that actually I was mistaken the / Root Directory for the ~/ Home Directory. So the Tests are really working. Maybe you could create another Answer for this Question with your own Version. – None – 2019-10-21T16:05:00.987