Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Linux Forums > Linux - General
User Name
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.


  Search this Thread
Old 04-06-2004, 10:22 PM   #1
Registered: Aug 2003
Location: Lewisville, TX
Distribution: Kubuntu
Posts: 295

Rep: Reputation: 30
Manually remounting cd-rom drive stinks...

Ok, I went and got the 2.6.5 kernel from, but yea of course supermount doesn't come with it. So anyways, I don't feel like downloading kernel-tmb-source (which has supermount) and recompiling (not right now, at least...)

So what I would like to do is have a shell script that does the following:

fuser /mnt/cdrom
(then it 'grabs' the process # and stores it in, say, $cd)
kill $cd
umount /mnt/cdrom
That would eject the CD rom no matter what. I want it to see if there is a CD in the drive before it tries to eject it, if so then it ejects. And if there is no CD in the drive, then it does:

eject -t
mount /dev/cdrom /mnt/cdrom
Is this more trouble than it's worth? Should I just go ahead and spend the time compiling another kernel and reinstalling the NVidia drivers?
Old 04-07-2004, 05:21 AM   #2
Registered: Jul 2003
Location: Brighton, Michigan, USA
Distribution: Lots of distros in the past, now Linux Mint
Posts: 748

Rep: Reputation: 31
For something like this, (and to make it easily accessible to whomever, even remotely) you could use a script (using grep/awk/etc.) that checks the output from 'df'. If there is an entry for /dev/cdrom (or whatever you cdrom is), then eject. If there isn't, there isn't likely to be a disk in the drive. This is simple, but has a flaw. If your drive is a cdrw, it won't eject if there's a blank disk in the drive. To overcome this flaw, you need to know a little more about how cd drives work, and then it becomes one of those "if you know this much, you wouldn't be posting this question" kind of things. Then again, you won't typically need a supermount function for a blank disk.

For the simple version, just grep 'df' for '/dev/cdrom' or whatever your device is, and place the result into a variable. Test it to see if it's 'true' or not. If you get no result (no /dev/cdrom in df list), it will be false, any mounted cdrom will return true.

One caveat: Some oddball scripting languages invert true and false (t=0/null, false=anything else). If you're using one of them, you probably already know this, though.
Old 04-07-2004, 08:30 AM   #3
Registered: Aug 2003
Location: Lewisville, TX
Distribution: Kubuntu
Posts: 295

Original Poster
Rep: Reputation: 30
Yep I know about the true/false issue, lol.

I code in PHP, so not to sound incompetent or anything, but what exactly is the code for what you are talking about?

$cd = grep | df /dev/cdrom
if ($cd = 0) umount /mnt/cdrom
else eject -t
mount /mnt/cdrom

As you can see, I don't code in shell, LOL! So yea, if you could just edit that code or just give me the working one, that would be good. Oh, anything for grabbing the process ID and killing it?

Thanks so much!


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 On
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
cd-rom drive working in knoppix Hard drive installation dj_dubbbz Linux - Newbie 5 03-02-2004 11:58 AM
burning cd's in linux stinks illtbagu Linux - Software 8 12-11-2003 02:50 PM
manually entering drive geometry artofluke Slackware 1 12-08-2003 03:06 AM
SuSe 8.2 - remounting CD drive James_N Linux - Newbie 1 08-31-2003 12:25 AM
http, red hat 9.0 stinks illtbagu Linux - Newbie 7 04-22-2003 11:27 AM > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 09:42 PM.

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