Linux umount device is busy

Принудительно размонтировать раздел (umount — device is busy)

Иногда не получается размонтировать раздел, так как выходит ошибка:

umount — device is busy

umount: /mnt/disk: device is busy

Тогда его можно размонтировать принудительно командой

umount -l /mnt/disk

umount -f /mnt/disk

авторынок

Похожие материалы (по тегу)

234 комментарии

Стартовый касательно довольно расхожих видов продвижения касательно коммерции есть навесная рекламное объявление, которую реально разместить на публичном локации плюс привлекать интересующихся клиентов. Предприятие LowCostPrint уже из течении многих лет занимается форматную печатью большой трудности также сумеет воплотить задание в постижимым цене в Московской области. В онлайн магазине баннер 6х3 пользователь сможет выбрать интересующий модификацию баннера: рекламные растяжки, интерьер оттиск, ненастоящие фасады, стенды, постпечатная печать, наклейки, пропечатка по сетке и другие форматы широкого печати.
Определиться с подходящим вариантом клиентам помогут наши опытные менеджеры, те что у телефонном распорядке дадут полноценный ответ на всяческих неотложных вопросы, укажут счет плюс посодействуют осущетсвить широкоформатную печать именно по онлайн ресурс. Трудясь на нашем оборудовании также из https://баннер-москва.рф/ прямыми снабженцами, наш магазин гарантируем новым покупателям отличное свойства, быстрая реализация, формирование любых размеров и верную тон!

Error 523 origin is unreachable

Error 523 origin is unreachable

Error 523 origin is unreachable

I’m not sure where you’re getting your information, but good topic.
I needs to spend some time learning much more or understanding more.
Thanks for magnificent info I was looking for this information for my mission.

Источник

3 Ways to Force Unmount in Linux Showing “device is busy”

In some situations when you try to unmount a filesystem especially NFS, it displays ‘device is busy’ message. This happens often when the NFS server has some issues (mainly unreachable) and you have a soft NFS mount.

There are different ways and options we can try out if normal NFS unmount fails. In this tutorial, I will explain how to perform a force unmount in Linux.

In our scenario, we have an NFS filesystem mounted on to /var/linoxide directory.

Let’s first use df command to display all mounted directories.

When we try to umount the remote partition, we have an error message. The following example shows the unmount fails because the device is busy:

1) With lsof

The lsof (list open files) command displays a list of all open files and the processes associated with them on a specific file system, directory, or device. By default, it lists all files, shared libraries, and directories that are currently open and provides as much information as possible about each of them.

Here we can use lsof command to find PID (process id) corresponding to our mount point and then kill that process.

Here we have the 3 PID of the process using the mounted directory. You can see vim command, which means that a file is being edited by the ‘linoxide’ user. You can inform the user to stop his action or kill the process.

Now, let’s see the results:

You can look that our user has stopped his modification but we still have bash command in execution but we don’t know why. We can now kill the two processes with kill command.

Now we will kill the first bash process

We can verify the result

We can see that one process is killed

Now let’s verify for the second process

Now let’s try to unmount the folder

Our action has automatically unmounted the folder but let’s check with df command.

From the output, we can see directory /mnt/nfs/linoxide_srv has been unmounted from the system.

2) With fuser

The fuser (find user processes) command helps to identify processes that are preventing you from unmounting file systems. It finds user processes that are associated with whatever files, directories, or file system mount points that you supply as command-line arguments.

We can use fuser command with -m option which lists all the processes accessing the files or mount point on the file system and the -v option which shows a result like ps command with PID, user and the executed command.

You can see the command in execution.

With fuser command, it is possible to directly kill the process in execution with -k option without kill command

Check the result

It seems that only the mount is in execution. Let’s try to unmount the folder

We don’t have any more error messages. Check the mount point

We can see that the /mnt/nfs/linoxide_srv folder has been unmounted as we want.

3) Lazy unmount

Umount command has an -l option to perform a lazy unmount (requires kernel 2.4.11 or later). The mount will be removed from the filesystem namespace (so you won’t see it under /mnt/nfs/linoxide anymore) but it stays mounted, so programs accessing it can continue to do so. When the last program accessing it exits, the unmount will actually occur.

Читайте также:  Windows security client error

We can see that the folder is busy. Now let’s try to do a lazy unmount

We don’t have an error message. We will check if the command was being executed without error

Now let’s check the mount point

We can see that the mount point /mnt/nfs/linoxide_srv doesn’t appear again but as we said earlier, for example, our ‘linoxide’ user is still modifying his file, can create new files, etc. On the server, we can see the file that the user is modifying.

We can need to unmount a partition because of an emergency or simply to remove a device but a problem can occur because that device is busy. It is important to examine every process on the system before making a decision for the method to resolve the problem. The lsof and fuser commands make it easy to identify the processes that are preventing you from unmounting a file system. Finally, if you want to use a force unmount use -f option.

Conclusion

In this tutorial, we learned different options available when you are unable to umount in Linux and Unix-style systems. All mentioned force umount options explained should work on all Linux distributions like Ubuntu, Mint, etc.

