ext4

From Gentoo Wiki
(Redirected from User:Csfore/Ext4 rewrite)
Jump to:navigation Jump to:search
This page contains changes which are not marked for translation.

Resources

ext4 (fourth extended file system) is an open source disk filesystem and the most recent version of the extended series of filesystems. It is the primary file system in use by many Linux systems making it arguably the most stable and well tested file system supported in Linux.

Initially created as a fork of ext3, ext4 brings new features, performance improvements, and removal of size limits with moderate changes to the on-disk format. It can span volumes up to 1 Exabyte and with maximum file size of 16TB. Instead of the classic ext2/3 bitmap block allocation, ext4 uses extents, which improve large file performance and reduce fragmentation. Ext4 also provides more sophisticated block allocation algorithms (delayed allocation and multiblock allocation) giving the filesystem driver more ways to optimize the layout of data on the disk.

Installation

Kernel

Activate the following kernel options for the ext4 filesystem code:

KERNEL Enabling ext4 support
File systems  --->
  <*> The Extended 4 (ext4) filesystem Search for <code>CONFIG_CONFIG_EXT4_FS</code> to find this item.

Support for optional ext4 features:

KERNEL Enabling optional features for ext4
File systems  --->
  [*]   Ext4 POSIX Access Control Lists Search for <code>CONFIG_CONFIG_EXT4_FS_POSIX_ACL</code> to find this item.
  [*]   Ext4 Security Labels Search for <code>CONFIG_CONFIG_EXT4_FS_SECURITY</code> to find this item.
  [ ]   EXT4 debugging support
Note
The ext4 filesystem code can handle ext2, ext3 and ext4 filesystems. It will maintain compatibility if the filesystem is mounted as ext2 or ext3, and will provide upgradability when mounted as ext4. Additionally tune2fs can be used to add ext3- and ext4-specific features to an existing ext2 or ext3 filesystem, though certain hard limits will remain.
Warning
Both ext2 and ext3 file timestamps are affected by the year 2038 problem, while ext4 is Y2k38-safe since 2016, Linux kernel 4.3.6 and e2fsprogs 1.43. When an Extended filesystem specifically without a journal is desired, instead of ext2 a journal-less ext4 filesystem should be used; see ext4 without a journal.
Important
A normal ext4 system will not need to enable ext3 or ext2 options. The following filesystem options are here solely for historical purposes (ext3) and very special use-cases (ext2).

Ext3

The original ext3 driver was removed from the Linux kernel with version 4.3. There should remain only rare cases which make it necessary to use an ext3 filesystem, in which case the ext4 driver may be used.

Note
It is advised to use the ext4 driver to mount ext3 filesystems. The old ext3 driver should not be enabled.

Activate the following kernel options for ext3 driver:

KERNEL Enabling ext3 support
File systems  --->
   <*> Ext3 journalling file system support

Support for optional ext3 features:

KERNEL Enabling optional features for ext3
File systems  --->
   [*]   Default to 'data=ordered' in ext3 
   [*]   Ext3 extended attributes
   [*]     Ext3 POSIX Access Control Lists
   [*]     Ext3 Security Labels

Ext2

Note
The ext2 filesystem does not have journaling support.
Warning
When the original ext2 filesystem driver is enabled, it will be used to mount ext2 filesystems. Under normal circumstances it is highly recommended to use the ext4 driver, and not to enable the older ext2 driver: there is absolutely no necessity for a separate driver when the ext4 driver is already available to mount ext2 filesystems.
Note
The original ext2 filesystem code remains available for special cases. For example: compared to the ext4 filesystem code, the original ext2 code has a lower memory footprint. (In such cases, the ext4 driver will be entirely omitted, so ext3 and ext4 filesystems will not be available.)

Activate the following kernel options for ext2 support using the original ext2 filesystem code:

KERNEL Enabling ext2 support
File systems  --->
   <*> Second extended fs support

Support for optional ext2 features:

KERNEL Enabling optional features for ext2
File systems  --->
   [*]   Ext2 extended attributes
   [*]     Ext2 POSIX Access Control Lists
   [*]     Ext2 Security Labels

Large drive support

KERNEL Enabling large drives for x86 kernels
-*- Enable the block layer  --->
    [*]   Support for large (2TB+) block devices and files

USE flags

USE flags for sys-fs/e2fsprogs Standard EXT2/EXT3/EXT4 filesystem utilities

