LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 12-08-2004, 05:31 AM   #16
Moebius
Member
 
Registered: Dec 2002
Location: Milwaukee, WI
Distribution: Ubuntu, Kubuntu, Debian, CentOS
Posts: 216

Original Poster
Rep: Reputation: 30

OK, I wrote a shell script that should be user-friendly enough and should take care of every option. Copy/paste the code below into a text editor and save it as smartumount in your /usr/bin dir (as root) make sure it's executeable by using the command "chmod +x /usr/bin/smartumount"

First the script tries to umount the drive normally. It that fails, it tries to restart famd which is the most common problem. If that fails it tries to restart xinetd. If that fails it uses the command "fuser -ki <your-unmountable-drive>" which asks you if you want to kill each process that's using that folder. Be careful with this - you should know what each process is before you kill it. If that fails, probably because you didn't kill all the processes, it asks you if you want lazily unmount the volume, which removes the drive even though processes are still using it. I'm no expert, so let me know if I should make any improvements. Feel free to post this wherever you want.

USAGE:
smartumount folder-to-unmount

Example:
smartumount /mnt/ipod

Note: you might have to change the path to init.d for your distro. For example you might need to change every instence of "/etc/init.d" to "/etc/rc.d/init.d"

Code:
#!/bin/bash

if [ `whoami` != "root" ]; then
	echo "You must run this as root"
	exit
fi

dir=$1

# first try unmounting it without doing anything special
testumount=`umount $dir 2>&1`
if [ `echo $testumount | grep "not mounted" | wc -l` -gt 0 ]; then
	echo "$dir isn't mounted, exiting"
	exit
fi

if [ `echo $testumount | grep busy | wc -l` -gt 0 ]; then
	echo "Having trouble, checking famd..."
else
	echo "unmounted $dir without any trouble..."
	exit
fi

# check famd
if [ `ps -e |grep famd|wc -l` -gt 0 ]; then
	/etc/init.d/famd restart
	# try unmounting again
	if [ `umount $dir 2>&1 | wc -l` -gt 0 ]; then
		echo "I tried restarting famd, but that didn't work. checking xinetd"
	else
		echo "Unmounted $dir by restarting famd"
		exit
	fi
else
	echo "famd isn't running so it couldn't be that.."
fi


# check xinetd
if [ `ps -e | grep xinetd | wc -l` -gt 0 ]; then
	/etc/init.d/xinetd stop
	# try unmounting again
	if [ `umount $dir 2>&1 | wc -l` -lt 1 ]; then
		/etc/init.d/xinetd start
		echo "Unmounted $dir by restarting xinetd"
		exit
	fi
	/etc/init.d/xinetd start
	echo "I tried stopping xinetd, but that didn't work."

else
	echo "xinetd isn't running so it couldn't be that.."
fi

echo
echo "I'm going to list processes that are using the folder you are 
trying to umount. Answer whether you'd like to kill them or not. 
You should look up each process before you answer. Use the 
following command in a separate shell:"
echo
echo "	ps -e | grep <pid>"
echo
echo "where <pid> is the number of the process."
echo
fuser -ki $dir
echo
if [ `echo $testumount | grep busy | wc -l` -gt 0 ]; then
	echo "OK, this is the last resort. Do you want to umount the volume using "
	echo "the -l option? According to the umount man page -l means:"
	echo
	echo "	Lazy unmount. Detach the filesystem from the filesystem 
	hierarchy now, and cleanup all references to the filesystem as 
	soon as	it is not busy anymore.  (Requires kernel 2.4.11 or later.)"
	echo
	echo "Use -l option? (y\n)"
	read yn
	if [ $yn == "y" ]; then
		umount -l $dir
	else
		echo "OK. Sorry I couldn't help"
	fi
else
	echo "You're all good :)"
fi

exit

Last edited by Moebius; 12-08-2004 at 05:40 PM.
 
Old 12-08-2004, 10:32 AM   #17
Superme
Member
 
Registered: Jul 2004
Location: Smiths Falls Ontario (near ottawa [our capital])
Distribution: slackware 9.1, redhat 9.0, PHLAK, SuSE 9.0Pro windows XP (HEAVILY MODIFIED)
Posts: 111

Rep: Reputation: 15
if you are on kde try using diskslim and right click on the drive and go to un mount this usually can force an unmount safely
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
umount :device busy Pedroski Linux - Hardware 14 12-29-2004 03:37 PM
fam and umount says device is busy Brian1 Fedora 2 10-05-2004 07:33 PM
umount /var device busy winchester169 Linux - Networking 1 06-25-2004 07:53 PM
umount: /mnt/floppy: device is busy tryangle Linux - Newbie 4 11-10-2003 10:16 PM
umount: /mnt/a5: device is busy PTBmilo Linux - General 2 01-31-2003 10:48 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 10:50 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration