Wiki source code of Fixing 'Umount Target is Busy' Error in Linux
Last modified by Сергей Коршунов on 2023/06/08 18:51
Show last authors
author | version | line-number | content |
---|---|---|---|
1 | Unmounting disks in the Linux command line is not complicated. All you have to do is to use the umount command: | ||
2 | |||
3 | {{{umount target}}} | ||
4 | |||
5 | But once in a while, you'll come across an error that says **'umount: target is busy'**: | ||
6 | |||
7 | [[~[~[image:https://linuxhandbook.com/content/images/2023/03/target-is-busy-while-unmounting-the-drive-in-Linux.png~|~|alt="target is busy while unmounting the drive in Linux" height="151" width="837"~]~]>>url:https://linuxhandbook.com/content/images/2023/03/target-is-busy-while-unmounting-the-drive-in-Linux.png]] | ||
8 | |||
9 | So how are you supposed to solve this issue? | ||
10 | |||
11 | Well, before solving this issue, let me share the reason behind this problem first. | ||
12 | |||
13 | == The reason behind Umount target is busy == | ||
14 | |||
15 | The reason is quite simple! The target device is still in use. | ||
16 | |||
17 | 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. | ||
18 | |||
19 | == How to solve Umount target is busy in Linux == | ||
20 | |||
21 | ⚠️ | ||
22 | |||
23 | If an ongoing data transfer occurs in the background, you may lose your data by forcefully unmounting your drive. | ||
24 | |||
25 | 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. | ||
26 | |||
27 | In this tutorial, I will share three ways to unmount the target: | ||
28 | |||
29 | * By killing the process itself | ||
30 | * Using force unmount | ||
31 | * Using the lazy unmount | ||
32 | |||
33 | Let's start with the first method. | ||
34 | |||
35 | === Method 1: Unmout target by killing the process itself (recommended) === | ||
36 | |||
37 | This is the best way of unmounting the target in my opinion as you are eventually killing the process itself. | ||
38 | |||
39 | The first step is to [[find the PID of the process>>url:https://linuxhandbook.com/find-process-id/]] that causes the problems. | ||
40 | |||
41 | To do so, I will be [[using the lsof command>>url:https://linuxhandbook.com/lsof-command/]] in the following manner: | ||
42 | |||
43 | {{{sudo lsof /Path/to/target}}} | ||
44 | |||
45 | [[~[~[image:https://linuxhandbook.com/content/images/2023/03/find-PID-of-the-mounted-drive-1.png~|~|alt="find PID of the mounted drive" height="276" width="896"~]~]>>url:https://linuxhandbook.com/content/images/2023/03/find-PID-of-the-mounted-drive-1.png]] | ||
46 | |||
47 | Once you get the PID, it's quite simple to [[force kill the process>>url:https://linuxhandbook.com/kill-process/]]: | ||
48 | |||
49 | {{{sudo kill -9 [PID]}}} | ||
50 | |||
51 | And now, you should be able to unmount the drive easily: | ||
52 | |||
53 | [[~[~[image:https://linuxhandbook.com/content/images/2023/03/kill-the-process-and-unmount-the-drive.png~|~|alt="kill the process and unmount the drive" height="152" width="896"~]~]>>url:https://linuxhandbook.com/content/images/2023/03/kill-the-process-and-unmount-the-drive.png]] | ||
54 | |||
55 | Pretty neat way. Isn't it? | ||
56 | |||
57 | === Method 2: Using force unmount (for Network File Systems) === | ||
58 | |||
59 | The force unmount option is mainly preferred by those who are dealing with network file systems. | ||
60 | |||
61 | So **it may NOT give you the expected results with your local file system.** | ||
62 | |||
63 | To use the force unmount, you will have to use the same old umount command but with the -f flag: | ||
64 | |||
65 | {{{sudo umount -f /Path/to/target}}} | ||
66 | |||
67 | [[~[~[image:https://linuxhandbook.com/content/images/2023/03/use-force-unmount-to-solve-target-is-busy-error.png~|~|alt="use force unmount to solve target is busy error" height="167" width="837"~]~]>>url:https://linuxhandbook.com/content/images/2023/03/use-force-unmount-to-solve-target-is-busy-error.png]] | ||
68 | |||
69 | === Method 3: Using the lazy unmount (Schrödinger's unmount) === | ||
70 | |||
71 | 📄 | ||
72 | |||
73 | 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! | ||
74 | |||
75 | It is more of a Schrödinger's mount when you can never be sure of whether the filesystem is unmounted or not! | ||
76 | |||
77 | So why am I even adding this to the solution's list? Well, this is the least harmful way of unmounting your stubborn drive. | ||
78 | |||
79 | To use the lazy unmount, you will have to use the -l flag with the umount command as shown: | ||
80 | |||
81 | {{{sudo umount -l /Path/to/target}}} | ||
82 | |||
83 | [[~[~[image:https://linuxhandbook.com/content/images/2023/03/using-the-lazy-unmount-to-solve-the-target-is-busy-in-linux.png~|~|alt="using the lazy unmount to solve the target is busy in linux" height="167" width="837"~]~]>>url:https://linuxhandbook.com/content/images/2023/03/using-the-lazy-unmount-to-solve-the-target-is-busy-in-linux.png]] | ||
84 | |||
85 | And here you have it! |