+tools Build extfs tools (mke2fs, e2fsck, tune2fs, etc.)
archive Add support for mke2fs to read a tarball as input. This allows not needing privileges. Needs app-arch/libarchive.
cron Install e2scrub_all cron script
fuse Build fuse2fs, a FUSE file system client for ext2/ext3/ext4 file systems
nls Add Native Language Support (using gettext - GNU locale utilities)
static-libs Build static versions of dynamic libraries as well
test Enable dependencies and/or preparations necessary to run tests (usually controlled by FEATURES=test but can be toggled independently)

Emerge

The sys-fs/e2fsprogs package and should be available as part of the default system set.

root #emerge --ask sys-fs/e2fsprogs

Usage

Creation

Warning
Any mkfs.* and mke2fs command will irreversibly destroy any content of the device (i.e. partition, volume, disk drive) or file it is told to format. Be sure to select the correct device and partition! (In the following examples /dev/sdx5 is used.)

To create an ext4 filesystem on the /dev/sdx5 partition:

root #mkfs.ext4 /dev/sdx5

Mounting

See filesystem.

Ext4 without a journal

In specific use-cases it may be desirable to create a journal-less filesystem. Even though ext2 does provide exactly that, it is also affected by the year 2038 problem regarding file timestamps. Only the ext4 filesystem has been made Y2K38-safe.

In order to get the current Extended filesystem without a journal, an ext4 filesystem can be created without the has_journal feature, or modified accordingly. (Note that this is not possible on ext3 filesystems.)

Removing the journal from an existing ext4 volume

To display filesystem features currently enabled on a specific ext2/3/4 volume:

root #dumpe2fs -h /dev/sdx5 | grep "^Filesystem features:"

To disable the journal, the filesystem must be unmounted first:

root #umount /dev/sdx5
root #tune2fs -O ^has_journal /dev/sdx5

The leading ^ disables the specified feature. Otherwise the feature would be enabled; i.e. to enable a journal on an existing ext2 or journal-less ext4 filesystem:

root #tune2fs -O has_journal /dev/sdx5

Running dumpe2fs again, the has_journal feature should no longer be listed. The filesystem can now be mounted again:

root #mount /dev/sdx5
EXT4-fs (/dev/sdx5): mounted filesystem abcdef01-2345-6789-9876-543210fedcba r/w without journal. Quota mode: disabled.

Create a new journal-less ext4 volume

To create (i.e. format) a new ext4 volume without a journal, the default options of the ext4 filesystem type have to be overridden:

root #mke2fs -t ext4 -O ^has_journal /dev/sdx5

Repeatedly creating a new journal-less ext4 volume: ext2v4

Ext4 filesystem tools create an Extended 4 filesystem with a journal by default. It may be tedious to continuously have to specify different options manually and repeatedly when creating such a journal-less ext4 volume on a regular basis, or it may be impossible to pass options when using automated filesystem creation from within other tools. For example, the systemd zram-generator doesn't support mke2fs options, instead it will always create a specified filesystem type, or short fs-type.

The mke2fs tool supports changing or adding filesystem types. For a journal-less ext4, a new Extended filesystem type, fs-type, has to be added to /etc/mke2fs.conf. Let's call it ext2-like version 4 Extended filesystem, or short ext2v4.

It suffices to just copy the ext4 lines and only remove the has_journal option, and to give it the new unique fs-type name, in this example ext2v4. The following multi-line awk command will accomplish this and display the result on screen. (It will not directly modify /etc/mke2fs.conf.) To be on the safe side, this can also be run as user (not as root):

user $
awk 'BEGIN { copy = 0 }
/^\[fs_types\]/ {
  print; next
}
/^\s*ext4\s*=\s*{/ {
  copy = 1
  buffer = $0
  next
}
copy {
  buffer = buffer ORS $0
  if ($0 ~ /^\s*}/) {
    mod = buffer
    sub(/ext4/, "ext2v4", mod)
    gsub(/,?has_journal,?/, "", mod)
    gsub(/,,/, ",", mod)
    gsub(/,}/, "}", mod)
    print buffer
    print mod
    copy = 0
  }
  next
}
{
  print
}' /etc/mke2fs.conf

By adding > /tmp/mke2fs.conf.new at the end of the above command (the last line should now look like this: }' /etc/mke2fs.conf > /tmp/mke2fs.conf.new) the result is saved to /tmp/mke2fs.conf.new, and the two files can be easily compared:

