Linux umount target is busy

How to fix the error “umount target is busy”

Attaching and removing storage devices from your system is a crucial part of data transfer in any computer. In Linux, the mount and unmount keywords are provided, which will add or remove certain storage components or even file systems. These commands can help to switch between various storage devices. For example, you can unmount a certain storage device and mount another one to use it. Oftentimes, while attempting to unmount a device, the “umount target is busy” problem can be invoked.

This article will guide you on why this problem arises and how it can be dealt with easily.

How to Resolve the “umount target is busy” Issue?

The reasons behind this problem can relate to the working of this command. This section will not only elaborate on why this error occurs but will also help you resolve it.

Reason: The Device is in Use

There are many different processes that have enough permissions to be able to access any storage device at any time. Due to this, the device is accessed the majority of the time. If a device is being accessed and the user tries to unmount the device, it will prompt the error mentioned above. This happens because if the device is unmounted during its use, there is a chance of some data being lost. To prevent that from happening, the error will be invoked, and the device will not be unmounted.

Let’s have a look at how this issue can be fixed.

Solution 1: Unmount Forcefully

The first solution is to try to unmount the device forcefully. It needs to be noted that this method should only be applied when there is no sensitive data on the device because this process has a chance of causing data loss. To unmount the device forcefully, run the following command:

Where “-f” is used to force the unmount, and the “device-path” is the directory path of the device.

Solution 2: Stop the Active Process

As discussed above, an active process may be causing the error “unmount target is busy”. We simply need to stop the active process occupying the device to fix it. Use the command below to access the process list of the device:

Читайте также:  Error 2002 hy000 mysql linux

Running this command will return all the processes surrounding that device.

The next step is to note down their process ID. The snippet below shows sample PIDs:

Note down the process-id and terminate the process using the command shown below:

Using this command, you can terminate all the processes that are attached to the device. After this, the error will not occur, and you can successfully unmount the device.

Solution 3: Lazy Unmount

It is a combination of both the methods mentioned above and is effective among all. In lazy unmount, the system will forcefully unmount the device but in a methodical way. Using this way, the system will slowly remove all the processes attached to the device that is not in use. To achieve this, use the following command:

The “l” represents the lazy unmount in the device.

Using any of these methods, the problem “umount target is busy” can be fixed easily.

Conclusion

The “umount target is busy” issue occurs due to the device being in use by various processes at the time of unmounting. The problem can be resolved in 3 ways. The first is to forcefully unmount the device, which risks the loss of data. The second way is to find and eliminate each process individually. The third way is to do a lazy unmount, which will automatically remove all ideal processes and then unmount the device. This article has provided a detailed guide on the reasons behind this error and has proposed a list of solutions as well.

TUTORIALS ON LINUX, PROGRAMMING & TECHNOLOGY

Источник

Fixing ‘Umount Target is Busy’ Error in Linux

A not-so-uncommon error while using umount command is ‘target is busy’. Learn what you can do to get rid of this error.

Unmounting disks in the Linux command line is not complicated. All you have to do is to use the umount command:

But once in a while, you’ll come across an error that says ‘umount: target is busy’:

target is busy while unmounting the drive in Linux

So how are you supposed to solve this issue?

Well, before solving this issue, let me share the reason behind this problem first.

The reason behind Umount target is busy

The reason is quite simple! The target device is still in use.

With enough permissions, any process might be utilizing that drive that you want to unmount, and to prevent data loss, the kernel won’t allow you to unmount.

How to solve Umount target is busy in Linux

If an ongoing data transfer occurs in the background, you may lose your data by forcefully unmounting your drive.

Читайте также:  Подключение серверу терминалов linux

There are times when you want to unmount the drive at any cost. Perhaps the drive isn’t responding for some reason and you want to unmount it.

In this tutorial, I will share three ways to unmount the target:

Let’s start with the first method.

Method 1: Unmout target by killing the process itself (recommended)

This is the best way of unmounting the target in my opinion as you are eventually killing the process itself.

