LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 03-05-2013, 07:04 PM   #1
Justin F
LQ Newbie
 
Registered: Jan 2013
Posts: 8

Rep: Reputation: Disabled
What does it actually mean to mount a filesystem?


Yeah, I know, total n00b question. But in all seriousness, I cannot figure out what it means to mount a filesystem. I just don't understand how / can be mounted from a subset of root (/dev/[device]). What I mean is, how can /dev/(device) be mounted to / when you have to go through / to get to /dev? It makes no sense, and all the searches I've done for it just don't explain it in terms I can understand.

I would appreciate it if someone could provide a better explanation for me that is dumbed down to "idiot's terms," so to speak.
What I'm looking for is what exactly mounting means. I want to know what it means, what it does, and how it affects the system.

Also, sorry if this is the wrong forum. I thought about the newbie forum, but then it was like "MAKE SURE YOU'RE IN THE RIGHT FORUM" and I was like "uh..."
 
Old 03-05-2013, 07:29 PM   #2
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142
The "files" you see in /dev are not files, they're devices. You can access them through the filesystem for convenience sake, but they're not really there. If you were to mount your root drive in some other OS (say if you booted a live CD), the "dev" directory would be more-or-less empty. The same goes for most of what you see in /proc/. They're not real files, just a temporary reference to some memory location or device or kernel module that's being presented to you on the filesystem so that you can access it from "user space".
 
1 members found this post helpful.
Old 03-05-2013, 08:12 PM   #3
Justin F
LQ Newbie
 
Registered: Jan 2013
Posts: 8

Original Poster
Rep: Reputation: Disabled
See, now this makes so much more sense. So the system initially mounts /dev/(device) to / so you can actually access all of your stuff, correct? Because if it didn't do that, you wouldn't physically be able to access any of your files or programs and linux would be unusable, no?
 
Old 03-05-2013, 08:22 PM   #4
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142
Before the root drive has been mounted, there is no filesystem, so there is no / or /dev or any of that. If you look at your grub config you'll see how your root device is being referenced before it's been mounted. Mine is "hd2,gpt1". After the drive has been mounted to /, device files are created for it and all of the other devices on the system (other drives, serial ports, etc.) in /dev/ so that they can be accessed from user space.

Last edited by suicidaleggroll; 03-05-2013 at 08:23 PM.
 
Old 03-05-2013, 08:29 PM   #5
Justin F
LQ Newbie
 
Registered: Jan 2013
Posts: 8