user $diff /etc/mke2fs.conf /tmp/mke2fs.conf.new
18a19,21
>       ext2v4 = {
>               features = extent,huge_file,flex_bg,metadata_csum,metadata_csum_seed,64bit,dir_nlink,extra_isize,orphan_file
>       }

If only the line specifying ext2v4 was added, it's safe to move the new file to /etc/mke2fs.conf. (The owner and permissions of /etc/mke2fs.conf must remain unchanged: root:root and 644.)

root #mv /etc/mke2fs.conf /etc/mke2fs.conf.bak
root #install -m 644 /tmp/mke2fs.conf.new /etc/mke2fs.conf
root #rm /tmp/mke2fs.conf.new
FILE /etc/mke2fs.confExample illustrating the added fs_type "ext2v4"
[fs_types]
        ext4 = {
                features = has_journal,extent,huge_file,flex_bg,metadata_csum,metadata_csum_seed,64bit,dir_nlink,extra_isize,orphan_file
        }
        ext2v4 = {
                features = extent,huge_file,flex_bg,metadata_csum,metadata_csum_seed,64bit,dir_nlink,extra_isize,orphan_file
        }

A new "ext2v4" filesystem may now be created by specifying it as the type:

root #mke2fs -t ext2v4 /dev/sdx5

Many tools will create a filesystem by running mkfs.*, where * stands for the specified fs-type. E.g. the systemd zram-generator will always run mkfs.fs-type to create the filesystem specified in the zram configuration file. In order for the new type ext2v4 to be available in this way, it suffices to create the mkfs.fs-type symlink to mke2fs:

root #ln -s mke2fs /sbin/mkfs.ext2v4

Now, a journal-less ext4 filesystem can be created as simple as:

root #mkfs.ext2v4 /dev/sdx5

Utilities

Utilities included in the package consist of:

Utility Description Man page
badblocks A small program for stress testing block devices. badblocks(8)
debugfs An ext2/ext3/ext4 file system debugger. debugfs(8)
dumpe2fs A tool to dump ext2/ext3/ext4 filesystem information. dumpe2fs(8)
e2fsck A tool for checking ext2/ext3/ext4 filesystems. e2fsck(8)
e2image A tool for saving critical ext2/ext3/ext4 filesystem metadata to a file. e2image(8)
e2label A tool to change the label on an ext2/ext3/ext4 filesystem (symlinks to tune2fs).
e2undo A tool to replay an undo log for an ext2/ext3/ext4 filesystem. e2undo(8)
fsck.ext2 Checks, specifically, an ext2 filesystem (symlinks to e2fsck).
fsck.ext3 Checks, specifically, an ext3 filesystem (symlinks to e2fsck).
fsck.ext4 Checks, specifically, an ext4 filesystem (symlinks to e2fsck).
fsck.ext4dev Checks, specifically, an ext4dev filesystem (symlinks to e2fsck).
logsave A tool to save the output of a command in a logfile. logsave(8)
mke2fs The base program for creating ext2/ext3/ext4 filesystems. Creation commands symlink here. mke2fs(8)
mkfs.ext2 Creates, specifically, an ext2 filesystem (symlinks to mke2fs).
mkfs.ext3 Creates, specifically, an ext3 filesystem (symlinks to mke2fs).
mkfs.ext4 Creates, specifically, an ext4 filesystem (symlinks to mke2fs).
mkfs.ext4dev Creates, specifically, an ext24dev filesystem (symlinks to mke2fs).
resize2fs An ext2/ext3/ext4 filesystem resizer. resize2fs(8)
tune2fs Adjust tunable filesystem parameters on ext2/ext3/ext4 filesystems. tune2fs(8)
chattr Change file attributes on a Linux filesystem. chattr(1)
lsattr List ext2/ext3/ext4 file attributes. lsattr(1)
e2freefrag Report free space fragmentation information. e2freefrag(8)
e4defrag An online defragmenter for ext4 filesystem. e4defrag(8)
filefrag Report on file fragmentation. filefrag(8)
mklost+found Create a lost+found directory on a mounted ext2/ext3/ext4 file system. mklost+found(8)

See also

  • XFS — a high-performance journaling filesystem
  • Btrfs — a copy-on-write (CoW) filesystem for Linux aimed at implementing advanced features while focusing on fault tolerance, self-healing properties, and easy administration.
  • FATfilesystem originally created for use with MS-DOS (and later pre-NT Microsoft Windows).

External resources

References