In our previous tutorial I have explained the concepts of mounting and unmounting the filesystems, Now let us see how to unmount a busy filesystem …In Linux/Unix If a device is reporting busy then it won’t let you bring the device to inactive state, the file system will report busy (umount /dev/***: device is busy)when you try to unmount that it could be due to various reasons,
1.When more users are accessing that filesystem.
2.Any media mounted in that mount point(CD/DVD/FLOPPY/USB).
So bringing those filesystems to Unmount state without any data loss is the challenging for most of the system admins.
We have a utility called “fuser” it helps us to unmount a busy filesystem without any data loss.
What is meant by fuser?
fuser helps us to identify the processes that are currently accessing the filesystem by giving the owner name for the processes, the process id number and much more…With this utility, we can also apply the options to get the brief details from the fuser output.Here are some of the important options we use frequently with the fuser utility.
Options:
k – Kill the process
c – Current Directory
e – Executable file being run
v – Verbose output
u – To get the username.
Let me show you how to unmount the busy filesystem with the help of “fuser” utility.
Syntax:
#fuser
or
#fuser
Ex:1 Unmount the busy filesystem.
On my disk I have a filesystem /dev/sda2 and it is mounted on the mount point directory /home, As all, we know /home is the default home directory for the normal user logins Let me first log in to the server as a normal user(nirmal), then after that as a root user I will try to unmount the /home filesystem ,obviously it will give you the output as the “Device is busy” as all the initialization files will run from this directory to create the user login desktop.
Check the mounted filesystem details
#df -h
From the above output, the filesystem /dev/sda2 is mounted on the directory /home
Umount the /dev/sda2 filesystem
You can either use device name or mount point directory to unmount
The above output says the device is busy since it is accessing by some process, Now check how many processes currently occupying the filesystem.
Identify the processes occupying the current directory
#fuser -c /home
From the above output the numerical value indicates the “PROCESS ID” and character “c” means the “Current Directory”, so currently, two processes are running on the filesystem, Now let us try to kill the processes that are occupying the current mount point directory by running the following syntax,
#fuser -ck /dev/sda2
k –>kill
Check whether the running process successfully killed or not,
#fuser -c /dev/sda2
From the above output it is confirmed all the process killed by the fuser, Now try to unmount the filesystem
#umount /dev/sda2
Now this time you will not see the device busy error
Now confirm /dev/sda2 is unmounted or not by running the following command
#df -h
From the above output, the filesystem /dev/sda2 successfully unmounted.
Ex:2 Display all the Processes that are using the current Directory
#fuser .
Here “.” indicates the current working directory
From the above output, we can see more processes are occupying the current directory.
Ex:3 Check with the -v verbose output
#fuser -v .
The output now displayed the owner name of the process, PID and much more in a separate column.
Note: You can also use the -u option with the “fuser” command to get the owner list for all the processes that are occupying your current directory
#fuser -cu /home
Ex:4 Display which Processes using the executable
In this example let me try open the firefox page on my server by using the command “firefox”and after that let uscheckwhether “fuser” identifies the executable file path from this firefox program.
#firefox
Now, I will get the path for the executable program(firefox) by running the following command,
#ps -aef |grep firefox
From the output the first line shows the executable path for the Firefox, we will use this path with the fuser now,
#fuser /usr/lib64/firefox-3.6/firefox
The output shows the PID of the process and “e” indicates the file is an executable one.
Ex:4 Umount the filesystem with “-f” option
You can also unmount a busy filesystem with the -f option(forcefully), But remember running the following command will put your filesystem in maintenance state or data loss also may occur as it will forcefully kill the running process ,So it is highly recommended before you test this in your production box take a full back up of the particular filesystem so that if any data loss occurs you can restore it back later .
Note: Programs which access the files will get an error after unmounted with -f option.
Comments
Post a Comment
If you any doubt , Please let me know