Filters
How to search
  • Plain words find names, texts and examples.
  • "two words" finds the exact phrase.
  • --name or -x finds an option.
  • #word looks only inside commands.
  • @grep finds lessons and labs that use grep.
  • Filters: cat:network · in:labs · in:notes · level:rhcsa · ch:8 · root:yes. Put ! before a word to leave it out. OR between words means one of them.
  • ↑ ↓ to move · Enter to open · Esc to close · / to search

mkfs.ext4

Create an ext4 (or ext3/ext2) file system.

Level
RHCSA exam
Group
Disks and file systems
Needs root
Yes
Package
e2fsprogs
Also called
mke2fs, mkfs.ext3, mkfs.ext2

What it does

mkfs.ext4 is mke2fs -t ext4. ext4 can grow (also mounted) and shrink (only unmounted) with resize2fs. By default 5 % of the blocks are reserved for root (-m), so root can still work when users fill the disk.

How to write it

mkfs.ext4 [OPTION]... DEVICE [SIZE]

Options 30

Most used

-L LABEL
Set a label (max 16 characters).
-m PERCENT
Reserved blocks for root (default 5).
-t TYPE
ext2, ext3 or ext4 (with mke2fs).
-T USAGE
Usage type from mke2fs.conf: news, largefile, largefile4, small, floppy.
-b SIZE
Block size (1024, 2048, 4096).
-i BYTES
Bytes per inode (smaller = more inodes).
-N NUMBER
Number of inodes.
-I SIZE
Inode size.
-U UUID
Set the UUID.
-O FEATURES
Turn features on or off (^feature = off), like ^has_journal.
-E OPTIONS
Extended options: stride=, stripe_width=, lazy_itable_init=, nodiscard …
-j
Create a journal (ext3).
-J OPTIONS
Journal options (size=, device=).
-e continue|remount-ro|panic
What to do on errors.
-c
Check for bad blocks first.
-l FILE
Read bad blocks from a file.
-g N, -G N
Blocks per group / groups per flex group.
-C SIZE
Cluster size (bigalloc).
-d DIR
Copy this folder into the new file system.
-M DIR
Last mounted directory.
-o OS
Creator OS.
-r REVISION
File system revision.
-S
Write only superblock and group descriptors (rescue, dangerous).
-D
Use direct I/O.
-z FILE
Save an undo file.
-n
Dry run: show what would happen.
-F
Force.
-q
Quiet.
-v
Verbose.
-V
Show the version.

Examples 10

$ run as a normal user# run as root (or with sudo)

  1. 1Create ext4

    mkfs.ext4 /dev/vdb2

    Asks before overwriting an existing file system.

  2. 2With a label

    mkfs.ext4 -L backup /dev/vdb2

    Mount with LABEL=backup.

  3. 3Less reserved space on a data disk

    mkfs.ext4 -m 1 /dev/vdb2

    1 % instead of 5 % (big disks waste a lot with 5 %).

  4. 4Many small files

    mkfs.ext4 -T small /dev/vdb2

    More inodes (mail or cache folders).

  5. 5Large files only

    mkfs.ext4 -T largefile4 /dev/vdb2

    Fewer inodes, more space for data.

  6. 6Dry run

    mkfs.ext4 -n /dev/vdb2

    Shows the backup superblock positions — useful for repair.

  7. 7ext3 or ext2

    mke2fs -t ext3 /dev/vdb3

    Older formats, for old systems.

  8. 8Fast create on big devices

    mkfs.ext4 -E lazy_itable_init=1,nodiscard /dev/vdb2

    Finishes the inode tables in the background.

  9. 9Check the result

    dumpe2fs -h /dev/vdb2 | grep -E 'volume name|Reserved block|Inode count'

    Settings of the new file system.

  10. 10Change settings later

    tune2fs -m 1 -L data2 /dev/vdb2

    No need to recreate.

Files

/etc/mke2fs.conf
Defaults and usage types.

Exit codes

0 :: Done. 1 :: Error.