I have several closely related questions about what happens when I insert a CD. The files on the CD /media/Ubuntu 11.04 i386/, but from what I’ve seen /dev/cdrom is also involved.
-
What is the difference between
/dev,
/mediaand/mnt? Following is what I
have found from internet but I still
have little idea:/dev— this folder contains device
files/media— this is a mount point for
removable devices/mnt— this is a temporary mount point
-
What is the purpose of
mount? In
other words, if a device has been
represented by the OS as a device
file under/dev, why can it not be
accessed via the device file
directly without mounting?Is mount only used for storage device, not for non-storage device, such as graphical card, network card, camera, …?
-
Where is a device file under
/dev
mounted to, under/mediaor under
/mnt? I remember I have seen
both, but am curious when
to mount to which? -
I found my CD was automatically
mounted to/media/Ubuntu 11.04 i386.
I guess the device file of the CD is
/dev/cdrom, but I cannot confirm it
by looking into/dev/cdromand
/media/Ubuntu 11.04 i386:$ ls -l /media/Ubuntu 11.04 i386/ total 3522 -r--r--r-- 1 Tim Tim 143 2011-04-27 13:04 autorun.inf ... $ ls -l /dev/cdrw lrwxrwxrwx 1 root root 3 2011-05-28 15:12 /dev/cdrw -> sr0 $ ls -l /dev/cdrom lrwxrwxrwx 1 root root 3 2011-05-28 15:12 /dev/cdrom -> sr0
How can I find out which device file is for my CD?
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
There are a lot of questions here and I’ll do my best to answer them. I’m certain that those more knowledgeable than I will be able to help you further. (I’d appreciate if those people could help me out too.)
In *nix, everything is a file. For example, your CD-ROM is a file.
/dev– Here you’ll find physical devices as well as things you wouldn’t normally think of as devices such as /dev/null./media&/mntare directories where you may mount a physical device such as a CD-ROM, HDD partition, USB stick, etc.
The purpose of mount (and the opposite umount) is to allow dynamic mounting of devices. What I mean here is that perhaps you may want to only mount a device under certain circumstances, and at other times have it not readily accessible. You may wish to mount an entire file system at /mnt when repairing a system. You may wish to mount a disc image (e.g. foo.iso) from time to time. Etc.
You may choose to mount a device in /dev at either /media or /mnt. There are more or less correct ways of doing this. For example, from your question you say:
/media this is a mount point for
removable devices/mnt this is a temporary mount point
That’s pretty much correct. Read here for how /media and /mnt should be used according to the Filesystem Hierarchy Standard. I do this pretty incorrectly, opting to use /media when in fact I should be using /mnt, most of the time. It’s also worth noting that an internal HDD with associated partitions may be referred to, somewhat confusingly, removeable media.
I’m on OS X here so I can’t check right now (BSD does things slightly differently regarding optical drives) but /dev/cdrom is a device file for your CD-ROM. As is /dev/cdrw. See the ‘->’ in the ls -l output in your question? That’s indicating that both /dev/cdrom and /dev/cdrw are symbolically linked to /dev/sr0. ‘sr‘ is the device driver name; ‘sr0’ is the device file name.
/media/Ubuntu 11.04 i386 is simply an .iso image that has been auto-mounted at /media.
I hope that helps a bit.
Method 2
The answer from boehj explains the basics pieces in play here. The one thing I would add is about the difference between a device and a mounted file system. The fact of the matter is that you can access a device node directly. For example you could use dd if=/dev/sda of=/dev/sdb to make your second ATA device an exact copy of the first one, or you can cat /dev/sr0 > mycd.iso to rip a CD and make an iso image of it.
The difference is that when you mount a device to a location, you create a path in your directory structure that accesses the device using a file system driver. The file system driver handles things all the special things that need to happen like caching, indexing, seeking, etc in order for your raw drive device to appear to you with all the conveniences of a file system.
Method 3
Building on boehj’s answer, mount is used behind the scenes at boot time to check in /etc/fstab to see where each existing partition that it’s supposed to know about should be mounted into the actual filesystem.
Unlike with – for instance – Windows, where you don’t get much of a choice beyond what drive letter a partition gets, this allows any device or partition to be mounted anywhere in the filesystem tree if you so wish — for example, university network computers would typically only have /bin/ and /lib and a few temporary partitions mounted locally, while /usr/ (containing almost all of the software that isn’t required during the boot phase) and /home/ (containing all users’ home directories) would be mounted from a centrally accessible NFS server.
It’s also responsible for quietly mounting various temporary and virtual filesystems such as /dev/shm/, /sys/, /dev/pts/, and on more modern systems /run/. Chances are you’ll rarely if ever do anything directly with these, but a lot of software relies on these to exist behind the scenes. Take a look at the output of the bare mount command, or in /etc/fstab — you might learn something interesting.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0