Ext2, ext3 and ext4

Source: Internet
Author: User

Ext2 and ext3

The Linux ext2/ext3 file system uses an index node to record file information, acting as a file allocation table in windows. An index node is a structure that contains information such as the length of a file, creation and modification time, permission, ownership, and location on the disk. A file system maintains an array of index nodes. Each file or directory corresponds to the unique element in the index node array. The system assigns a number to each index node, that is, the index number of the node in the array, which is called the index node number. The Linux File System saves the node number and file name of the file index in the directory at the same time. Therefore, the directory is only a table that combines the file name and its index node number. Each pair of file names in the Directory and the index node number are called a connection. A file has a unique index node number that corresponds to it. For an index node number, multiple file names can correspond to it. Therefore, the same file on the disk can be accessed through different paths.
By default, the file system used before Linux is ext2, which is indeed efficient and stable. However, with the application of the Linux System in key services, the weakness of the Linux file system is gradually revealed: The ext2 file system used by the system by default is not a log file system. This is a critical weakness in key industries. This article describes how to use the ext3 Log File System in Linux.
The ext3 file system is developed directly from the ext2 file system. Currently, the ext3 file system is very stable and reliable. It is fully compatible with the ext2 file system. You can smoothly transition to a file system with sound log functions. This is actually the original intention of the initial design of the ext3 log file system.

Ext3 log file system features
1. High Availability
After the system uses the ext3 file system, the system does not need to check the file system even after it is shut down abnormally. After a crash occurs, it takes tens of seconds to restore the ext3 file system.
2. Data Integrity:
The ext3 file system can greatly improve the integrity of the file system and avoid unexpected downtime damage to the file system. There are two modes available for ext3 file systems to ensure data integrity. One of them is the "Maintain file system and data consistency at the same time" mode. In this way, you will never see junk files stored on the disk due to abnormal shutdown.
3. File System speed:
Although the ext3 file system may have to write data multiple times during data storage, in general, ext3 is better than ext2. This is because the log function of ext3 optimizes the disk drive read/write headers. Therefore, the read/write performance of the file system is not lower than that of the ext2 file system.
4. Data Conversion
It is very easy to convert an ext2 file system to an ext3 file system. Simply Type Two commands to complete the conversion process. You do not need to take the time to back up, restore, and format partitions. Use the tune2fs tool provided by an ext3 File System to easily convert the ext2 file system to an ext3 log file system. In addition, the ext3 file system can be directly loaded into the ext2 file system without any changes.
5. Multiple log Modes
Ext3 has multiple log modes, one of which is to define the data in the file system, that is, the data of all file data and metadata) logging (Data = journal mode); another mode is to record logs only for metadata, but not for data, that is, the so-called data = ordered or data = writeback mode. System Administrators can choose between system speed and file data consistency based on the actual work requirements of the system.

Ext3 File System
Create a new ext3 file system. For example, to format the hda8 partition on the disk to the ext3 file system and record the logs in the/dev/hda1 partition, the procedure is as follows:
[Root @ stationxx root] # mke2fs-J/dev/hda8
Mke2fs 1.24a (02-sep-2001)
Filesystem label =
OS type: Linux
Block size = 1024 (log = 0)
......
Creating Journal (8192 blocks): Done
Writing superblocks and filesystem accounting information: Done
This filesystem will be automatically checked every 30 mounts or
180 days, whichever comes first. Use tune2fs-C or-I to override.
When creating a new file system, you can see that when the ext3 file system performs an automatic detection for 180 days or 31st times is mounted, this parameter can be adjusted as needed.

Mount the new file system to the primary partition/data directory:
[Root @ stionxx root] # Mount-T ext3/dev/hda8/Data
Note: The/dev/hda8 partition formatted as the ext3 file system is loaded to the/data directory.
The ext3 code is based on ext2, and its disk format is the same as that of ext2. This means that an ext3 file system with a clean unload can be remounted as an ext2 file system. The ext3 file system can still be loaded into the ext2 file system. You can switch a file system between ext3 and ext2. The ext3 log file still exists in the ext2 file system, but ext2 cannot recognize the log.