The first step is to find the PID of the process that causes the problems.

To do so, I will be using the lsof command in the following manner:

find PID of the mounted drive

Once you get the PID, it’s quite simple to force kill the process:

And now, you should be able to unmount the drive easily:

kill the process and unmount the drive

Method 2: Using force unmount (for Network File Systems)

The force unmount option is mainly preferred by those who are dealing with network file systems.

So it may NOT give you the expected results with your local file system.

To use the force unmount, you will have to use the same old umount command but with the -f flag:

sudo umount -f /Path/to/target

use force unmount to solve target is busy error

Method 3: Using the lazy unmount (Schrödinger’s unmount)

This option does not actually unmount your target but just removes the target from the namespace. And will unmount the target when the drive is not being utilized anymore!

It is more of a Schrödinger’s mount when you can never be sure of whether the filesystem is unmounted or not!

So why am I even adding this to the solution’s list? Well, this is the least harmful way of unmounting your stubborn drive.

To use the lazy unmount, you will have to use the -l flag with the umount command as shown:

sudo umount -l /Path/to/target

using the lazy unmount to solve the target is busy in linux

Which one should you choose?

In times like you have to have your drive unmounted, I would prefer going with the 1st method which involves killing the process itself.

And there is a strong reason why. It gets my job done without any hiccups.

Sure, you may want to go with either of the last two options based on your use case.

Источник

Umount Target is Busy

“In Linux, we use the umount command to unmount a device or partition as specified by its path. However, in some scenarios, you may encounter the “target is busy” error when attempting to unmount a device.

In this tutorial, we will attempt to break down the cause of this error, why it occurs, and how you can resolve it.”

Cause of “Target is Busy” Error

Once you mount a device in your system, any process with sufficient permission can access its filesystem. When the “target is busy” error occurs, it means that an active process is currently accessing a file or directory within the device.

Therefore, to prevent data loss, the Linux kernel will prevent you from unmounting the device when it’s being accessed.

Читайте также:  Arch linux deb или rpm

But there are some instances where you need to remove the device. Let us discuss the various techniques you can use to do this.

Fix 1: Terminate the Running Process

We have established that the main cause of this error is an active process that is accessing a file within the device.

Therefore, to resolve this error, we can terminate the process, and the device will be free to be mounted.

Luckily, Linux has a command that allows you to show all the view the open files and the processes that are accessing that file.

You can learn more about about the lsof command here:

We can use the lsof command followed by the path to the disk. For example, if we are getting the error in device /dev/sda1, we can view the open files and the associated processes using the command:

The command should return the processes accessing the files are their IDs.

We can then take the PIDs and use them to kill the process.

Once the process is terminated, you can unmount your device.

Keep in mind that there may be more than one process accessing a file. Hence, ensure to terminate all of them.

Fix 2: Force Unmount

Another solution for unmounting a busy device is to force it. This can be useful if the error is caused by an unreachable resource such as a network resource.

Keep in mind that force unmounting a device can lead to data loss.

To do this, use the -f option as:

Fix 3: Lazy Unmount

The third and safer alternative to the force unmount is a lazy unmount. A lazy unmount allows the system to detach the specified mount point in a hierarchical manner. It works by removing any references to the filesystem as soon as it’s not busy.

And once no process is accessing the fs, the system runs the unmount command successfully and removes the device.

This is a safe option as you do not forcibly close any running processes. Instead, you allow the system to monitor once the operations are complete and then unmount the device.

To use a lazy unmount, use the -l flag in the umount command:

Conclusion

That’s it for this one. In this tutorial, we covered the cause of the “target is busy” error when unmounting devices in a Linux system. We also provided three solutions for unmounting the device appropriately.

As always, thanks for reading!!

About the author

John Otieno

My name is John and am a fellow geek like you. I am passionate about all things computers from Hardware, Operating systems to Programming. My dream is to share my knowledge with the world and help out fellow geeks. Follow my content by subscribing to LinuxHint mailing list

Источник

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