1

If I were to install a physical file system onto a Linux machine, why should I mount that file system to a custom location? Why not just have the file system be located at its device path? "/dev/...."

Izzo
  • 961
  • There is no filesystem information in the device. How would the OS differentiate between different file system types (ext4, xfs, etc.)? Also, how would you specify that /dev/sdb4 is to be referenced as /home? How do you prevent submirrors being accessed when combined into a software raid? Problems are endless. – doneal24 Feb 07 '22 at 16:48
  • My question stems from confusion in identifying separate file systems within the root file system. For example, when I look at some directory /home/user1, I often get confused as to whether or not this is a directory within / file system, or if this is a separate file system just mounted. The answer to this question is always "it depends" on how the file systems were set up. – Izzo Feb 07 '22 at 17:17
  • There are many ways to check but one quick&dirty way is df /home/user1. df -hlP -x tmpfs may also be useful. – doneal24 Feb 07 '22 at 17:22

3 Answers3

2

Why not just have the file system be located at its device path?

I don't think that it would be desirable to do that. The result would be that all software would then need to be somehow aware of the devices you have plugged in.

If you have a look at how MS Windows does it (with drive letters) layouts are limited by the environment variables such as %HOMEPATH%. If you have a lot of music on another hard drive then there's no way to tell your software that E: is the music folder for one user.

In *nix systems this problem doesn't exist. If you want your music on another HD, then just add an entry to /etc/fstab to mount it to /home/me/Music and software never needs to be told of the change.


Also the names under /dev are not actually stable. For example you can plug in a USB hard drive before you boot and there's a chance it could be assigned /dev/sda instead of your internal drive. This would make it very difficult to configure anything at all since you couldn't guarantee which names were assigned.


It actually makes much more sense to lay out your file system based on grouping similar types of things together and rather than becoming overly concerned on where they are stored.

The Filesystem Hierarchy Standard groups things partially based on the requirements. This allows some very useful tricks such as putting the whole of /usr onto a read-only network file system (NFS) while keeping configuration for each machine separate in the writable /etc.

It allows sys-admins to make decisions on what should be stored where while users and software generally don't need to know this and don't want to track it.


Its worth noting that even under Windows (At least Windows Server) the same technique is possible and drives may be mounted anywhere else in the filesystem.

0

Linux keeps all devices as files in some special directories like /dev or /sys. So /dev is a place for devices. They are seen in / filesystem like regular files, but in fact they aren't. Kernel drivers translates file operation on devices to physical commands sent via bus.

For example you may see a raw content of your disk by using following command:

dd if=/dev/sda1 count=64

But you will see only 32kb raw data which are not interpreted in any way (in fact they contains filesystem metadata, sometimes included with booting instructions like FAT filesystem). By mounting such file (device) you get access to see your device as filesystem structure which are put in the mount point. So mounting change the meaning of raw data into organized collection accessible by directories and files.

  • /dev/sda1 should not be presenting a partition table, that should come from /dev/sda. The first few blocks likely will give you some filesystem metadata in some form. – doneal24 Feb 07 '22 at 18:52
  • @doneal24 I didn't mentioned that /dev/sda1 is a partition table. Anyway I reviewed the answer. Including your suggestion. Thank you. – user12425014 Feb 08 '22 at 17:49
0

It's a convention described in the Filesystem Hierarchy Standard (FHS), a reference describing the conventions, used for the layout of a UNIX system.

See https://en.wikipedia.org/wiki/Filesystem_Hierarchy_Standard and https://refspecs.linuxfoundation.org/fhs.shtml

In unix all is file, this means that in /dev you find devices files, with special bloc flag.

In unix the device can be mounted at any place in the filesystem hierarchy.

By convention, you would mount the various devices in /mnt, this has changed to /media for temporary devices.

You can find udisks2 mount point under /run/media/$USER while it was /media for udisks. Kde and Gnome use this convention.

By attaching a device to a mount point, you register in the kernel a bidirectionnal relation, where every action under the mount point will be reflected on the raw device and vice-versa.

Actualy windows do it but hide that, you have a \Device\HarddiskVolumeX, but it only support to mount it as A:, C:, D:\ or X:\

You can get the list of mount point with the mount or df commands.

You may look at this question for references what is the distinction between /media, /mnt and /run/mount?

  • Note that changes to the block device behind a mount point are normally not reflected, and you’ll end up with severe corruption if you try that. Also, Windows can mount file systems without using drive letters. – Stephen Kitt Feb 07 '22 at 19:05