On a headless Linux server (latest fedora if this is of interest), how can I detect that the inserted optical disk is an audio disk, as opposed to a data disk or a video DVD? There is no desktop environment installed, and I would prefer not to install one.

What I can see is that mounting fails, but I guess that could also be the case for a corrupt data disk:

[root@server ~]# mount /dev/sr0 /mnt/cdrom
mount: /dev/sr0 is write-protected, mounting read-only
mount: /dev/sr0: can't read superblock
[root@server ~]# echo $?

Any suggestions?


A way to achieve this is to use the cdparanoia command line tool. In Ubuntu Linux you can install it through

sudo apt install cdparanoia

then run

cdparanoia -Q

Where "-Q" stands for "query". If there's no audio disc in the drive, you'll get

cdparanoia III release 10.2 (September 11, 2008)
004: Unable to read table of contents header
Unable to open disc.  Is there an audio CD in the drive?

Otherwise it'd look like...

Table of contents (audio tracks only): track        length             begin        copy pre ch
  1.     8315 [01:50.65]        0 [00:00.00]    no   no  2
  2.    12830 [02:51.05]     8315 [01:50.65]    no   no  2
  3.    15642 [03:28.42]    21145 [04:41.70]    no   no  2
  4.    16238 [03:36.38]    36787 [08:10.37]    no   no  2
| improve this answer | |
  • If you want to use it in a script, redirect stdout and stderr to /dev/null, and use the return value - 0 (success) if there's a disk, or non-zero (failure) otherwise. – Toby Speight Apr 28 '16 at 16:06

How can I detect if an inserted optical disk is an audio disk?

checkforaudio=`gvfs-info -f cdda://sr0/ | grep "filesystem::type: cdda"`
if [ "$checkforaudio" == "  filesystem::type: cdda" ]; then
    vlc cdda:///dev/sr0
        checkfordvd=`find /media/*/ -name "VIDEO_TS" | grep "VIDEO_TS"`
        if [ ${checkfordvd:(-8)} == "VIDEO_TS" ]; then
            vlc dvd:///dev/sr0
exit 0

Source http://ubuntuforums.org/showthread.php?t=1911452

| improve this answer | |
  • I actually knew the source, but was under the false impression that gvfs-info requires gnome, as it its part of the gnome project. It turns out that gvfs-client (the package containing gvfs-info in fedora) installs without the rest of gnome, so yours is certainly a great answer. However, sind I will need cdparanoia anyway in my project (plus it is much smaller), I will accept the other answer. – Isaac Apr 28 '16 at 17:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.