Force unmount of NFS-mounted directory [closed] - linux

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 9 years ago.
Locked. This question and its answers are locked because the question is off-topic but has historical significance. It is not currently accepting new answers or interactions.
I have an NFS-mounted directory on a Linux machine that has hung. I've tried to force an unmount, but it doesn't seem to work:
$ umount -f /mnt/data
$ umount2: Device or resource busy
$ umount: /mnt/data: device is busy
If I type "mount", it appears that the directory is no longer mounted, but it hangs if I do "ls /mnt/data", and if I try to remove the mountpoint, I get:
$ rmdir /mnt/data
rmdir: /mnt/data: Device or resource busy
Is there anything I can do other than reboot the machine?

You might try a lazy unmount:
umount -l

If the NFS server disappeared and you can't get it back online, one trick that I use is to add an alias to the interface with the IP of the NFS server (in this example, 192.0.2.55).
Linux
The command for that is something roughly like:
ifconfig eth0:fakenfs 192.0.2.55 netmask 255.255.255.255
Where 192.0.2.55 is the IP of the NFS server that went away. You should then be able to ping the address, and you should also be able to unmount the filesystem (use unmount -f). You should then destroy the aliased interface so you no longer route traffic to the old NFS server to yourself with:
ifconfig eth0:fakenfs down
FreeBSD and similar operating systems
The command would be something like:
ifconfig em0 alias 192.0.2.55 netmask 255.255.255.255
And then to remove it:
ifconfig em0 delete 192.0.2.55
man ifconfig(8) for more!

Try running
lsof | grep /mnt/data
That should list any process that is accessing /mnt/data that would prevent it from being unmounted.

I had the same problem, and
neither umount /path -f,
neither umount.nfs /path -f,
neither fuser -km /path,
works
finally I found a simple solution >.<
sudo /etc/init.d/nfs-common restart, then lets do the simple umount ;-)

Your NFS server disappeared.
Ideally your best bet is if the NFS server comes back.
If not, the "umount -f" should have done the trick.
It doesn't ALWAYS work, but it often will.
If you happen to know what processes are USING the NFS filesystem,
you could try killing those processes and then maybe an unmount would work.
Finally, I'd guess you need to reboot.
Also, DON'T soft-mount your NFS drives. You use hard-mounts to guarantee
that they worked. That's necessary if you're doing writes.

Couldn't find a working answer here; but on linux you can run "umount.nfs4 /volume -f" and it definitely unmounts it.

Related