If you have any questions or feedback, feel free to leave a comment.

Источник

Busy Device on Umount

I often experience a problem to umount a directory:

There are many reasons why the device is busy. Sometimes there are processes running which have open locks on it, sometimes there are other directories mounted on top of /mnt/dir .

What are the steps to check why a directory couldn’t be unmounted.

I know there are many reasons, but it’s ok if you explain a specific solution.

[X] running processes on mounted volumes.
[X] another volume is mounted on top of a volume we want to unmount
[_] NFS locks the volume we want to unmount

6 Answers 6

The way to check is fuser -vm /mnt/dir , which must be run as root. It will tell you which processes are accessing the mount point.

An alternative is lsof /mnt/dir , which will show each open file on the mount. Again best run as root.

You can run either of these as non-root, but then the output will be limited to your processes—ones from other users will just be silently not shown, even though they will prevent unmounting the filesystem.

Example:

The «access» field tells you how its being accessed. In this case, the kernel has it in use as a mount (duh, but unmount will be OK with only this). bash has it as the current working directory (will have to cd to a different directory before unmount) and gvim both has the current directory and has a file open (will need to close that gvim).

In this output, you can see the current directories for both bash and gvim (as type DIR ). You can also see which file gvim has open for write.

How to force the issue:

fuser has a -k option which will send a signal (default: SIGKILL ) to each process using the mount. This is a rather forceful way to stop the mount from being busy. (And of course, be careful of what you SIGKILL !)

umount has an -l option to perform a lazy unmount. The mount will be removed from the filesystem namespace (so you won’t see it under /mnt/Zia/src anymore, in the example) but it stays mounted, so programs accessing it can continue to do so. When the last program accessing it exits, the unmount will actually occur.

There is one final fixable cause of unmount failing, and that’s an NFS server going down. Here you can use umount -f , but you risk data loss if you do so. (The client may have cached writes that haven’t been confirmed by the server yet, and those writes will be discarded. Apps, however, have already been told the write is successful.)

Источник

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

Want to improve this question? Update the question so it’s on-topic for Stack Overflow.

Closed 3 years ago .

Linux: Which process is causing «device busy» when doing umount?

12 Answers 12

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 .

Читайте также:  Windows с narod ru

(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..

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:

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).

Источник

How to unmount a busy device

I’ve got some samba drives that are being accessed by multiple users daily. I already have code to recognize shared drives (from a SQL table) and mount them in a special directory where all users can access them.

I want to know, if I remove a drive from my SQL table (effectively taking it offline) how, or even is, there a way to unmount a busy device? So far I’ve found that any form of umount does not work.

Ignoring the possibility of destroying data — is it possible to unmount a device that is currently being read?

14 Answers 14

YES!! There is a way to detach a busy device immediately — even if it is busy and cannot be unmounted forcefully. You may cleanup all later:

NOTE/CAUTION

  1. These commands can disrupt a running process, cause data loss OR corrupt open files. Programs accessing target DEVICE/NFS files may throw errors OR could not work properly after force unmount.
  2. Do not execute above umount commands when inside mounted path (Folder/Drive/Device) itself. First, you may use pwd command to validate your current directory path (which should not be the mounted path), then use cd command to get out of the mounted path — to unmount it later using above commands.

If possible, let us locate/identify the busy process, kill that process and then unmount the samba share/ drive to minimize damage:

lsof | grep ‘ ‘ (or whatever the mounted device is)

pkill target_process (kills busy proc. by name | kill PID | killall target_process )

umount /dev/sda1 (or whatever the mounted device is)

Make sure that you aren’t still in the mounted device when you are trying to umount.

/Documents on Solaris 11; but Documents had subfolders and it was the issue.

Avoid umount -l

At the time of writing, the top-voted answer recommends using umount -l .

  • It doesn’t actually unmount the device, it just removes the filesystem from the namespace. Writes to open files can continue.
  • It can cause btrfs filesystem corruption

Work around / alternative

The useful behaviour of umount -l is hiding the filesystem from access by absolute pathnames, thereby minimising further moutpoint usage.

This same behaviour can be achieved by mounting an empty directory with permissions 000 over the directory to be unmounted.

Then any new accesses to filenames in the below the mountpoint will hit the newly overlaid directory with zero permissions — new blockers to the unmount are thereby prevented.

First try to remount,ro

The major unmount achievement to be unlocked is the read-only remount. When you gain the remount,ro badge, you know that:

  1. All pending data has been written to disk
  2. All future write attempts will fail
  3. The data is in a consistent state, should you need to physcially disconnect the device.

mount -o remount,ro /dev/device is guaranteed to fail if there are files open for writing, so try that straight up. You may be feeling lucky, punk!

You should then be able to remount the device read-only and ensure a consistent state.

If you can’t remount read-only at this point, investigate some of the other possible causes listed here.

Read-only re-mount achievement unlocked 🔓☑

Congratulations, your data on the mountpoint is now consistent and protected from future writing.

Why fuser is inferior to lsof

