In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
Ext2 and ext3
The Linux ext2/ext3 file system uses index nodes to record file information, acting like a file allocation table for windows. An index node is a structure that contains information about the length of a file, time of creation and modification, permissions, ownership, location on disk, and so on. A file system maintains an array of index nodes, and each file or directory corresponds to a unique element in the array of index nodes. The system assigns a number to each index node, which is the index number of the node in the array, called the index node number. The linux file system saves both the file index node number and the file name in the directory. So, a directory is just a table that combines the name of a file with its index node number, and each pair of file names and inodes in the directory is called a connection. For a file, there is a unique index node number, but for an index node number, there can be multiple file names. Therefore, the same file on disk can be accessed through different paths.
The file system previously used by Linux by default is the Ext2,ext2 file system is indeed efficient and stable. However, with the application of Linux system in critical business, the weakness of Linux file system is gradually exposed: the default ext2 file system used by the system is non-journal file system. This is an Achilles' heel in key industries. This article introduces the application of ext3 journaling file system under Linux.
The Ext3 file system is developed directly from the Ext2 file system. At present, the ext3 file system is very stable and reliable. It is fully compatible with the ext2 file system. Users can make a smooth transition to a well-journaled file system. This is actually the original intention of the original design of the ext3 journaling file system.
Characteristics of Ext3 journaling file system
1. High availability
After the system uses the ext3 file system, the system does not need to check the file system even after an abnormal shutdown. "after an outage, 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 the damage to the file system caused by unexpected downtime. In terms of ensuring data integrity, the ext3 file system has two modes to choose from. One of them is the "maintain consistency of file system and data at the same time" mode. In this way, you will never see junk files stored on disk due to an abnormal shutdown.
3. Speed of the file system:
Although when using the ext3 file system, you may sometimes have to write data multiple times when storing data, but overall, ext3 performs better than ext2. This is because ext3's logging function optimizes the drive read-write head of the disk. Therefore, the read and write performance of the file system is no lower than that of the Ext2 file system.
4. Data conversion
It is very easy to convert from ext2 file system to ext3 file system. You can simply type two commands to complete the conversion process. Users do not have to spend time backing up, restoring, formatting partitions, and so on. Using tune2fs, a gadget provided by the ext3 file system, you can easily convert an ext2 file system to an ext3 journaled file system. In addition, the ext3 file system can be loaded directly into the ext2 file system without any changes.
5. Multiple log modes
Ext3 has a variety of logging modes, one working mode is to log all file data and metadata (data that defines the data in the file system, that is, data) (data=journal mode); the other working mode is to log only the metadata, but not the data, that is, the so-called data=ordered or data=writeback mode. System managers can choose between the working speed of the system and the consistency of file data according to the actual working requirements of the system.
Actual use of the Ext3 file system
To create a new ext3 file system, for example, to format the ext3 file system with the hda8 partition on disk and log it 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 the time it takes for the ext3 file system to perform automatic detection is 180 days or every 31st time it is mount, in fact, this parameter can be adjusted as needed.
Mount the new file system to the primary partition / data directory as follows:
[root@stionxx root] # mount-t ext3 / dev/hda8 / data
Note: the / dev/hda8 partition formatted as the ext3 file system is loaded into the / data directory above.
Ext3 is based on ext2 code, which has the same disk format as ext2; this means that a cleanly unmounted ext3 file system can be remounted as an ext2 file system. The Ext3 file system can still be loaded as an ext2 file system, and you can switch a file system freely between ext3 and ext2. At this point, the ext3 log file on the ext2 file system still exists, but the ext2 does not recognize the log.
Taking the conversion of a file system as an example, convert an ext2 file system to an ext3 file system with the following command:
[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 converting an ext2 file system to an ext3 file system, it is not necessary to unmount the partition for conversion.
After the conversion is complete, don't forget to change the file system of the corresponding partition in the / etc/fstab file from the original ext2 to ext3.
Location of ext3 logs
Logs can be placed on another storage device, for example, on partition / dev/hda8. For example, to create an ext3 file system on / dev/hda8 and store the 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
E2fsck in the new e2fsprogs supports the ext3 file system. When an ext3 file system is corrupted, unmount the device and repair 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 from ext2 to ext3? There are four main reasons: availability, data integrity, speed, and ease of migration.
1. Availability
After an abnormal crash (power outage, system crash), the ext2 file system can be mounted and used only after the consistency check is done through e2fsck. The time it takes to run e2fsck depends largely on the size of the ext2 file system. It takes a long time to verify a slightly larger file system (dozens of GB). If there are a large number of files on the file system, the verification time is longer. It may take an hour or more to validate a file system with hundreds of GB. This greatly limits availability. In contrast, ext3 does not require file system verification unless there is a hardware failure, even if the system shuts down abnormally. This is because the data is written to disk in a way that the file system is always consistent. After an abnormal shutdown, the time it takes to restore the ext3 file system does not depend on the size of the file system or the number of files, but on the size of the "logs" required to maintain consistency. With the default log settings, the recovery time is only one second (depending on the hardware speed).
2. Data integrity
With the ext3 file system, the data integrity performance is reliably guaranteed when the computer is shut down abnormally. You can choose the type and level of data protection. You can choose to keep the file system consistent, but allow the data on the file system to be damaged during an abnormal shutdown; this can improve some speed in some cases (but not all). You can also choose to keep the reliability of the data consistent with the file system; this means that you won't see any data junk in the newly written files after the crash. This secure choice that keeps the reliability of the data consistent with the file system is the default.
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 choose one of the three logging modes to optimize speed, selectively sacrificing some data integrity.
4. Easy to migrate
You can enjoy the benefits of a reliable journaling file system without reformatting your hard drive and easily migrating from ext2 to ext3. Yes, you don't need to do a long, boring, possibly wrong "backup-reformat-restore" operation to experience the advantages of ext3. There are two ways to migrate:
If you upgrade your system, the Red Hat Linux installer will assist with the migration. All you need to do is press the select button for each file system.
Using the tune2fs program, you can add logging to an existing ext2 file system. If the file system is mounted during the conversion process (mount), the file ".journal" will appear in the root directory; if the file system is not mounted, the file will not appear in the file system. To convert a file system, just run tune2fs-j / dev/hda1 (or any device name of the file system you want to convert) and change the ext2 in the file / etc/fstab to ext3. If you want to convert your root file system, you must boot using initrd boot. Follow the mkinitrd manual to run the program and verify that your LILO or GRUB configuration is loaded with initrd (if not successful, the system will still boot, but the root file system will be mounted as ext2, not ext3, as you can confirm with the command cat / proc/mounts. For more information, see the man page online manual of the tune2fs command (execute man tune2fs).
In a word, ext3 journal file system is the simplest choice for linux system to transition from ext2 file system to journal file system at present, and its implementation is also the most concise. Because it is developed directly from the ext2 file system, the upgrade process of the system from ext2 file system to ext3 log file system is smooth, which can maximize the security of system data. At present, the safest way for linux systems to use journaling file systems is to choose ext3 file systems.
The latest ext4
Linux kernel has officially supported the new file system Ext4 since 2.6.28. Ext4 is an improved version of Ext3 that modifies some of the important data structures in Ext3, rather than just adding a logging function as Ext3 did to Ext2. Ext4 provides better performance and reliability, as well as richer features:
1. Compatible with Ext3. By executing several commands, you can migrate from Ext3 to Ext4 online without reformatting the disk or reinstalling the system. The original Ext3 data structure remains the same, and Ext4 acts on the new data, which, of course, gives the entire file system the larger capacity supported by Ext4.
two。 Larger file systems and larger files. Compared with the largest 16TB file system and the largest 2TB file currently supported by Ext3, Ext4 supports 1EB (1048576TB, 1EB=1024PB, 1PB=1024TB) file systems and 16TB files, respectively.
3. An unlimited number of subdirectories. Ext3 currently supports only 32000 subdirectories, while Ext4 supports an unlimited number of subdirectories.
4. Extents . Ext3 uses indirect block mapping, which is extremely inefficient when manipulating large files. For example, for a 100MB-sized file, you need to create a mapping table of 25600 blocks (each of which is 4KB) in Ext3. While Ext4 introduces the popular concept of extents in modern file system, each extent is a group of continuous data blocks, and the above file is expressed as "the file data is saved in the next 25600 data blocks", which improves a lot of efficiency.
5. Multi-block allocation. When writing data to the Ext3 file system, Ext3's block allocator can only allocate one 4KB block at a time. Writing a 100MB file calls the 25600-degree data block allocator, while Ext4's multi-block allocator "multiblock allocator" (mballoc) supports the allocation of multiple blocks in one call.
6. Delayed allocation. The block allocation strategy of Ext3 is to allocate as soon as possible, while the strategy of Ext4 and other modern file operating systems is to delay allocation as much as possible until the file is written in cache, so that the block allocation of the whole file can be optimized and the performance can be significantly improved when combined with the first two features.
7. Fast fsck. In the past, the first step in performing fsck would be slow because it checks all inode. Now Ext4 adds a list of unused inode to the inode table of each group, so that the fsck Ext4 filesystem can skip them and check only those inode that are in use.
8. Log check. Logs are the most commonly used part and can easily lead to disk hardware failures, while recovering data from corrupted logs can lead to more data corruption. The log verification function of Ext4 can easily determine whether the log data is corrupted, and it combines the two-phase logging mechanism of Ext3 into one phase, which not only increases security but also improves performance.
9. No log (No Journaling) mode. Logging always has some overhead, and Ext4 allows logging to be turned off so that some users with special needs can use it to improve performance.
10. Online defragmentation. Although delayed allocation, multi-block allocation, and extents can effectively reduce file system fragmentation, fragmentation is inevitable. Ext4 supports online defragmentation and will provide e4defrag tools to defragment individual files or entire file systems.
11. Inode-related features. Ext4 supports a larger inode, which is 256bytes by default for Ext4 to accommodate more extended attributes (such as nanosecond timestamps or inode versions) in inode than Ext3's default inode size of 128bytes. Ext4 also supports rapid extension attributes (fast extended attributes) and inode retention (inodes reservation).
twelve。 Persistent pre-allocation (Persistent preallocation). In order to ensure that the downloaded file has enough space to store, P2P software often creates an empty file of the same size as the downloaded file in advance, so as to avoid the download failure caused by the shortage of 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. There is an internal cache on the disk to re-adjust the write order of bulk data and optimize write performance, so the file system can write commit records only after the log data has been written to disk. If the commit records are written first, and the logs may be corrupted, then data integrity will be affected. Ext4 enables barrier by default. Only when all the data before barrier is written to disk can the data after barrier be written. (this feature can be disabled through the "mount-o barrier=0" command. )
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.