View the Most Wanted LQ Wiki articles.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 08-13-2006, 06:51 PM   #1
LQ Newbie
Registered: Aug 2006
Distribution: Kubuntu
Posts: 5

Rep: Reputation: Disabled
How to detect CD/DVD drives on Linux

How do you get the device name of the CD/DVD drive?

I'm writing a CD/DVD burning script for non-technical users and I need to show which drives are available, and get the device name which is passed to growisofs (DVDs).

For CDs I used to use "cdrecord -scanbus", but this is not working for me under 2.6 kernels. Anybody know why?

Many Thanks.
Old 08-13-2006, 08:17 PM   #2
Senior Member
Registered: Dec 2005
Location: Indiana
Distribution: RHEL/CentOS/SL 5 i386 and x86_64 pata for IDE in use
Posts: 4,790

Rep: Reputation: 56
Nope, works for me maybe something with your version of cdrecord or your configration, besides this seems to work also;

$ ls -al /dev/cdrom
lrwxrwxrwx 1 root root 3 Aug 13 19:48 /dev/cdrom -> hdc
[lenard@Aspire5000 ~]$ ls -al /dev/dvd
lrwxrwxrwx 1 root root 3 Aug 13 19:48 /dev/dvd -> hdc

$ cdrecord -scanbus
Cdrecord-Clone 2.01-dvd (--) Copyright (C) 1995-2004 Jörg Schilling
Note: This version is an unofficial (modified) version with DVD support
Note: and therefore may have bugs that are not present in the original.
Note: Please send bug reports or support requests to
Note: The author of cdrecord should not be bothered with problems in this version.
scsidev: 'ATA'
devname: 'ATA'
scsibus: -2 target: -2 lun: -2
Linux sg driver version: 3.5.27
Using libscg version 'schily-0.8'.
cdrecord: Warning: using inofficial libscg transport code version (schily - Red Hat-scsi-linux-sg.c-1.83-RH '@(#)scsi-linux-sg.c 1.83 04/05/20 Copyright 1997 J. Schilling').
1,0,0 100) 'HL-DT-ST' 'DVD-RW GCA-4080N' '0H38' Removable CD-ROM
Old 08-13-2006, 08:28 PM   #3
Registered: Oct 2003
Distribution: Gentoo, Mint, Ubuntu, Vector
Posts: 149

Rep: Reputation: 15
cdrecord dev=ATA -scanbus
Old 08-14-2006, 01:17 AM   #4
LQ Newbie
Registered: Aug 2006
Distribution: Kubuntu
Posts: 5

Original Poster
Rep: Reputation: Disabled
Thanks, "dev=ATA" just tried to get /dev/hda and gave up. However, that gave me an idea:

cdrecord dev=ATAPI -scanbus

This worked as expected, listing all devices :-)

Can anybody explain why? I need a machine independent method. My script will run on a live CD, so cdrecord will be the same and the environment, but what about different hardware?


(I'm running Kubuntu Dapper. I think this is a Debian issue because I've also had it happen with 2.6 kernels on Knoppix.)
Old 08-14-2006, 03:07 AM   #5
Registered: Feb 2004
Location: Switzerland
Distribution: Fedora - RedHat - Mandrake - OpenSuse
Posts: 216

Rep: Reputation: 35
hwo about if you try "hwbrowser" (with root permission).

It should give you a pretty good idea of what is on your system.

Old 08-15-2006, 06:16 PM   #6
LQ Newbie
Registered: Aug 2006
Distribution: Kubuntu
Posts: 5

Original Poster
Rep: Reputation: Disabled
"hwbrowser" seems to be a GUI app. I don't think I could call it from a script, could I?

(I'm running Kubuntu, and there's no hwbrowser package compiled, so I can't just try it out without building from source.)
Old 08-15-2006, 06:25 PM   #7
LQ Guru
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 6,520

Rep: Reputation: 1774Reputation: 1774Reputation: 1774Reputation: 1774Reputation: 1774Reputation: 1774Reputation: 1774Reputation: 1774Reputation: 1774Reputation: 1774Reputation: 1774
What I would do is ... look at the mtab to see what's mounted. Maybe the fstab to see what could be mounted. Look for things like "cdrom" in there.

Remember... your guiding assumption in Unix software must be that the user is not root, cannot be root, and never will be. You have no way of knowing what sort of system you're running on, nor what sort of devices you might be given access to. This is entirely different from the usual (still...) behavior of Windows software, where darn-near-everything is highly privileged and assumes that it must be so. Assume that you are not running on a "personal" computer!
Old 08-15-2006, 07:36 PM   #8
Registered: Aug 2002
Posts: 14,077

Rep: Reputation: 1298Reputation: 1298Reputation: 1298Reputation: 1298Reputation: 1298Reputation: 1298Reputation: 1298Reputation: 1298Reputation: 1298
It depends on the kernel, distribution and the version of cdrecord.
With 2.4 kernels its 'cdrecord -scanbus' and 2.6 kernels its 'cdrecord dev=ATAPI -scanbus' However, some distributions have modified cdrecord so -scanbus and dev=ATAPI -scanbus both work with a 2.4 kernel. I have a 2.4 kernel knoppix liveCD with ide-scsi module loaded and both methods work.

With the 2.6 kernel you can specify the device as dev=/dev/hdc instead of dev=0,0,0
And with the 2.6 kernel hdx=ide-scsi is no longer required.


cd, dvd

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
FC3 install DVD fails to detect SATA drives Bagatur Fedora - Installation 4 02-05-2007 09:59 AM
DVD decrypter can not detect dvd drive through Wine lnthai2002 Linux - Software 2 01-15-2006 08:36 PM
DVD-RW drives, do they all work with Linux? Ricky Newbie Linux - Hardware 2 12-14-2005 11:41 AM
Help, I can't detect all my SATA drives ofdofd Linux - Hardware 0 10-02-2004 02:58 AM

All times are GMT -5. The time now is 08:22 AM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration