Why does Linux need to have both `/dev/cdrom` and `/media/cdrom`?

/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)


(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.)


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.