0

When you plug in a USB storage device such as a pen drive for example there are two things that happen. First the device appears and then its file system is mounted. When the device is plugged in you can mount and unmount its file system.

Hence my question is: what does the operating system see that file system as? Is it something like a single image file for example: mydevice_ext4.img ?

  • 2
    In UNIX/Linux like OS, everything is a file (more correct: has a file descriptor). Every storage device you plug in will get a file descriptor like /dev/sdb and all partitions on it will also get one each, like /dev/sdb1. Now the file system in a partition is just the data content you get when you read that "partition file". It can be interpreted as a file system by mounting it somewhere, which makes the content of the file system available as files and folders. – Byte Commander Dec 3 '16 at 11:34
  • Great answer! Can I view the raw data content on the device before it's interpreted as a file system ? – Shady Programmer Dec 3 '16 at 12:04
  • 2
    Sure you can. You can open it like a regular file, but beware that you need root rights (use sudo) to be allowed to read it and you must know that it is binary data (so most text viewers will not be too useful) and that it is huge, which might be a problem for some viewers as well. – Byte Commander Dec 3 '16 at 12:09
2

A filesystem/partition like /dev/sda1 can be seen (or at least represented as an interface in the root filesystem) as a "block device" which is one of the categories of . Files are representations of data stored somehow, and a filesystem is a bunch of data with some kind of coherent structure. The block device file is a "raw" representation of the structured data. To make it accessible as files and directories that you can read and interact with, it can be mounted...

If you ls -l /dev - you see some entries starting with the letter b indicating a block device, and this will include any filesystem such as internal partitions, peripheral devices, etc... here's some from my system (#comments added by me)

brw-rw---- 1 root disk 179,  1 Dec  3 07:14 /dev/mmcblk1p1  #ESP
brw-rw---- 1 root disk 179,  2 Dec  3 07:14 /dev/mmcblk1p2  #root partition
brw-rw---- 1 root disk 179,  3 Dec  3 07:14 /dev/mmcblk1p3  #swap

This wikipedia article explains the concept of a device file in some detail.

  • So you're saying that the file system is seen as "block device" but I thought that block device is the actual hardware device ? Also is it right to say that file system is always a partition ? Another thing is that I thought that /media is supposed to be the mount point, can /dev be described as mount point as well ? – Shady Programmer Dec 3 '16 at 12:10
  • @ShadyProgrammer a block device is a type of file and as such it is a representation of some data. The drive itself (eg /dev/sda) is also a block device. I'm not sure whether a filesystem can always be called a partition; I will consider it. As I understand it, a mount point is a directory where data in some filesystem can be accessed, so I don't think device files can be considered to be mount points. Rather, they can be attached to mount points in a way that makes them accessible – Zanna Dec 3 '16 at 12:52
  • This has gotten confusing really fast. So by your definition of a mount point, block device files such as /dev/sda can actually be said to be mount points and so if they're mount points then why aren't they mounted at /media directory ? – Shady Programmer Dec 3 '16 at 13:34
  • @ShadyProgrammer er... I thought I said no, /dev/sda1 etc are not mount points, they can be attached to a mount point, such as /media/storage. But / and /boot/efi are also mount points... – Zanna Dec 3 '16 at 14:32
  • The reason it might look like I twisted your explanation in my comment above is that when you said "As I understand it, a mount point is a directory where data in some file system can be accessed" I thought that because you can access the devices raw data when it appears as /dev/sda it can technically be considered a mount point. However I've done further reading throughout the whole day today on this topic and experimented on my PC as well. Finally I think (although my understanding is still a bit shaky) I can understand what's going on here. Anyway, your initial answer was helpful. – Shady Programmer Dec 3 '16 at 19:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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