Ext4
From ArchWiki
i18n |
---|
Česky |
English |
Türkçe |
简体中文 |
Contents |
Introduction
Ext4 is the evolution of the most used Linux filesystem, Ext3. In many ways, Ext4 is a deeper improvement over Ext3 than Ext3 was over Ext2. Ext3 was mostly about adding journaling to Ext2, but Ext4 modifies important data structures of the filesystem such as the ones destined to store the file data. The result is a filesystem with an improved design, better performance, reliability, and features.
Source: Ext4 - Linux Kernel Newbies
Creating ext4 Partitions From Scratch
- Upgrade your system: pacman -Syu
- Format the partition: mkfs.ext4 /dev/sdxY (replace sdxY with the device to format (e.g. sda1))
- Mount the partition
- Add an entry to /etc/fstab, using the filesystem 'type' ext4
Migrating From ext3 to ext4
There are two ways of migrating partitions from ext3 to ext4:
- mounting ext3 partitions as ext4 without converting (compatibility)
- converting ext3 partitions to ext4 (performance)
These two approaches are described below.
Mounting ext3 Partitions as ext4 Without Converting
Rationale
A compromise between fully converting to ext4 and simply remaining with ext3 is to mount existing ext3 partitions as ext4.
Pros:
- Compatibility (the filesystem can continue to be mounted as ext3) – This allows users to still read the filesystem from other distributions/operating systems without ext4 support (e.g. Windows with ext3 drivers)
- Improved performance (though not as much as a fully-converted ext4 partition) – See Ext4 - Linux Kernel Newbies for details
Cons:
- Fewer features of ext4 are used (only those that do not change the disk format such as multiblock allocation and delayed allocation)
Procedure
- Edit /etc/fstab and change the 'type' from ext3 to ext4 for any partitions you would like to mount as ext4.
- Re-mount the affected partitions.
- Done.
Converting ext3 Partitions to ext4
Rationale
To experience the benefits of ext4, an irreversible conversion process must be completed.
Pros:
- Improved performance and new features – See Ext4 - Linux Kernel Newbies for details
Cons:
- Cannot be read/written with ext3 drivers (note that there is no known ext4 driver for Windows)
- Irreversible (ext4 partitions cannot be 'downgraded' to ext3)
Prerequisites
The following software is required on the Arch Linux system:
- kernel26 >= 2.6.28
- e2fsprogs >= 1.41
If converting one's /boot partition to ext4:
- grub >= 0.97 (with ext4 patch)
If converting one's root (/) partition to ext4:
- mkinitcpio >= 0.5.20
If converting one's root (/) partition to ext4, the following software is also needed on a bootable CD/USB drive:
- e2fsprogs >= 1.41
Procedure
These instructions were adapted from http://ext4.wiki.kernel.org/index.php/Ext4_Howto and http://bbs.archlinux.org/viewtopic.php?id=61602. They have been tested and confirmed by this author as of January 16, 2009.
- UPGRADE! Perform a sysupgrade to ensure all required packages are up-to-date: pacman -Syu
- BACK-UP! Back-up all data on any ext3 partitions that are to be converted to ext4. Although ext4 is considered 'stable' for general use, it is still a relatively young and untested file system. Furthermore, this conversion process was only tested on a relatively simple setup; it is impossible to test each of the many possible configurations the user may be running.
- Edit /etc/fstab and change the 'type' from ext3 to ext4 for any partitions that are to be converted to ext4.
- The conversion process with e2fsprogs must be done when the drive is not mounted. If converting one's root (/) partition, the simplest way to achieve this is to boot from some other live medium, as described in the 'Prerequisites' section above.
- Boot the live medium (if necessary).
- For each partition to be converted to ext4:
- Ensure the partition is NOT mounted
- Run tune2fs -O extents,uninit_bg,dir_index /dev/the_partition (where /dev/the_partition is replaced by the path to the desired partition, such as /dev/sda1)
- Run fsck -fp /dev/the_partition
- Reboot Arch Linux!
Migrating files to extents
Despite the filesystem is now converted to ext4, all files that have been written before the conversion do not yet take advantage of the new extents of ext4, which will improve large file performance and reduce fragmentation and filesystem check time. In order to fully take advantage of ext4, all files would have to be rewritten on disk. A utility called e4defrag is being developed and will take care of this task ; however, it is not yet ready for production.
Fortunately, it is possible to use the chattr program, which will cause the kernel to rewrite the file using extents. It is possible to run this command on all files and directories of one partition (e.g. if /home is on a dedicated partition):
find /home -xdev -type f -print0 | xargs -0 chattr +e find /home -xdev -type d -print0 | xargs -0 chattr +e
It is recommended to test this command on a small number of files first, and check if everything is going all right. It may also be useful to check the filesystem after conversion.
Using the lsattr command, it is possible to check that files are now using extents. The letter 'e' should appear in the attribute list of the listed files.
Troubleshooting
Kernel Panic
One problem this author encountered was a kernel panic after converting the root (/) partition to ext4. This is because the initial ramdisk was detecting the partition as 'ext4dev', rather than 'ext4'. It was a simple matter to boot with the 'fallback' initial ramdisk and re-create the 'default' initial ramdisk:
# mkinitcpio -p kernel26
During the creation process, mkinitcpio correctly detected and included ext4 modules in the initial ramdisk.
GRUB Error 13
After a recent kernel update, this author encountered a GRUB error while attempting to boot from an ext4 /boot partition:
Error 13: Invalid or unsupported executable format
The solution is to boot from the live medium and chroot into the Arch Linux installation:
# mkdir /mnt/arch # mount -t ext4 /dev/sda1 /mnt/arch # mount -t proc proc /mnt/arch/proc # mount -t sysfs sys /mnt/arch/sys # mount -o bind /dev /mnt/arch/dev
# chroot /mnt/arch /bin/bash
If /boot is on a separate partition, this partition must also be mounted:
# mount -t ext4 /dev/sda2 /boot
Then, the following command should resolve the issue. (Does anyone know why?):
# grub-install --recheck /dev/sda
Data Corruption
Some early adopters of ext4 encountered data corruption after a hard reboot. Please read Ext4 data loss; explanations and workarounds for more information.
Since kernel 2.6.30, ext4 is considered "safe(er)." Several patches improved the robustness of ext4 - albeit at a slight performance cost. A new mount option (auto_da_alloc) can be used to disable this behavior. For more information, please read Linux 2 6 30 - Filesystems performance improvements.
For kernel versions earlier than 2.6.30, consider adding rootflags=data=ordered to the kernel line in GRUB's menu.lst as a preventative measure.