MKE2FS(8)

โœจ NAME โœจ

mke2fs โ€” create an ext2/ext3/ext4 file system ๐ŸŽ€

(also, hi bestie, this is from section 8, the System Manager's Manual โ€” the big-girl system admin pages ๐Ÿ’…)


๐ŸŒธ SYNOPSIS ๐ŸŒธ

mke2fs [ -c | -l filename ] [ -b block-size ] [ -C cluster-size ] [ -d
root-directory|tarball|- ] [ -D ] [ -g blocks-per-group ] [ -G number-
of-groups ] [ -i bytes-per-inode ] [ -I inode-size ] [ -j ] [ -J
journal-options ] [ -N number-of-inodes ] [ -n ] [ -m reserved-blocks-
percentage ] [ -o creator-os ] [ -O [^]feature[,...]  ] [ -q ] [ -E
extended-options ] [ -v ] [ -F ] [ -L volume-label ] [ -M last-mounted-
directory ] [ -S ] [ -t fs-type ] [ -T usage-type ] [ -U UUID ] [ -V ] [
-e errors-behavior ] [ -z undo_file ] device [ fs-size ]
mke2fs -O journal_dev [ -b block-size ] [ -L volume-label ] [ -n ] [ -q
] [ -v ] external-journal [ fs-size ]

๐Ÿฆ‹ DESCRIPTION ๐Ÿฆ‹

mke2fs is the girl who makes file systems. She creates an ext2, ext3, or ext4 file system, usually inside a disk partition (or a file, no judgment) that you name with device. Iconic behaviour, honestly. ๐Ÿ‘‘

The size of the file system is set by fs-size. And here's the tea on how that number gets read:

  • If fs-size has no suffix, it's interpreted as power-of-two kilobytes โ€” unless you also passed the -b block-size option, in which case fs-size is read as the number of block-size blocks.
  • If fs-size is suffixed with 'k', 'm', 'g', 't' (upper-case or lower-case, she's not picky ๐Ÿซถ), it's interpreted in power-of-two kilobytes, megabytes, gigabytes, terabytes, etc.
  • If fs-size is just... omitted? Then mke2fs creates the file system based on the device size. Let her cook. โœจ

If mke2fs is run as mkfs.XXX (that's mkfs.ext2, mkfs.ext3, or mkfs.ext4), then the -t XXX option is implied โ€” so mkfs.ext3 makes a file system for use with ext3, mkfs.ext4 makes one for ext4, and so on down the line. It's giving "I already know what you want". ๐Ÿ’…

The defaults for the parameters of your brand-new file system, whenever you haven't overridden them with the options listed below, are controlled by the /etc/mke2fs.conf configuration file. Go read mke2fs.conf(5) for the details, bestie, it's all in there. ๐Ÿ“–


๐Ÿ’– OPTIONS ๐Ÿ’–

  • -b block-size โ€” set the size of blocks, in bytes. Valid block-size values are powers of two from 1024 up to 65536 โ€” but โš ๏ธ keep in mind the kernel can only mount file systems whose block-size is smaller than or equal to the system page size: that's 4k on x86 systems, and up to 64k on ppc64 or aarch64 depending on kernel configuration. If you omit it, block-size gets heuristically determined from the file system size and the expected usage of the file system (peep the -T option). In most common cases the default block size is 4k. And here's the fun bit: if block-size is preceded by a negative sign ('-'), mke2fs uses heuristics to figure out the appropriate block size, with the constraint that the block size will be at least block-size bytes. That's useful for certain hardware devices that require the blocksize to be a multiple of 2k. Slay for weird hardware. ๐Ÿ”ฅ
  • -c โ€” check the device for bad blocks before creating the file system. If you specify this option twice, a slower read-write test is used instead of the fast read-only test. Double it and give it to the next person, I guess. ๐Ÿ˜ญ
  • -C cluster-size โ€” specify the size of clusters in bytes for file systems using the bigalloc feature. Valid cluster-size values range from 2 to 32768 times the filesystem block size, and it must be a power of 2. You can only specify cluster-size if the bigalloc feature is enabled. (Check ext4(5) for more details about bigalloc, no cap.) The default cluster size when bigalloc is enabled is 16 times the block size. ๐Ÿงš
  • -d root-directory|tarball|- โ€” copy the contents of the given directory or tarball into the root directory of the file system. Tarball input is only available if mke2fs was compiled with libarchive support enabled and if the libarchive shared library is available at run-time. The special value - will read a tarball from standard input. So extra. Obsessed. ๐Ÿ“
  • -D โ€” use direct I/O when writing to the disk. This avoids mke2fs dirtying a lot of buffer cache memory, which may impact other applications running on a busy server. However โ€” and this is the tradeoff, bestie โ€” this option will cause mke2fs to run much more slowly. So it's a whole tradeoff situation with direct I/O. ๐Ÿ’€
  • -e error-behavior โ€” change the behavior of the kernel code when errors are detected. In all cases, a file system error will cause e2fsck(8) to check the file system on the next boot. error-behavior can be one of these:
    1. continue โ€” continue normal execution.
    2. remount-ro โ€” remount file system read-only.
    3. panic โ€” cause a kernel panic. ๐Ÿ˜ฑ
  • -E extended-options โ€” set extended options for the file system. Extended options are comma separated, and may take an argument using the equals ('=') sign. Multiple -E options may also be used. Fun history moment: the -E option used to be -R in earlier versions of mke2fs. The -R option is still accepted for backwards compatibility, but it is deprecated. ๐Ÿซ  The following extended options are supported:
    • assume_storage_prezeroed[=<0 to disable | 1 to enable>] โ€” if enabled, mke2fs assumes that the storage device has been prezeroed, skips zeroing the journal and inode tables, and annotates the block group flags to signal that the inode table has been zeroed.
    • discard โ€” attempt to discard blocks at mkfs time (discarding blocks initially is useful on solid state devices and sparse / thin-provisioned storage). When the device advertises that discard also zeroes data (any subsequent read after the discard and before write returns zero), then mark all not-yet-zeroed inode tables as zeroed. This significantly speeds up file system initialization. This is set as default. โญ
    • encoding=encoding-name โ€” enable the casefold feature in the super block and set encoding-name as the encoding to be used. If encoding-name is not specified, the encoding defined in mke2fs.conf(5) is used.
    • encoding_flags=encoding-flags โ€” define parameters for file name character encoding operations. If a flag is not changed using this parameter, its default value is used. encoding-flags should be a comma-separated lists of flags to be enabled. To disable a flag, add it to the list with the prefix "no".

The only flag that can be set right now is strict, which means that invalid strings should be rejected by the file system. In the default configuration, the strict flag is disabled.

  • hash_seed=UUID โ€” use the specified UUID as the seed for hashing, rather than generating a random seed each time. Intended for use with reproducible builds. Reproducible girlies rise up. ๐ŸŒˆ
  • lazy_itable_init[=<0 to disable | 1 to enable>] โ€” if enabled and the uninit_bg feature is enabled, the inode table will not be fully initialized by mke2fs. This speeds up file system initialization noticeably, but it requires the kernel to finish initializing the file system in the background when the file system is first mounted. If the option value is omitted, it defaults to 1 to enable lazy inode table zeroing.
  • lazy_journal_init[=<0 to disable | 1 to enable>] โ€” if enabled, the journal inode will not be fully zeroed out by mke2fs. This speeds up file system initialization noticeably, but it carries some small risk if the system crashes before the journal has been overwritten entirely one time. ๐Ÿ˜ฌ If the option value is omitted, it defaults to 1 to enable lazy journal inode zeroing.
  • mmp_update_interval=interval โ€” adjust the initial MMP update interval to interval seconds. Specifying an interval of 0 means to use the default interval. The specified interval must be less than 300 seconds. Requires that the mmp feature be enabled.
  • nodiscard โ€” do not attempt to discard blocks at mkfs time. (the anti-discard, if you will ๐Ÿ™ˆ)
  • no_copy_xattrs โ€” normally mke2fs will copy the extended attributes of the files in the directory hierarchy specified via the (optional) -d option. This will disable the copy and leaves the files in the newly created file system without any extended attributes.
  • num_backup_sb=<0|1|2> โ€” if the sparse_super2 file system feature is enabled, this option controls whether there will be 0, 1, or 2 backup superblocks created in the file system.
  • offset=offset โ€” create the file system at an offset from the beginning of the device or file. This can be useful when creating disk images for virtual machines. ๐Ÿ–ฅ๏ธ
  • orphan_file_size=size โ€” set size of the file for tracking unlinked but still open inodes and inodes with truncate in progress. Larger file allows for better scalability; reserving a few blocks per CPU is ideal.
  • packed_meta_blocks[=<0 to disable | 1 to enable>] โ€” place the allocation bitmaps and the inode table at the beginning of the disk. This option requires that the flex_bg file system feature to be enabled in order for it to have effect, and will also create the journal at the beginning of the file system. This option is useful for flash devices that use SLC flash at the beginning of the disk. It also maximizes the range of contiguous data blocks, which can be useful for certain specialized use cases, such as supported Shingled Drives.

okay bestie that's the first chunk and there is so much more coming โ€” don't go anywhere ๐Ÿ’œ

  • quotatype=quota-type[:...] โ€” tell mke2fs which quota types to switch on in the brand-new filesystem. Your options are usrquota, grpquota, and prjquota, and bestie you write them as a colon-separated list. Heads up tho: this only does anything if the quota feature is actually set. If you don't specify it at all, the default quota types that get initialized are both user and group quotas. And if the project feature is enabled, then project quotas get initialized too. ๐Ÿ’…
  • resize=max-online-resize โ€” reserve enough space so the block group descriptor table can grow big enough to support a filesystem that has max-online-resize blocks. Future-proofing queen. โœจ
  • revision=fs-revision โ€” set the filesystem revision number. Revision 0 filesystems play nice with pre-1.2 Linux kernels (so like, before 1995 ๐Ÿ˜ญ). You only need this for testing or for the girlies who genuinely want to run extremely early, historical Linux systems. The current default โ€” and the one every modern Linux supports โ€” is revision 1. Periodt.
  • root_owner[=uid:gid] โ€” set the numeric user and group ID of the root directory. If you don't give a UID:GID, it uses the user and group ID of whoever is running mke2fs. Quick lore drop: in mke2fs 1.42 and earlier, the UID and GID of the root directory were set by default to the UID and GID of the user running the mke2fs command. The root_owner= option lets you specify these values explicitly and dodge the side-effects for users who do not expect the contents of the filesystem to change based on who ran mke2fs. Iconic, honestly.
  • root_perms[=permissions] โ€” set the root directory permissions in octal format. If you don't give any permissions, the root directory permissions get set according to the default filesystem umask. No cap.
  • root_selinux=label โ€” set the root directory's SELinux security context as label, typically system_u:object_r:root_t, with an optional level/range suffix such as :s0 for MCS/MLS policy types. ๐Ÿซถ
  • stride=stride-size โ€” configure the filesystem for a RAID array with stride-size filesystem blocks. This is the number of blocks read or written to disk before moving on to the next disk, which some people call the chunk size. It mostly affects where filesystem metadata like bitmaps get placed at mke2fs time, so they don't all end up stacked on one disk โ€” which would hurt performance. It may also be used by the block allocator. Lowkey important. ๐Ÿ”ฅ
  • stripe_width=stripe-width โ€” configure the filesystem for a RAID array with stripe-width filesystem blocks per stripe. This is typically stride-size * N, where N is the number of data-bearing disks in the RAID (like, for RAID 5 there's one parity disk, so N is the number of disks in the array minus 1). This lets the block allocator avoid read-modify-write of the parity in a RAID stripe when possible while data is being written. Genius behaviour tbh. โœจ
  • test_fs โ€” set a flag in the filesystem superblock saying it may be mounted using experimental kernel code, such as the ext4dev filesystem. ๐Ÿงช

  • -F โ€” Force mke2fs to create a filesystem even if the specified device isn't a partition on a block special device, or if other parameters just don't make sense. And if you want to force mke2fs to create a filesystem even when the filesystem appears to be in use or is mounted โ€” which is a truly dangerous thing to do โ€” you have to specify this option twice. Not once. Twice. Respect the double. ๐Ÿ’€
  • -g blocks-per-group โ€” specify the number of blocks in a block group. Ngl there's generally no reason for you to ever set this, because the default is optimal for the filesystem. (For admins creating filesystems on RAID arrays, it's preferable to use the -E stride= extended option rather than messing with the number of blocks per group.) This one's generally used by developers working on test cases. Also: if the bigalloc feature is enabled, the -g option specifies the number of clusters in a block group. ๐Ÿ‘‘
  • -G number-of-groups โ€” specify how many block groups get packed together to create a bigger virtual block group (a "flex_bg group") in an ext4 filesystem. This improves meta-data locality and performance on meta-data heavy workloads. The number of groups must be a power of 2, and you may only specify it if the flex_bg filesystem feature is enabled. Rules are rules bestie. โœจ
  • -i bytes-per-inode โ€” specify the bytes/inode ratio. mke2fs creates one inode for every bytes-per-inode bytes of space on the disk. The larger the ratio, the fewer inodes get made. This value generally shouldn't be smaller than the block-size of the filesystem, because then you'd be making more inodes than could ever be used. โš ๏ธ Be warned: it is not possible to change this ratio on a filesystem after it's created, so be careful deciding the correct value for this parameter. Also note that resizing a filesystem changes the number of inodes to maintain this ratio. Choose wisely, main character. ๐Ÿ˜ญ
  • -I inode-size โ€” specify the size of each inode in bytes. The inode-size value must be a power of 2 larger or equal to 128. The larger the inode-size, the more space the inode table eats, which reduces usable space in the filesystem and can also negatively impact performance. And fr, it is not possible to change this value after the filesystem is created.

File systems with an inode size of 128 bytes do not support timestamps beyond January 19, 2038. ๐Ÿ˜ญ Inodes that are 256 bytes or larger will support extended timestamps, project id's, and the ability to store some extended attributes in the inode table for improved performance. Glow-up.

The default inode size is controlled by the mke2fs.conf(5) file. In the mke2fs.conf file shipped with e2fsprogs, the default inode size is 256 bytes for all filesystems, except for the GNU Hurd since it only supports 128-byte inodes. ๐Ÿง

  • -j โ€” create the filesystem with an ext3 journal. If the -J option isn't specified, the default journal parameters get used to create an appropriately sized journal (given the size of the filesystem) stored within the filesystem. Note that you must be using a kernel with ext3 support to actually make use of the journal. No kernel support, no journal magic. ๐Ÿ’ซ
  • -J journal-options โ€” create the ext3 journal using options specified on the command line. Journal options are comma separated, and may take an argument using the equals (=) sign. The following journal options are supported:
    • device=external-journal โ€” attach the filesystem to the journal block device located on external-journal. The external journal must already have been created using the command:
mke2fs -O journal_dev external-journal

Note that external-journal must have been created with the same block size as the new filesystem. In addition, while there's support for attaching multiple filesystems to a single external journal, the Linux kernel and e2fsck(8) do not currently support shared external journals yet.

Instead of specifying a device name directly, external-journal can also be specified by either LABEL=label or UUID=UUID to locate the external journal by either the volume label or UUID stored in the ext2 superblock at the start of the journal. Use dumpe2fs(8) to display a journal device's volume label and UUID. See also the -L option of tune2fs(8). ๐ŸŽ€

  • fast_commit_size=fast-commit-size โ€” create an additional fast commit journal area of size fast-commit-size kilobytes. This option is only valid if the fast_commit feature is enabled on the filesystem. If this option isn't specified and the fast_commit feature is turned on, the fast commit area size defaults to journal-size / 64 megabytes. The total size of the journal with the fast_commit feature set is journal-size + ( fast-commit-size * 1024 ) megabytes. The total journal size may be no more than 10,240,000 filesystem blocks or half the total filesystem size โ€” whichever is smaller.
  • location=journal-location โ€” specify the location of the journal. The argument journal-location can either be given as a block number, or, if the number has a units suffix (e.g., 'M', 'G', etc.), it's interpreted as the offset from the beginning of the filesystem. ๐Ÿ“
  • size=journal-size โ€” create an internal journal (like, stored inside the filesystem) of size journal-size megabytes. The size of the journal must be at least 1024 filesystem blocks (that's 1MB if using 1k blocks, 4MB if using 4k blocks, etc.) and may be no more than 10,240,000 filesystem blocks or half the total filesystem size โ€” whichever is smaller. โœจ

Only one of the size or device options can be given for a filesystem. Pick a lane bestie. ๐Ÿ’…

  • -l filename โ€” Read the bad blocks list from filename. Heads up, bestie: the block numbers in that bad block list must be generated using the same block size as used by mke2fs. So basically, the -c option to mke2fs is a much simpler and less error-prone method of checking a disk for bad blocks before formatting it, because mke2fs will automatically pass the correct parameters to the badblocks(8) program. slay.
  • -L new-volume-label โ€” Set the volume label for the file system to new-volume-label. The maximum length of the volume label is 16 bytes. Keep it cute and short, okay?
  • -m reserved-blocks-percentage โ€” Specify the percentage of the file system blocks reserved for the super-user. This avoids fragmentation, and allows root-owned daemons, such as syslogd(8), to continue to function correctly after non-privileged processes are prevented from writing to the file system. The default percentage is 5%. Bestie, don't touch it unless you know what you're doing.
  • -M last-mounted-directory โ€” Set the last mounted directory for the file system. This might be useful for the sake of utilities that key off of the last mounted directory to determine where the file system should be mounted. iykyk.
  • -n โ€” Causes mke2fs to not actually create a file system, but display what it would do if it were to create a file system. This can be used to determine the location of the backup superblocks for a particular file system, so long as the mke2fs parameters that were passed when the file system was originally created are used again. (With the -n option added, of course!) Iconic dry-run energy.
  • -N number-of-inodes โ€” Overrides the default calculation of the number of inodes that should be reserved for the file system (which is based on the number of blocks and the bytes-per-inode ratio). This allows the user to specify the number of desired inodes directly. Direct control? Obsessed.
  • -o creator-os โ€” Overrides the default value of the "creator operating system" field of the file system. The creator field is set by default to the name of the OS the mke2fs executable was compiled for. So it's like a lil name tag for your filesystem.
  • -O [^]feature[,...] โ€” Create a file system with the given features (file system options), overriding the default file system options.

The features that are enabled by default are specified by the base_features relation, either in the [defaults] section in the /etc/mke2fs.conf configuration file, or in the [fs_types] subsections for the usage types as specified by the -T option, further modified by the features relation found in the [fs_types] subsections for the file system and usage types. See the mke2fs.conf(5) manual page for more details. The file system type-specific configuration setting found in the [fs_types] section will override the global default found in [defaults].

The file system feature set will be further edited using either the feature set specified by this option, or if this option is not given, by the default_features relation for the file system type being created, or in the [defaults] section of the configuration file.

The file system feature set is comprised of a list of features, separated by commas, that are to be enabled. To disable a feature, simply prefix the feature name with a caret ('^') character. Features with dependencies will not be removed successfully. The pseudo-file system feature "none" will clear all file system features.

For more information about the features which can be set, please see the manual page ext4(5). Feature queen behavior.

  • -q โ€” Quiet execution. Useful if mke2fs is run in a script. No yapping, just vibes.
  • -S โ€” Write superblock and group descriptors only. This is an extreme measure to be taken only in the very unlikely case that all of the superblock and backup superblocks are corrupted, and a last-ditch recovery method is desired by experienced users. It causes mke2fs to reinitialize the superblock and group descriptors, while not touching the inode table and the block and inode bitmaps. The e2fsck(8) program should be run immediately after this option is used, and there is no guarantee that any data will be salvageable.
Danger, bestie: Due to the wide variety of possible options to mke2fs that affect the on-disk layout, it is critical to specify exactly the same format options, such as block-size, fs-type, feature flags, and other tunables when using this option, or the file system will be further corrupted. In some cases, such as file systems that have been resized, or have had features enabled after format time, it is impossible to overwrite all of the superblocks correctly, and at least some file system corruption will occur. It is best to run this on a full copy of the file system so other options can be tried if this doesn't work.
  • -t fs-type โ€” Specify the file system type (i.e., ext2, ext3, ext4, etc.) that is to be created. If this option is not specified, mke2fs will pick a default either via how the command was run (for example, using a name of the form mkfs.ext2, mkfs.ext3, etc.) or via a default as defined by the /etc/mke2fs.conf file. This option controls which file system options are used by default, based on the [fs_types] configuration stanza in /etc/mke2fs.conf.

If the -O option is used to explicitly add or remove file system options that should be set in the newly created file system, the resulting file system may not be supported by the requested fs-type. (e.g., "mke2fs -t ext3 -O extent /dev/sdXX" will create a file system that is not supported by the ext3 implementation as found in the Linux kernel; and "mke2fs -t ext3 -O ^has_journal /dev/hdXX" will create a file system that does not have a journal and hence will not be supported by the ext3 file system code in the Linux kernel.) So don't mix and match unless you're ready for chaos.

  • -T usage-type[,...] โ€” Specify how the file system is going to be used, so that mke2fs can choose optimal file system parameters for that use. The usage types that are supported are defined in the configuration file /etc/mke2fs.conf(5). The user may specify one or more usage types using a comma separated list.

If this option is not specified, mke2fs will pick a single default usage type based on the size of the file system to be created. If the file system size is less than 3 megabytes, mke2fs will use the file system type floppy. If the file system size is greater than or equal to 3 but less than 512 megabytes, mke2fs will use the file system type small. If the file system size is greater than or equal to 4 terabytes but less than 16 terabytes, mke2fs will use the file system type big. If the file system size is greater than or equal to 16 terabytes, mke2fs will use the file system type huge. Otherwise, mke2fs will use the default file system type default. Size type queen, not size queen.

  • -U UUID โ€” Set the universally unique identifier (UUID) of the file system to UUID. The format of the UUID is a series of hex digits separated by hyphens, like this: "c1b9d5a2-f162-11cf-9ece-0020afc76f16". The UUID parameter may also be one of the following:
    • clear โ€” clear the file system UUID
    • random โ€” generate a new randomly-generated UUID
    • time โ€” generate a new time-based UUID

UUIDs are iconic, periodt.

  • -v โ€” Verbose execution. Tell me everything, king.
  • -V โ€” Print the version number of mke2fs and exit. Short and sweet.
  • -z undo_file โ€” Before overwriting a file system block, write the old contents of the block to an undo file. This undo file can be used with e2undo(8) to restore the old contents of the file system should something go wrong. If the empty string is passed as the undo_file argument, the undo file will be written to a file named mke2fs-device.e2undo in the directory specified via the E2FSPROGS_UNDO_DIR environment variable or the undo_dir directive in the configuration file.
WARNING: The undo file cannot be used to recover from a power or system crash.

Not a time machine, bestie. Sorry.


โœจ ENVIRONMENT โœจ

  • MKE2FS_SYNC โ€” If set to non-zero integer value, its value is used to determine how often sync(2) is called during inode table initialization. Sync queen.
  • MKE2FS_CONFIG โ€” Determines the location of the configuration file (see mke2fs.conf(5)). Config file finder.
  • MKE2FS_FIRST_META_BG โ€” If set to non-zero integer value, its value is used to determine first meta block group. This is mostly for debugging purposes. Debug vibes only.
  • MKE2FS_DEVICE_SECTSIZE โ€” If set to non-zero integer value, its value is used to determine logical sector size of the device. Sector size, but make it logical.
  • MKE2FS_DEVICE_PHYS_SECTSIZE โ€” If set to non-zero integer value, its value is used to determine physical sector size of the device. Physical, not logical. We love a distinction.
  • MKE2FS_SKIP_CHECK_MSG โ€” If set, do not show the message of file system automatic check caused by mount count or check interval. Skip the pop-up, got it.

๐Ÿ‘‘ AUTHOR ๐Ÿ‘‘

This version of mke2fs has been written by Theodore Ts'o <tytso@mit.edu>. Legend.

๐ŸŒˆ AVAILABILITY ๐ŸŒˆ

mke2fs is part of the e2fsprogs package and is available from http://e2fsprogs.sourceforge.net. Go get it, bestie.

๐Ÿ” SEE ALSO ๐Ÿ”

๐Ÿ’– That's a wrap on MKE2FS(8) โ€” from e2fsprogs version 1.47.4, dated March 2025. Mwah! ๐Ÿ’–

๐Ÿ“ฆ where this page comes from