Why not use use fuser earlier? Well, you could have, but fuser operates upon a directory, not a device, so if you wanted to remove the mountpoint from the file name space and still use fuser , you’d need to:

  1. Temporarily duplicate the mountpoint with mount -o bind /media/hdd /mnt to another location
  2. Hide the original mount point and block the namespace:
  1. The original namespace hidden (no more files could be opened, the problem can’t get worse)
  2. A duplicate bind mounted directory (as opposed to a device) on which to run fuser .
Читайте также:  Creating windows installer package

This is more convoluted [1] , but allows you to use:

which will interactively ask to kill the processes with files open for writing. Of course, you could do this without hiding the mount point at all, but the above mimicks umount -l , without any of the dangers.

The -w switch restricts to writing processes, and the -i is interactive, so after a read-only remount, if you’re it a hurry you could then use:

to kill all remaining processes with files open under the mountpoint.

Hopefully at this point, you can unmount the device. (You’ll need to run umount on the mountpoint twice if you’ve bind mounted a mode 000 directory on top.)

to interactively kill the remaining read-only processes blocking the unmount.

Dammit, I still get target is busy !

Open files aren’t the only unmount blocker. See here and here for other causes and their remedies.

Even if you’ve got some lurking gremlin which is preventing you from fully unmounting the device, you have at least got your filesystem in a consistent state.

You can then use lsof +f — /dev/device to list all processes with open files on the device containing the filesystem, and then kill them.

[1] It is less convoluted to use mount —move , but that requires mount —make-private /parent-mount-point which has implications. Basically, if the mountpoint is mounted under the / filesystem, you’d want to avoid this.

Try the following, but before running it note that the -k flag will kill any running processes keeping the device busy.

The -i flag makes fuser ask before killing.

Check for exported NFS file systems with exportfs -v. If found, remove with exportfs -d share:/directory. These don’t show up in the fuser/lsof listing, and can prevent umount from succeeding.

Linux 2.1.116 added the umount2() system call, which, like umount(), unmounts a target, but allows additional flags controlling the behaviour of the operation:

MNT_FORCE (since Linux 2.1.116) Force unmount even if busy. (Only for NFS mounts.) MNT_DETACH (since Linux 2.4.11) Perform a lazy unmount: make the mount point unavailable for new accesses, and actually perform the unmount when the mount point ceases to be busy. MNT_EXPIRE (since Linux 2.6.8) Mark the mount point as expired. If a mount point is not currently in use, then an initial call to umount2() with this flag fails with the error EAGAIN, but marks the mount point as expired. The mount point remains expired as long as it isn’t accessed by any process. A second umount2() call specifying MNT_EXPIRE unmounts an expired mount point. This flag cannot be specified with either MNT_FORCE or MNT_DETACH. Return Value

On success, zero is returned. On error, -1 is returned, and errno is set appropriately.

Just in case someone has the same pb. :

I couldn’t unmount the mount point (here /mnt ) of a chroot jail.

Here are the commands I typed to investigate :

As you can notice, even lsof returns nothing.

Then I had the idea to type this :

Here it was a /mnt/dev bind to /dev that I had created to be able to repair my system inside from the chroot jail.

After umounting it, my pb. is now solved.

Someone has mentioned that if you are using terminal and your current directory is inside the path which you want to unmount, you will get the error.
As a complementary, in this case, your lsof | grep path-to-be-unmounted must have below output:

I recently had a similar need to unmount in order to change it’s label with gparted.

/dev/sda1 was being mounted via /etc/fstab as /media/myusername. When attempts to unmount failed, I researched the error. I had forgotten to unmount a dual partitioned thumb drive with a mountpoint on /dev/hda1 first.

I gave ‘lsof’ a go as recommended.

The output of which was:

lsof: WARNING: can’t stat() fuse.gvfsd-fuse file system /run/user/1000/gvfs
Output information may be incomplete.
lsof: WARNING: can’t stat() fuse file system /run/user/1000/doc
Output information may be incomplete.

Since lsof burped up two fuse warnings, I poked around in /run/user/1000/*, and took a guess that it could be open files or mount points (or both) interfering with things.

Since the mount points live in /media/, I tried again with:

The same two warnings, but this time it returned additional info:

bash 4350 myusername cwd DIR 8,21 4096 1048577 /media
sudo 36302 root cwd DIR 8,21 4096 1048577 /media
grep 36303 myusername cwd DIR 8,21 4096 1048577 /media
lsof 36304 root cwd DIR 8,21 4096 1048577 /media
lsof 36305 root cwd DIR 8,21 4096 1048577 /media

Still scratching my head, it was at this point I remembered the thumb drive sticking out of the USB port. Maybe the scratching helped.

So I unmounted the thumb drive partitions (unmounting one automatically unmounted the other) and safefly unplugged the thumb drive. After doing so, I was able to unmount /dev/sda1 (having nothing mounted on it anymore), relabel it with gparted, remount both the drive and thumb drive with no issues whatsoever.
Bacon saved.

Источник

Оцените статью