1

I was reading about mounting in Operating Systems and have the following question related to it:
When we plug an external hard disk it gets automatically mounted in our file system, the one our operating system is using.But how does the operating system know which file system format, like NTFS or FAT32, the Hard Disk is using?
In other words, how will it know which type of File System to mount when we plug a hard-disk into our system?

sarthak
  • 1,472

2 Answers2

2

Almost every filesystem out there starts with some magic values, so you can determine the filesystem type by reading the first few bytes and comparing their values against a list of supported values provided by the drivers.

Some types of partition formats provide information about the filesystem that's on the partition. However this information is incomplete and not always reliable, so Linux largely if not completely ignores it.

0

I believe the Operating System takes a list of filesystems that it knows of (FAT, EXT2, EXT3 etc.) and matches each one of them in a defined order (based on their popularity probably) against the disk partition, until it finds a match.

The command blkid can be used to determine the filesystem type of a partition. It has a parameter -n to limit the list of filesystems that it probes. for example:

blkid -p -n vfat,ext3,ext4 /dev/sda1
# this will only probe for vfat, ext3 and ext4 filesystems on /dev/sda1
# -p     Switch to low-level superblock probing mode (bypass cache)
SparedWhisle
  • 3,668