Closing an open ssh port in Linux with one line [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 3 years ago.
Improve this question
I often ssh tunnel into Rstudio on a server I have set up. I'm trying to devise a single command that I can use to close the ssh port. I know that I can find the PID for localhost:1234 with:
sudo lsof -i :1234
And I also know that I can kill the process with:
sudo kill $(sudo lsof -t -i:1234)
The issue is that if I have Chrome open to run Rstudio server, the 2nd command will kill the open Chrome browswer as well. Is there a way to modify the 2nd command so that I close the open ssh port, but not the Chrome browser? There are two PID numbers, so I could theoretically grep for 'ssh' but I'm not sure how.
EDIT FOR CLARITY:
For example, I get the following output from the first command. I want to modify the 2nd command so that I can kill PID 15834, but not 30117. Apologies, I hope that makes more sense.
try this
sudo kill $(sudo lsof -t -i:1234 -c ssh)
-c => selects the listing of files for processes executing the command that begins with the characters of c.
Just firewall the port:
sudo iptables -I INPUT -p tcp --dport 1234 -j DROP

Error applying chroot to group (groupmod: group 'www' does not exist) [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 5 years ago.
Improve this question
So I am trying to chroot all the users who are in group www to the directory /var/www. But I every time I try to do that, it comes back saying the group doesn't exist. (even though the group does exist)
[root#server var]# cat /etc/fedora-release
Fedora release 26 (Twenty Six)
[root#server var]# groupadd -r www
[root#server var]# groupmod -R /var/www www
groupmod: group 'www' does not exist
[root#server var]# ls -la
drwxrwxrwx. 5 root www 46 Jul 12 06:44 www
As you can see the error message is less than helpful. I have looked around on stackoverflow but haven't come across an answer to this specific question yet.
Can anyone shed some light on what I am doing wrong?
That is not what groupmod -R does. What it means is that the groupmod program will chroot into the directory, and then do everything. It’s intended for when you have one system mounted inside another, such as if you booted from a live USB drive to make changes to a broken system.
Once groupmod has run chroot, it looks in the /var/www/etc/group file to figure out what group ID www corresponds to, which of course fails because if your system is at all sanely set up you don’t have a var/www/etc/group file.
I do not know how to make sure all processes by a specific user run in a chroot, and I don’t think that’s the right way to achieve your goal. If a program is chrooted into /var/www, it doesn’t have access to any of the utilities it might expect, like the web server executable. Instead, I would look at the documentation of your web server and see if it supports this directly, or see if you can get a custom mount namespace using systemd.

rmdir failed because of "Device or resource busy" [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 1 year ago.
Improve this question
there are a lot of similar problem like "Device or resource busy". But I think my problem is different with them.
I use mount --bind to bind a directory
mount --bind /tmp/origin /tmp/mount
and then could umount successfully
umount /tmp/mount
And then if I call rm at once
rm -rf /tmp/mount
I could get a error Device or resource busy. If I wait 2~3 seconds, and then call rm, it could success.
So this behaviour is very strange here. I try use
lsof +D /tmp/mount
could not see anything.
I also use fuser -vm /tmp/mount, could not see any process hold this folder.
I compare the /proc/mounts before umount /tmp/mount and after umount /tmp/mount. /tmp/mount has already removed.
I compare the stat /proc/mounts before umount /tmp/mount and after umount /tmp/mount. The inode also different, this means /tmp/mount has already removed complete.
Even I call sync && echo 2 > /proc/sys/vm/drop_caches and try to drop file caches, it still not work.
I try this in both Ubuntu 14.04 and CentOS 6.6. They have same results.
I faced problem like this because I mount shared folder in VM and I want to remove directory after unmount and I just want to share my solution.
un-mount path
sudo umount /your_path
remove mout path in /etc/fstab
sudo nano /etc/fstab
reboot
sudo reboot
remove directory
sudo rm -rf /your_path
In my experience, the following operations are asynchronous on Linux:
Closing file. Immediately after close() returns, umount() may return EBUSY while it performs asynchronous release. See discussion here: page 1, page 2.
Umounting filesystem. Mounted device may be busy until all data is written to disk.
Even I call sync && echo 2 > /proc/sys/vm/drop_caches and try to drop file caches, it still not work.
See sync(8):
On Linux, sync is only guaranteed to schedule the dirty blocks for writing; it can actually take a short time before all the blocks are finally written. The reboot(8) and halt(8) commands take this into account by sleeping for a few seconds after calling sync(2).
As for /proc/sys/vm/drop_caches, see here:
This is a non-destructive operation and will not free any dirty objects.
Thus, immediately after your command, data may be still queued for write and umounting is not yet finished.
Update
However, when asynchronous umounting is in action, kernel will return EBUSY for operations on mounted device, but not for mount point.
So the cases above could not be the reason of your problem :P
PS.
Actually I don't understand why the man page states that sync(8) is not synchronous in Linux. It calls sync(2) which states:
According to the standard specification (e.g., POSIX.1-2001), sync() schedules the writes, but may return before the actual writing is done. However, since version 1.3.20 Linux does actually wait. (This still does not guarantee data integrity: modern disks have large caches.)
Thank you for #g-v answer. But I found the result is another problem. We use CLONE_NEWNS flag when fork a process. More details could be found in CLONE_NEWNS flag and MESOS-3349 Device busy bug
In a short word, we mount in parent process. And then umount in child process, because of CLONE_NEWNS, the mount point still exists which handled by parent process. So when call rmdir would got EBUSY error code.
To avoid above problems, we could use shared mount or slave mount. More details could be found in LWN 159092
check
df -h
then
sudo umount /path
Follow these steps:
open Resource Monitor
click on "associated handles" drop box
search the folder creating problem
Right click on each process and "End process".
Now you can delete the folder

Telnet File Transfer between two linux machines [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 7 years ago.
Improve this question
I want to send a file from one Linux machine with IP suppose "192.168.2.25" to other Linux machine that's a server "192.168.2.110"
how can i do that by using Telnet command??
A simple option is to use netcat (nc). This is particularly useful on stripped down Linux systems where services like ssh and ftp are turned off.
On destination machine run the following command: nc -l -p 1234 > out.file
On source machine run the following command: nc -w 3 <dest-ip-adr> 1234 < out.file
For more details look, for example, here.
There are also netcat implementations for Windows, e.g. ncat.
While it may not be possible with only telnet, it is possible with telnet and netcat. Some of the examples above just referenced using netcat, but there have been times when I was on an old machine that was still in production that had telnet but not netcat. In this case, you can set netcat to listen on a newer, remote machine and telnet the file to it.
On the newer remote machine:
netcat -l <PORT> > OUTPUT.FILE
On the older telnet only machine:
cat FILE | telnet REMOTE-HOST PORT
Note that this works with text files. If you have a binary file of some sort you would need to do further manipulation on both ends.
Telnet just gives you a remote terminal session. The best you could do is telnet, open a new file in an editor and copy/paste the text from the local machine.
To copy files use something like rsync, scp, rcp or ftp.

Linux: Which process is causing "device busy" when doing umount? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 4 years ago.
Improve this question
Linux: Which process is causing "device busy" when doing umount?
Look at the lsof command (list open files) -- it can tell you which processes are holding what open. Sometimes it's tricky but often something as simple as sudo lsof | grep (your device name here) could do it for you.
Just in case... sometimes happens that you are calling umount from the terminal, and your current directory belongs to the mounted filesystem.
You should use the fuser command.
Eg. fuser /dev/cdrom will return the pid(s) of the process using /dev/cdrom.
If you are trying to unmount, you can kill theses process using the -k switch (see man fuser).
Check for open loop devices mapped to a file on the filesystem with "losetup -a". They wont show up with either lsof or fuser.
Also check /etc/exports. If you are exporting paths within the mountpoint via NFS, it will give this error when trying to unmount and nothing will show up in fuser or lsof.
lsof +f -- /mountpoint
(as lists the processes using files on the mount mounted at /mountpoint. Particularly useful for finding which process(es) are using a mounted USB stick or CD/DVD.
lsof and fuser are indeed two ways to find the process that keeps a certain file open.
If you just want umount to succeed, you should investigate its -f and -l options.
That's exactly why the "fuser -m /mount/point" exists.
BTW, I don't think "fuser" or "lsof" will indicate when a resource is held by kernel module, although I don't usually have that issue..
Open files
Processes with open files are the usual culprits. Display them:
lsof +f -- <mountpoint or device>
There is an advantage to using /dev/<device> rather than /mountpoint: a mountpoint will disappear after an umount -l, or it may be hidden by an overlaid mount.
fuser can also be used, but to my mind lsof has a more useful output. However fuser is useful when it comes to killing the processes causing your dramas so you can get on with your life.
List files on <mountpoint> (see caveat above):
fuser -vmM <mountpoint>
Interactively kill only processes with files open for writing:
fuser -vmMkiw <mountpoint>
After remounting read-only (mount -o remount,ro <mountpoint>), it is safe(r) to kill all remaining processes:
fuser -vmMk <mountpoint>
Mountpoints
The culprit can be the kernel itself. Another filesystem mounted on the filesystem you are trying to umount will cause grief. Check with:
mount | grep <mountpoint>/
For loopback mounts, also check the output of:
losetup -la
Anonymous inodes (Linux)
Anonymous inodes can be created by:
Temporary files (open with O_TMPFILE)
inotify watches
[eventfd]
[eventpoll]
[timerfd]
These are the most elusive type of pokemon, and appear in lsof's TYPE column as a_inode (which is undocumented in the lsof man page).
They won't appear in lsof +f -- /dev/<device>, so you'll need to:
lsof | grep a_inode
For killing processes holding anonymous inodes, see: List current inotify watches (pathname, PID).
lsof and fuser didn't give me anything either.
After a process of renaming all possible directories to .old and rebooting the system every time after I made changes I found one particular directory (relating to postfix) that was responsible.
It turned out that I had once made a symlink from /var/spool/postfix to /disk2/pers/mail/postfix/varspool in order to minimise disk writes on an SDCARD-based root filesystem (Sheeva Plug).
With this symlink, even after stopping the postfix and dovecot services (both ps aux as well as netstat -tuanp didn't show anything related) I was not able to unmount /disk2/pers.
When I removed the symlink and updated the postfix and dovecot config files to point directly to the new dirs on /disk2/pers/ I was able to successfully stop the services and unmount the directory.
Next time I will look more closely at the output of:
ls -lR /var | grep ^l | grep disk2
The above command will recursively list all symbolic links in a directory tree (here starting at /var) and filter out those names that point to a specific target mount point (here disk2).
If you still can not unmount or remount your device after stopping all services and processes with open files, then there may be a swap file or swap partition keeping your device busy. This will not show up with fuser or lsof. Turn off swapping with:
sudo swapoff -a
You could check beforehand and show a summary of any swap partitions or swap files with:
swapon -s
or:
cat /proc/swaps
As an alternative to using the command sudo swapoff -a, you might also be able to disable the swap by stopping a service or systemd unit. For example:
sudo systemctl stop dphys-swapfile
or:
sudo systemctl stop var-swap.swap
In my case, turning off swap was necessary, in addition to stopping any services and processes with files open for writing, so that I could remount my root partition as read only in order to run fsck on my root partition without rebooting. This was necessary on a Raspberry Pi running Raspbian Jessie.
Filesystems mounted on the filesystem you're trying to unmount can cause the target is busy error in addition to any files that are in use. (For example when you mount -o bind /dev /mnt/yourmount/dev in order to use chroot there.)
To find which file systems are mounted on the filesystem run the following:
mount | grep '/mnt/yourmount'
To find which files are in use the advice already suggested by others here:
lsof | grep '/mnt/yourmount'

Resources