Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This question already has an answer here:

Inspired by this question. Why does Linux need both /dev/cdrom and /media/cdrom?

Why not just access files on the cdrom through /dev/cdrom?

share|improve this question

marked as duplicate by Jakuje, Wouter Verhelst, Archemar, Gilles filesystems Mar 19 at 18:02

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

Why does it have both /dev/sda1 and /? – immibis Mar 19 at 5:55
@immibis Yes, there do exist some other ways to ask this question. Thanks for pointing it out. I didn't realize it at first. :) – smwikipedia Mar 19 at 10:07
up vote 41 down vote accepted

/media/cdrom is a convention for the mountpoint, while /dev/cdrom is the special device that could be mounted on the former.

You need both, because they serve different purposes: most applications do not read directly from the special device, but can read from a filesystem (something that is mounted)

share|improve this answer
I think @smwikipedia ask about why /dev/cdrom is not used as mountpoint, needing to mount it in another place. I used to think about this also in the past since it's already possible to mount a filesystem on top of a file (descriptor), maybe it's common to do otherwise for legacy reasons... – Piranna Mar 18 at 12:56
@Piranna Yes, you are right. I do want to know why not just directly use /dev/cdrom to access CDROM files, be it called mount point or whatever. – smwikipedia Mar 18 at 13:22
@ThomasDickey You said Most applications do not read directly from the special device. I think that's because a file system is easier to interact with than a raw block device. If so, I think my own answer is similar to yours. – smwikipedia Mar 18 at 13:51
If you're dealing with files and directories, then you need a file system and hence the mount point. If you are dealing with the raw data - like when CD burning or copying by dd - there may not be even a valid filesystem, so you need the device file. – rexkogitans Mar 18 at 14:25
@smwikipedia for the same reason /dev/sda1 may be mounted on /. – J.F. Sebastian Mar 19 at 14:32

(Thanks for so many answers to my question. After searching the web for a while, I want to share my own understanding.)

According to here:

In Unix-like operating systems, a device file or special file is an interface for a device driver that appears in a file system as if it were an ordinary file.

According to here:

The mount command serves to attach the filesystem found on some device to the big file tree.

So, I think there are 2 different levels of software abstraction here:

  • /dev/cdrom is a device special file. It abstract the CD-ROM hardware as a block IO device. This abstraction is provided by the device driver.

  • /media/cdrom is a mount point for a filesystem. So it provides a higher level of abstraction of the CD-ROM hardware, i.e. as a file system. Such as ISO-9660 file system. And this abstraction is provided by the file system driver.

So basically, 2 different file locations for 2 different levels of abstraction. And in different scenarios, we may need different one. I think other OS such as Windows also provide such different options only that Linux unifies it into a single file hierarchy.

(I guess maybe I should do some experiment by writing some C code on Linux to interact with both /dev/cdrom and /media/cdrom. And see how everything goes on.)

(I will keep learning and refine my understanding as appropriate.)

share|improve this answer
One final bit of info: the /dev/cdrom special file (and actually everything in /dev) is actually just a way to give a name and permissions to a pair of numbers that reference something in the magic parts of the kernel. If you know the magic numbers, the /dev files can be recreated using them eveneif they were deleted; take a look at the docs for the "mknod" command for more esotrica. – StarWeaver Mar 19 at 6:16
"I think other OS such as Windows also provide such different options only that Linux unifies it into a single file hierarchy." – Windows is very similar, actually. In Unix, everything is a file, and other kinds of objects (devices, kernel objects, …) are represented as files (e.g. in /dev, /proc, or /sys). There is a single file hierarchy, and objects form subhierarchies. In Windows, everything is an object, files are just special kinds of objects. There is a single unified object hierarchy, and filesystems form subhierarchies. But there are two distinct entities, just like in Unix: – Jörg W Mittag Mar 19 at 7:47
a device object for the CD-ROM drive, and a mount point for the filesystem on that CD-ROM. Not also that in modern Windows, the mount point no longer has to be a drive letter, it can be mounted anywhere inside another filesystem, just like in Unix. – Jörg W Mittag Mar 19 at 7:48

Why do we have both /dev/cdrom and /media/cdrom?

Why do we have both /dev/sda2 and /home?

Basically, /dev/cdrom is a file. When you access it, you are accessing the individual bits and bytes on the CD (if there is one). Whereas /media/cdrom is a folder. When you access it, you are accessing the files stored on the CD.