Take the conversion file system as an example to convert the ext2 File System to the ext3 file system. The command is as follows:
[Root @ stationxx root] # tune2fs-J/dev/hda9
Tune2fs 1.24a (02-sep-2001)
Creating journal inode: Done
This filesystem will be automatically checked every 31 mounts or
180 days, whichever comes first. Use tune2fs-C or-I to override.
In this way, the original ext2 file system is converted to the ext3 file system. Note that when you convert an ext2 file system to an ext3 file system, you do not need to upload or convert the partition.
After the conversion, do not forget to change the file system of the corresponding partition in the/etc/fstab file from the original ext2 to ext3.

Storage location of ext3 logs
Logs can be stored on another storage device, such as/dev/hda8. For example, to create an ext3 File System on/dev/hda8 and store logs on an external device/dev/hda2, run the following command:
[Root @ stationxx root] # mke2fs-J device =/dev/hda8/dev/hda2
Ext3 File System Repair
The e2fsck in the new e2fsprogs supports the ext3 file system. When an ext3 file system is damaged, uninstall the device and fix it with e2fsck:
[Root @ stationxx root] # umount/dev/hda8
[Root @ stationxx root] # e2fsck-fy/dev/hda8

 

Advantages of ext3
Why do you need to migrate data from ext2 to ext3? There are four main reasons: availability, data integrity, speed, and ease of migration.
1. Availability
After an abnormal host (power failure or system crash), The ext2 file system can be loaded and used only after the e2fsck is used for consistency verification. The time for running e2fsck depends on the size of the ext2 file system. It takes a long time to verify larger file systems (dozens of GB. If the number of files in the file system is large, the verification time is longer. It may take an hour or longer to verify a file system of several hundred GB. This greatly limits availability. In contrast, ext3 does not require file system verification unless a hardware fault occurs. This is because the data is always written to the disk in the same way as the file system. After an abnormal shutdown, the recovery time of the ext3 file system does not depend on the file system size or number of files, but on the size of the "log" required for maintaining consistency. With the default log settings, the restoration takes only one second (depending on the hardware speed ).
2. Data Integrity
When an ext3 file system is used to shut down abnormally, the complete data performance is reliably guaranteed. You can select the type and level of data protection. You can choose to ensure the consistency of the file system, but allow the data on the file system to be damaged during abnormal shutdown; this can increase the speed (but not all) in some situations ). You can also choose to keep the data reliability consistent with the file system; this means that you will not see any data spam in the newly written files after the server goes on. The default setting is used to ensure data reliability consistent with that of the file system.
3. Speed
Although ext3 writes more data than ext2, ext3 is often faster than ext2 (high data stream ). This is because the log function of ext3 optimizes the rotation of the Hard Disk Head. You can select one of the three log modes to optimize the speed and selectively sacrifice some data integrity.
4. Easy migration
You can easily migrate from ext2 to ext3 without reformatting the hard disk and enjoy the advantages of a reliable log file system. Yes, you do not need to perform a long, boring, and potentially incorrect "backup-Reformat-Restore" operation to experience the advantages of ext3. There are two migration methods:
· If you upgrade your system, the Red Hat Linux installer will assist in migration. The job you need to do is to click the select button for each file system.
· Use the tune2fs program to add the log function to the existing ext2 file system. If the file system has been mounted during the conversion process, the file will appear in the root directory ". journal "; if the file system is not loaded, the file will not appear in the file system. To convert a file system, you only need to run tune2fs-J/dev/hda1 (or any device name of the file system you want to convert ), at the same time, change the ext2 in the/etc/fstab file to ext3. If you want to convert your root file system, you must use the initrd boot to start. Follow the mkinitrd manual description to run the program and check that initrd is loaded in your LILO or GRUB configuration. (if not, the system can still be started, but the root file system will be loaded as ext2, instead of ext3, you can use the command CAT/proc/mounts to confirm this .) For more information, see the man page online manual for the tune2fs command (run man tune2fs ).

