ext4 (fourth extended filesystem) is the default filesystem on Ubuntu, Debian and Linux Mint, and the most widely used filesystem on Linux. It is mature, fast for everyday workloads, protects data with a journal, can be grown while mounted and shrunk while unmounted, and every Linux rescue tool understands it.
This guide shows how to format a partition as ext4 with mkfs.ext4, which options are worth changing (label, reserved space, inodes), and how to inspect, tune, check and resize an ext4 filesystem afterwards with tune2fs, e2fsck and resize2fs. We tested every command on Ubuntu 26.04 with e2fsprogs 1.47.2; they are the same on Ubuntu 24.04, Debian, RHEL, Rocky Linux and Fedora.
Warning: formatting erases all data on the partition. Back up anything you need and double-check the device name before you run mkfs.
Quick Answer
To format the partition /dev/sdb1 as ext4 with the label “data”:
lsblk -fsudo umount /dev/sdb1sudo mkfs.ext4 -L data /dev/sdb1
If the disk has no partition yet, create one first: see how to create and format disk partitions in Linux.
Step 1 of 4Find the Partition
lsblk -o NAME,SIZE,FSTYPE,LABEL,MOUNTPOINTS
NAME SIZE FSTYPE LABEL MOUNTPOINTS
sda 40G
├─sda1 1G vfat /boot/efi
└─sda2 39G ext4 /
sdb 10G
└─sdb1 10G
Here /dev/sdb1 is the new, empty partition. Never format a partition that is mounted on /, /boot or /boot/efi: that is your running system. On NVMe drives, partitions are named like /dev/nvme1n1p1.
Step 2 of 4Unmount the Partition
mkfs.ext4 refuses to touch a mounted partition:
/dev/sdb1 is mounted; will not make a filesystem here!
If the MOUNTPOINTS column shows a path, unmount it first:
sudo umount /dev/sdb1
If that fails with “target is busy”, see how to mount and unmount disks in Linux.
Step 3 of 4Format the Partition as ext4
sudo mkfs.ext4 -L data /dev/sdb1
mke2fs 1.47.2 (1-Jan-2025)
Discarding device blocks: done
Creating filesystem with 2621184 4k blocks and 655360 inodes
Filesystem UUID: 7ce75f4a-7369-4cde-b9d3-1e139b9f4938
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632
Allocating group tables: done
Writing inode tables: done
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information: done
What the output tells you:
- 4k blocks: the block size, the smallest unit of storage. 4096 bytes is the default and the right choice for almost every disk.
- 655360 inodes: the maximum number of files and folders the filesystem can hold (one per 16 KB of space by default).
- Filesystem UUID: the unique ID you use in
/etc/fstab. - Superblock backups: copies of the filesystem’s key metadata.
e2fsckuses them to repair the filesystem if the main superblock is damaged.
If the partition already contains a filesystem, mkfs.ext4 asks before overwriting it:
/dev/sdb1 contains a ext4 file system labelled 'data'
created on Tue Dec 1 08:57:15 2026
Proceed anyway? (y,N)
Type y to continue. In scripts, add -F to skip the question. mkfs -t ext4 /dev/sdb1 is an older way to write the same command.
Step 4 of 4Check the Result and Mount It
lsblk -f /dev/sdb1sudo mkdir -p /datasudo mount /dev/sdb1 /datadf -hT /data
Filesystem Type Size Used Avail Use% Mounted on
/dev/sdb1 ext4 9.8G 2.1M 9.3G 1% /data
Notice that Avail (9.3G) is about 5% smaller than Size (9.8G). That is the reserved space explained in the next section. A new ext4 filesystem belongs to root; to let your user write to it, run sudo chown $USER:$USER /data. To mount it automatically at boot, add it to /etc/fstab by UUID as shown in Step 6 of our partitioning guide.
Useful mkfs.ext4 Options
The defaults are good for a general-purpose disk. These options are worth knowing:
| Option | What it does | Example |
|---|---|---|
-L | Set a volume label (up to 16 characters) | -L data |
-m | Percentage of space reserved for root (default 5) | -m 1 |
-T | Usage type that sets the inode ratio: small, big, huge, largefile, largefile4 | -T largefile |
-i | Bytes per inode (default 16384); lower = more inodes | -i 8192 |
-N | Exact minimum number of inodes | -N 2000000 |
-n | Dry run: show what would be created without writing anything | -n |
-F | Don’t ask before overwriting an existing filesystem | -F |
-E | Extended options, e.g. RAID stride or disabling lazy initialisation | -E lazy_itable_init=0 |
-O | Turn features on or off | -O ^has_journal |
Reserved blocks (-m): get back 5% of a data disk
By default ext4 keeps 5% of the space for the root user, so the system can still write logs and recover when a normal user fills the disk. That makes sense on the root filesystem, but on a 4 TB data disk it hides 200 GB. For data and backup disks, reserve 1% or nothing:
sudo mkfs.ext4 -m 1 -L data /dev/sdb1
You can also change it later, without reformatting and even while the filesystem is mounted:
sudo tune2fs -m 1 /dev/sdb1
tune2fs 1.47.2 (1-Jan-2025)
Setting reserved blocks percentage to 1% (26211 blocks)
On our 10 GB test partition this raised the available space in df from 9.3G to 9.7G. Keep the default 5% on the root (/) filesystem.
Inodes (-T, -i, -N): plan for many small files or a few large ones
ext4 creates a fixed number of inodes when you format it, and every file and folder uses one. If they run out, you get No space left on device even though df -h shows free space. We reproduced it on a test filesystem with very few inodes:
touch: cannot touch '/mnt/d/f117': No space left on devicedf -i /mnt/dFilesystem Inodes IUsed IFree IUse% Mounted on /dev/sdb2 128 128 0 100% /mnt/d
The inode count can’t be changed after formatting, so choose it up front:
- Millions of small files (mail servers, caches, build directories, PHP sessions): use
-T smallor-i 8192for more inodes. On a 10 GB partition-i 8192doubled the inodes from 655,360 to 1,310,720. - Few, large files (videos, VM images, database files, backups): use
-T largefile(one inode per 1 MB) or-T largefile4(per 4 MB) to waste less space on inode tables.
Check inode use on existing filesystems at any time with df -i.
Lazy initialisation
To format quickly, mkfs.ext4 leaves part of the inode tables to be initialised in the background after the first mount, by the ext4lazyinit kernel thread. On a large hard disk this can cause noticeable disk activity for a while. If you are about to benchmark the disk, format with -E lazy_itable_init=0,lazy_journal_init=0 to do all the work up front; formatting then takes longer.
Without a journal
-O ^has_journal creates ext4 without its journal. It writes slightly less, but after a crash or power cut a full e2fsck is needed and recent changes may be lost. Only use it for throw-away data such as caches on SD cards; for USB sticks shared with other systems, use exFAT instead (see how to format a USB drive in Linux).
View and Change ext4 Settings with tune2fs
tune2fs -l shows a filesystem’s settings and status:
sudo tune2fs -l /dev/sdb1 | grep -E "volume name|features|Inode count|Block count|Reserved block|Block size|Mount count|Check interval"
Filesystem volume name: data
Filesystem features: has_journal ext_attr resize_inode dir_index orphan_file filetype extent 64bit flex_bg metadata_csum_seed sparse_super large_file huge_file dir_nlink extra_isize metadata_csum
Inode count: 655360
Block count: 2621184
Reserved block count: 131059
Block size: 4096
Mount count: 1
Check interval: 0 ()
Common changes, all possible without reformatting:
sudo e2label /dev/sdb1 backupsudo tune2fs -m 1 /dev/sdb1sudo tune2fs -c 30 -i 1m /dev/sdb1
The first renames the volume (tune2fs -L does the same), the second changes the reserved space, and the third enables an automatic e2fsck every 30 mounts or every month, whichever comes first. New filesystems have periodic checks turned off (Check interval: 0), which is the right default for servers that rarely reboot.
Check and Repair an ext4 Filesystem
e2fsck (also called as fsck.ext4) checks and repairs ext4. Always run it on an unmounted filesystem; it refuses to repair a mounted one:
/dev/sdb1 is mounted.
e2fsck: Cannot continue, aborting.
Unmount it and force a full check:
sudo umount /dev/sdb1sudo e2fsck -f /dev/sdb1
e2fsck 1.47.2 (1-Jan-2025)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/sdb1: 12/655360 files (0.0% non-contiguous), 64284/2621184 blocks
If problems are found, e2fsck asks before fixing each one; add -y to answer yes to all. Use -n for a read-only check that changes nothing. To check the root filesystem, boot from a live USB or rescue mode, because it can’t be unmounted while the system runs from it.
Resize an ext4 Filesystem
ext4 can grow while mounted and shrink while unmounted. Resize the partition first when growing, and the filesystem first when shrinking.
Grow (after enlarging the partition, for example with growpart on a cloud VM or parted resizepart):
sudo resize2fs /dev/sdb1
The filesystem on /dev/sdb1 is now 2621184 (4k) blocks long.
Without a size, resize2fs fills the whole partition. This works online, so no downtime is needed.
Shrink (unmounted, after a forced check), here to 5 GB:
sudo umount /dev/sdb1sudo e2fsck -f /dev/sdb1sudo resize2fs /dev/sdb1 5G
Only then make the partition smaller, and never smaller than the filesystem. Take a backup before shrinking anything. XFS, the default on RHEL, can’t shrink at all, which is one reason to prefer ext4 when sizes may change.
ext4 vs XFS vs Btrfs
| ext4 | XFS | Btrfs | |
|---|---|---|---|
| Default on | Ubuntu, Debian, Mint | RHEL, Rocky, AlmaLinux | Fedora desktop, openSUSE |
| Shrink | Yes (offline) | No | Yes (online) |
| Snapshots, compression | No | No | Yes |
| Strength | Simple, reliable, best tool support | Very large files and volumes, parallel I/O | Snapshots, checksums for data |
For a general-purpose server or desktop disk, ext4 is the safe default.
Troubleshooting
/dev/sdb1 is mounted; will not make a filesystem here!
Unmount it first with sudo umount /dev/sdb1. Check with lsblk -f that you picked the right partition.
/dev/sdb1 is apparently in use by the system; will not make a filesystem here!
The partition is not mounted but is held by something else: it is part of an LVM volume group, a software RAID array (mdadm), an active swap area or an encrypted (LUKS) volume. Check with lsblk, which shows LVM, RAID and crypt devices under the partition. Format the logical volume or array (for example /dev/vg0/data) instead, or remove the partition from that setup first.
mount: wrong fs type, bad option, bad superblock
If an ext4 partition that used to work suddenly won’t mount and e2fsck reports Bad magic number in super-block, the main superblock is damaged. ext4 keeps backup copies. List where they are with a dry run of mkfs.ext4, which writes nothing when you pass -n (use the same options as when the filesystem was created):
sudo mkfs.ext4 -n /dev/sdb1
Then repair the filesystem from the first backup:
sudo e2fsck -fy -b 32768 /dev/sdb1
e2fsck: Superblock invalid, trying backup blocks...
data: ***** FILE SYSTEM WAS MODIFIED *****
In our test we wiped the primary superblock of a filesystem holding a file; after e2fsck -b 32768 it mounted again with the file intact. Be very careful to include -n: without it, mkfs.ext4 formats the partition.
No space left on device, but df shows free space
The filesystem has run out of inodes. Confirm with df -i. Delete unneeded small files (old sessions, cache files, mail queues) to free inodes. The permanent fix is to back up, reformat with more inodes (-T small or -i 8192) and restore.
The disk is smaller than expected
Disk makers count 1 GB as 109 bytes while df -h shows GiB (230 bytes), and ext4 uses some space for inode tables and the journal. On a data disk, also reduce the 5% reserved space with tune2fs -m 1.
Frequently Asked Questions
What is the difference between mkfs.ext4 and mkfs -t ext4?
None. mkfs -t ext4 simply runs mkfs.ext4, which itself is the mke2fs program from e2fsprogs.
Can I format a whole disk as ext4 without a partition?
Yes, sudo mkfs.ext4 /dev/sdb works and Linux can mount it. Creating one partition first is still recommended, because tools and other operating systems may otherwise treat the disk as empty and offer to initialise it.
Can I convert ext4 to XFS (or back) without losing data?
No. There is no in-place conversion between ext4 and XFS. Copy the data elsewhere, reformat, and copy it back. (The only in-place conversions are ext3 to ext4 and ext4 to Btrfs with btrfs-convert.)
Does Windows read ext4?
Not natively. WSL2 can mount ext4 disks with wsl --mount, and third-party drivers exist. For a disk shared between Linux and Windows, use exFAT or NTFS.
Conclusion
To format a partition as ext4, unmount it and run sudo mkfs.ext4 -L label /dev/sdXN. For data disks, lower the reserved space with -m 1, and choose the inode ratio with -T if you expect millions of small files or only large ones, since that can’t be changed later. Afterwards, tune2fs changes labels and settings, e2fsck -f checks the filesystem, and resize2fs grows it online or shrinks it offline.
Related guides:
- How to create and format disk partitions in Linux
- How to mount and unmount disks in Linux
- How to format a USB drive in Linux
- Back up and clone disk partitions
How did it make you feel?