Similarly, /dev/sda2 represents the raw contents of the second partition on the first harddrive. You would write to this directly, e.g., if you wanted to format the partition. (The mkfs program literally opens /dev/sda2 or whatever, and writes particular bit patterns onto it.) You then mount /dev/sda2 at, say, /home, and now you can access the actual files. As you access the files through the mount point, the filesystem driver is reading and writing the underlying device file.

This is just the way Unix does things.

share|improve this answer
Thanks for broadening my question. And the concise answer. – smwikipedia Mar 18 at 13:56
So I guess /media/cdrom is implemented on top of /dev/cdrom from a software perspective. Right? – smwikipedia Mar 18 at 13:57
@smwikipedia Pretty much, yes. – MathematicalOrchid Mar 18 at 14:01
Thanks for pointing out /dev/cdrom is a file while /media/cdrom is a folder. – smwikipedia Mar 18 at 14:27
"This is just the way Unix does things." No, in Unix, everything is a file scnr. On a more serious note though, in the Hurd, you do actually mount file systems by putting a translator on a device file that then presents itself as a folder with the content of the FS, even though it's just a process mediating the access to that single file (you still have the distinction between mount point and device file though). Hope that wasn't too confusing. – Christian Mar 18 at 14:41
  • You can see that /dev/cdrom is actually a block special file which is a device file.

    $ ls -l /dev/cdrom
    lrwxrwxrwx 1 root root 3 Mar 18 17:00 /dev/cdrom -> sr0
    $ ls -l /dev/sr0
    brw-rw----+ 1 root cdrom 11, 0 Mar 18 17:00 /dev/sr0
  • Visit Filesystem Hierarchy Standard:

    /media Mount points for removable media such as CD-ROMs (appeared in FHS-2.3).

    $ ls -ld /media/cdrom/
    drwxr-xr-x 2 root root 4096 Jun 15  2015 /media/cdrom/

    This directory contains subdirectories which are used as mount points for removeable media such as floppy disks, cdroms and zip disks.

So, /dev/cdrom and /media/crdom are totally different thing. one is a block/device file for CD-ROM whereas another is a directory for mounting it!

share|improve this answer

A good source of information that covers this (and more) can be found here https://en.wikipedia.org/wiki/Filesystem_Hierarchy_Standard

  • /media => Mount points for removable media such as CD-ROMs (appeared in FHS-2.3).
  • /mnt => Temporarily mounted filesystems.
share|improve this answer
You don't answer the part about /dev/cdrom - while the question doesn't reference /mnt. – maxschlepzig Mar 18 at 13:02

Why not just access files on the cdrom through /dev/cdrom

In addition to the answers already provided, you cannot use /dev/cdrom to access the cdrom content because mounting /dev/cdrom (the files present on the cdrom) on top of /dev/cdrom (the device) is a forbidden operation.

Under Linux, you can only mount a file system on top of an existing directory, not on top of an existing file or device.

Should the OS allow such an operation, a side effect would be accessing the original /dev/cdrom would no more be possible after the mount.

Should you really want to access your cdrom though /dev/cdrom, here is a hack that should work:

umount /media/cdrom
mv /dev/cdrom /dev/cdrom-org
mkdir /dev/cdrom
mount /dev/cdrom-org /dev/cdrom

Of course, there is no much point doing it.

share|improve this answer
Thanks for the deep analysis. – smwikipedia Mar 18 at 14:29

Linux device drivers are exposed as special files. Utilities/applications perform file operations on these files (ioctl calls) to control the devices.

One example of a utility that would make calls to a special file to control the device is "mount".

The mount utility is a program with the purpose to present the data on the cdrom device as a dir/file structure. This is a well understood and convenient way for users to use the data by simple reading it from the file structure that the mount utility created.

A cdrom device supports many other operations on the special file e.g. to open/close the tray etc.

Many special files used to control devices are stored in /dev to make it simple for developers/users of utilities to know where to look for it.

Furthermore, utilities that present data on devices (e.g. cdrom, sdcard, memory stick etc.) as a dir/file structure does so in /media to make it simple for developers/users to know where to look.

Both are therefore used for its own purpose.

share|improve this answer
It's helpful. I feel /dev is just like the Windows Device Manager. And thanks for pointing out A cdrom device supports many other operations on the special file e.g. to open/close the tray etc. – smwikipedia Mar 19 at 10:20

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