All in all, the ext3 Log File System is currently the simplest option for Linux from the ext2 File System to the log file system, and the implementation method is also the most concise. Because it is developed directly from the ext2 file system, the system is smoothly upgraded from the ext2 File System to the ext3 log file system, ensuring the security of system data to the maximum extent. Currently, the log file system is used in Linux. The safest way is to select the ext3 file system.

 

Latest ext4
Linux Kernel has officially supported the new file system ext4 since 2.6.28. Ext4 is the ultimate version of ext3. It modifies some important data structures in ext3, not just like ext3 for ext2, but adds a log function. Ext4 provides better performance and reliability, as well as richer features:

1. compatible with ext3. Execute several commands to migrate from ext3 online to ext4 without reformatting the disk or reinstalling the system. The original ext3 data structure is retained, and ext4 is used for new data. Of course, the entire file system also obtains a larger capacity supported by ext4.
2. Larger file systems and larger files. Compared with the ext3 currently supports a maximum of 16 TB file systems and a maximum of 2 TB files, ext4 supports 1 EB (1,048,576 TB, 1 EB = 1024 Pb, 1 Pb = Tb) file systems, and 16 TB files.
3. unlimited number of subdirectories. Ext3 currently only supports 32,000 subdirectories, while ext4 supports an unlimited number of subdirectories.
4. extents. Ext3 uses indirect block ing. When operating large files, the efficiency is extremely low. For example, for a 100 MB file, a ing table of 25,600 data blocks (4 kb for each data block) must be created in ext3. Ext4 introduces the popular extents concept in modern file systems. Each extent is a set of continuous data blocks, the preceding file indicates that the file data is stored in the next 25,600 data blocks, which improves the efficiency.
5. Multi-block allocation. When writing data to the ext3 file system, the ext3 data block distributor can allocate only one 4 kb block at a time. To write a 100 MB file, it is necessary to call the 25,600 data block distributor, the multiblock Allocator (mballoc) Multi-block allocator of ext4 supports allocating multiple data blocks at a time.
6. Delay allocation. The data block allocation policy of ext3 is to allocate as soon as possible, while the policy of ext4 and other modern file operating systems is to delay the allocation as much as possible, data blocks are allocated and written to the disk only after the files are written to the cache. This optimizes the data block allocation of the entire file and significantly improves the performance with the first two features.
7. Fast fsck. In the past, the first step of fsck execution was very slow, because it needs to check all inode. Now, ext4 adds a list of inode not used in each group to the inode table, in the future, The fsck ext4 file system can skip them and only check the inode in use.
8. Log verification. Logs are the most common part and can easily lead to disk hardware faults. Restoring data from damaged logs will cause more data corruption. The log verification function of ext4 can easily determine whether the log data is damaged. It also combines the two-phase Log Mechanism of ext3 into one phase, which improves the performance while increasing security.
9. No journaling mode. The log has some overhead. ext4 allows you to disable the log so that users with special requirements can improve the performance.
10. Online fragment. Although delayed allocation, multi-block allocation, and extents can effectively reduce File System fragments, fragments are inevitable. Ext4 supports online fragment and provides the e4defrag tool for fragment of individual files or the entire file system.
11. inode-related features. Ext4 supports a larger inode. Compared with the default inode size of 128 bytes in ext3, ext4 can accommodate more extended attributes (such as the nanosecond timestamp or inode version) in inode ), by default, the inode size is 256 bytes. Ext4 also supports fast extended attributes and inode reservation ).
12. Persistent preallocation ). In order to ensure sufficient storage space for the downloaded files, P2P software often creates an empty file with the same size as the downloaded file in advance, this prevents downloading failures due to insufficient disk space in the next few hours or days. Ext4 implements persistent pre-allocation at the file system level and provides the corresponding API (posix_fallocate () in libc), which is more efficient than the application software itself.
13. Barrier is enabled by default. The disk is equipped with an internal cache to re-adjust the write operation sequence of batch data and optimize the write performance. Therefore, the file system must write the log data to the disk before writing the commit record, if the commit record is written first, and the log may be damaged, data integrity will be affected. In ext4, barrier is enabled by default. Only data before barrier is written to the disk can be written to data after barrier. (You can disable this feature by running the "Mount-O barrier = 0" command .)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.