How does RHEL determine the FS type when you run mkfs?
In Solaris there was /etc/default/fs - I can not find any sort of configuration file or parameter which defines the default filesystem type to use (if none is specified).
On a more annoying note: my team (all ex-Solaris guys, including myself) generally run a mkfs without a -t ... and better yet, we would add 'ext4' to /etc/fstab for our newly created FS. It seems that RHEL will mount an ext2 filesystem using ext4 in the fstab.
[root@tmsapp01 ~]# file -sL /dev/mapper/ORAAPPVG-LV_U01
/dev/mapper/ORAAPPVG-LV_U01: Linux rev 1.0 ext2 filesystem data (mounted or unclean) (large files)
[root@tmsapp01 ~]# grep u01 /etc/fstab
/dev/mapper/ORAAPPVG-LV_U01 /u01 ext4 defaults 1 2
I think my issue is too wide-spread for this to be a bug.. but I have some homework now ;-)
Responses
Hi James,
Hopefully I'm not missing your intention here...
Not sure there is a default config in RHEL such as what you have seen in Solaris... but of course you could just use mkfs.ext3, mkfs.ext4, mkfs.xfs etc as whatever default makes sense...
I use one of the following, depending on the file system I wish to create: mkfs.ext4 or with rhel7 mkfs.xfs and also here
I'm no longer using ext3 but of course mkfs.ext3 is out there.
A side note, for those customers that insist on a rhel 5.current system, I can make all file systems ext4 at kickstart with the obvious exception of /boot and of course swap is different, found that out by accident when another admin tried it.
Hoping this helps...
Regards,
Remmele
Nice find,
We just use mkfs.[filesystem type] (i.e. mkfs.ext4, mkfs.xfs on rhel 7). Did you need to only use just 'mkfs' for a reason? I don't think I know the context of your scenario... Are you automating a file system creation?
It seems odd that ext2 is the default. I suspect your victim system is a rhel 6 system?
What a bummer...
At least there's a method to convert from ext4 to xfs when the time comes, or if it seems like a good idea. also see this link.
The mkfs binary is hard-coded to a default filesystem type of ext2:
#ifndef DEFAULT_FSTYPE
# define DEFAULT_FSTYPE "ext2"
#endif
However, if you specify a filesystem type with -t fstype then the binary takes your parameter and executes mkfs.fstype.
For example, if you run mkfs -t ext4 then the string mkfs.ext4 is built, and then execvp(mkfs.ext4 + options) is called.
The source is in disk-utils/mkfs.c from util-linux-ng. It's only a hundred lines or so. If you understand a little C option/string parsing like argv, optind, optarg, and sprintf you'll gasp it easily.
(Note: I checked the RHEL 6.5 package built from util-linux-ng-2.17.2 when looking at this)
This comes from the fact that all the ext filesystems are just feature additions on top of each other.
The features an ext2 filesystem has are valid to the ext4 driver, the driver just sees things like "no journal" and "no extents" and doesn't use the journal/extent parts of the ext4 code.
Of course, it's not a very good idea, and may cause the actually-ext2 filesystem to have changes made which make it not-ext2 anymore, so you just end up with a very feature-sparse sorta-ext4 filesystem.
I'd be surprised if we support mounting ext2-as-ext4 on RHEL 5 or 6, though the ext2/3/4 drivers have been unified into the one driver in RHEL7.
If I were in your place, I'd change procedures so people have to explicitly run mkfs.fstype when creating any filesystem (ext or otherwise) to remove any ambiguity, then confirm (and record) the filesystem type with file -s afterwards.
Just one of the many minor ways Linux and Solaris differ, I can understand how it seems odd. Growing up on Linux, the concept of a /etc/default/fs to specify a default filesystem type seems odd to me :)
I have been following this thread from the start and think it is an interesting quirk that James has stumbled upon, and good follow up discussion, cheers to those involved.
My question is, what would trigger the 'ext2' hard coding to be updated to something newer in the source? Is it likely to remain that way to avoid possible regression?
I also agree with James' comments above regarding mounting an ext2 with ext4, even if it wasn't an error that stopped mounting but a 'notice' message at mount time eg."mounting ext2 partition", this would be enough to make me check twice.
I have a habit of using mkfs.filesystem which I think is from early ext3 days, but this thread definitely made me check my SOPs to ensure the filesystem type was explicitly specified! Thanks for posting it up.
I've pretty much always worked with UNIX OSes that supported 2+ filesystems. So, was always just a habit to be explicit. Only particular annoyance with that is that the flag varies from OS to OS.
On the other hand, being in that habit means I also tend to be in the habit of specifying FSType in other tools that support it (e.g., df, mount and a few others across OSes).
I spoke to our upstream util-linux maintainer. Changing the default from ext2 isn't desireable, as existing things may rely on the ext2 behaviour of mkfs.
However, the standalone command mkfs (as opposed to mkfs.fstype) is considered deprecated and will be removed altogether in a future util-linux release.
The suggested way (and in future the only way) to make filesystems on Linux is to run mkfs.fstype explicitly.
Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.
