[BusyBox] Filesystem detection in mount & lazy unmount

Chris Spiegel busybox at happyjack.org
Tue Jul 12 08:24:58 UTC 2005


On Tuesday 12 July 2005 12:04 am, you wrote:
> On Monday 11 July 2005 17:06, Chris Spiegel wrote:
> > It's true that /etc/filesystems can sort of take the role of automatic
> > filesystem detection.  My goal as a lazy end-user, though, is to do as
> > little as humanly possible to get my system working -- currently I have
> > an initrd that, among other things, doesn't need to be told the root
> > filesystem type, and if I happen to change it I won't have to make sure
> > that a text file is up to date, because I'm using util-linux's mount.  Of
> > course, getting to my goal of lazy end-user may include lots of work
> > hacking code but I don't mind that for some reason.  :)
>
> The way automatic filesystem detection normally works is that it tries all
> the various filesystems the kernel supports in order, and takes the first
> one that doesn't fail.  If this doesn't successfully mount the filesystem,
> then the kernel doesn't support it.

Well, in recent util-linux releases, mount has the ability to do even better 
than just trying known filesystems in order.  It will do various checks on 
the partition to see if it sees any magic numbers of filesystems that it 
knows.  This way, even if the module isn't loaded and no /etc/filesystems 
exists, it still tries to use a particular filesystem, causing the module to 
be loaded.

For example, on my testing system, I have an XFS filesystem on /dev/hda1.  XFS 
support is built as a module.  If I do:
mount -v /dev/hda1 /mnt

I get:
mount: You didn't specify a filesystem type for /dev/hda1
       I will try type xfs

It knows to try xfs, and, moreover, the module gets loaded.

This code can be seen in util-linux 2.12q in mount/mount_guess_fstype.c.  It  
uses detection from libblkid if it's available, otherwise it has builtin 
filesystem-guessing code.

It's a generalized version of this code (by SGI for their libdisk) that I 
mentioned in my initial email, whose compiled size on my system is 5K.  So 
it's really not a huge space waster and it gets around having to maintain 
an /etc/filesystems -- although to be fair it does this by essentially 
putting a "more efficient" /etc/filesystems in the mount program itself.

Chris



More information about the busybox mailing list