Original Poster
Rep: Reputation: Disabled
Hm...okay, so a little more confirmation: direct device references like /dev/sda (I know I used that before, but it's the best example :P) are unusable if they aren't mounted because it's just a direct reference to the memory address and you can't access any of the contents that way, correct? Or say, /media/cdrom (or whatever the cdrom location may be) would be utterly useless unless actually mounted to a certain location to access its filestructure, correct?
 
Old 03-05-2013, 08:37 PM   #6
jefro
Moderator
 
Registered: Mar 2008
Posts: 21,974

Rep: Reputation: 3623Reputation: 3623Reputation: 3623Reputation: 3623Reputation: 3623Reputation: 3623Reputation: 3623Reputation: 3623Reputation: 3623Reputation: 3623Reputation: 3623
Most people come from windows where they know what C: is and what C:\ is.

Linux along with other OS's are not so hardware driven. One can manipulate storage to suite needs. It is more software driven.

There are two main issues with mount. First the system would have to know about some storage. Either as part of system or even network. It has to have that basics first. Then you can be allowed to use a mount command. That command could be behind the scenes on boot up or from your command line. You mount the filesystem with a command. In that command you used to have to be very specific about the file system and how it was to be mounted. Most newbies only use big name distro's that use a gui to mount or it automounts for you.

I suggest you look at the output of the manual pages for mount. Online here, http://linux.die.net/man/8/mount and from most distro's command line. Either a man mount command or in some cases mount --help command.
 
Old 03-05-2013, 08:43 PM   #7
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142
The order goes:

The machine loads the MBR on the boot drive, which is where grub is located
Grub loads its menu, and allows you to select which drive you want to boot from
Whatever drive you select is referenced in the way Grub uses, for example "hd2,gpt1" on my system. It doesn't use /dev/xxxx, because there's no such thing as /dev/ in this part of the boot process, there's not even a "/", there is no filesystem yet.
The next section is a bit fuzzy for me, but basically the root drive for the OS you select is mounted at /, then device files for every other device in the system are created in /dev/

As for your specific question:
Quote:
Hm...okay, so a little more confirmation: direct device references like /dev/sda (I know I used that before, but it's the best example :P) are unusable if they aren't mounted because it's just a direct reference to the memory address and you can't access any of the contents that way, correct? Or say, /media/cdrom (or whatever the cdrom location may be) would be utterly useless unless actually mounted to a certain location to access its filestructure, correct?
That's partially correct. The device isn't completely unusable though, there are still many things you can do with an unmounted device. You can repartition it, you can format it, you can pull raw (very low level) data off of it, etc. In fact there are many things that can ONLY be done on the raw /dev/ entry for an unmounted device. The device won't be regularly accessible on your filesystem until it has been mounted though. The mounting process essentially reads the partition and filesystem information from the device, and then presents it to you in a "normal" fashion at whatever mount point you specify when you mount it.

Last edited by suicidaleggroll; 03-05-2013 at 08:44 PM.
 
Old 03-05-2013, 08:45 PM   #8
frankbell
LQ Guru
 
Registered: Jan 2006
Location: Virginia, USA
Distribution: Slackware, Ubuntu MATE, Mageia, and whatever VMs I happen to be playing with
Posts: 19,311
Blog Entries: 28

Rep: Reputation: 6137Reputation: 6137Reputation: 6137Reputation: 6137Reputation: 6137Reputation: 6137Reputation: 6137Reputation: 6137Reputation: 6137Reputation: 6137Reputation: 6137
Here's an excellent tutorial on the Linux file system.

http://tldp.org/LDP/intro-linux/html/sect_03_01.html

The key concept is this:

In *nix, everything is a file.

Things that are not files, such as devices, are represented by or treated as files, and the system talks to them by talking to (or through) the file.

So a device (/dev/sda1) is represented by a file in /dev. It gets "mounted" to a file in, say, /mnt or /media (say, /mnt/sda1), which makes it available to the system. The process of mounting links /mnt/sda1 to /dev/sda1. The system can then talk to /mnt/sda1, which is the interface or channel for talking to /dev/sda1 which in turn relays the information to the physical partition represented by /dev/sda1.

This is a clumsy and completely non-technical description which I am sure that others can improve, I know, but I hope it helps clarify the concept, at least as I understand it.
 
Old 03-05-2013, 08:51 PM   #9
Justin F
LQ Newbie
 
Registered: Jan 2013
Posts: 8

Original Poster
Rep: Reputation: Disabled
Thank you, you've all been a great help to me, and I feel like I understand the whole concept a lot better, now. It's tough having to learn all this stuff after being super familiar with Windows for 10 years, y'know?
 
Old 03-05-2013, 09:54 PM   #10
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
There is a bit more to it that discussed.

When grub boots it loads the kernel, AND an initrd (initial read only filesystem) which a compressed archive of a tiny root system. The kernels built in init mounts a ram disk (empty), and the restores the archive to it. At this point the root device is the ram disk.

The init process now starts using facilities on the ramdisk - most are now using a service called "udev" which probes the existing hardware to identify what is in the system, and creates the inital /dev (which mounted as a "devfs" filesystem which is a filesystem representation of the device structures/drivers in the kernel). When drivers get loaded, they register with the devfs to create the "device files" used to access the device.

Note, all of this is still strictly memory resident. No disk based filesystems have been mounted.

The root device identified by the kernel parameters (taken from the grub boot - the parameter is "root=..." on the kernel specification) specifies the real, disk resident filesystem to use for /. This filesystem is usually identified by UUID (though it can be specified by device file name, or volume label). The problem with using the device file name is that the actual name created by udev depends on how/when udev identifies the device - a fast disk comes up before a slow one, so the fast one gets the sda name. But that doesn't mean sda<n> is the correct filesystem - It may be sdb.. if a disk gets replaced, things can get out of order. So UUID - this requires the udev service to retrieve the UUID for each partition it identifies.

When the memory resident init mounts the filesystem it uses /mnt of the ramdisk to mount it. The root filesystem is now known by the kernel.

A fancy system call ("pivot_root") is then used to exchange the ram disk root filesystem with that /mnt filesystem. At this point, the /mnt filesystem is the ramdisk, and / is now the disk resident filesystem. The /dev filesystem (the devfs memory resident thing) is mounted again as /dev, and the /mnt/dev dismounted, and the /mnt ramdisk dismounted. At this point the memory used by the ramdisk is reclaimed.

The kernel init isn't quite done yet - it then execs the init from /sbin/init so that the system can now complete its normal startup.

This slightly convoluted sequence makes the physical devices more independent of specific configuration - the root device could be on nearly anything, as long as that "anything" can be identified by the kernel.
 
2 members found this post helpful.
  


Reply



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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Can't mount device: mount you must specify the filesystem type elrodri Linux - Server 1 04-17-2012 04:52 AM
Mount SamFS filesystem on Linux (NFS mount ?) michalkm Linux - General 0 02-24-2009 06:35 AM
mount: unknown filesystem type 'ntfs' when trying to mount windows drive... DiZASTiX Linux - Hardware 12 09-28-2008 07:29 PM
How to mount a filesystem mikej_w Linux - Embedded & Single-board computer 3 11-16-2007 01:31 PM
Can't mount filesystem !! tuxuser19 Slackware 1 12-14-2005 06:59 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 10:59 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration