Ext3 is an extended high Performance log file system for the Ext2 file system

Source: Internet
Author: User

One of the most important decisions that embedded developers make is the type of file system to deploy. Some file system performance is relatively high, some file system space utilization ratio is high, there are some file system equipment failure or accidental power loss after the recovery of data more convenient.

Linux File System Concepts

Partition

Partitioning is a logical division of physical devices, and file systems exist on this device. A physical device can contain only one partition, occupy all available space, or it can be partitioned into multiple partitions to suit the requirements of a particular task. A partition can be viewed as a logical disk, which can store a complete file system. A partition is a logical part of the physical medium, and the organization of the data in this partition follows the corresponding provisions of this partition type. At the highest level, the data is stored in the partitions of the physical device.

Linux uses the Fdisk tool to manipulate partitions on block devices. The latest Fdisk tool can identify more than 90 different types of partitions.

The following list shows the output information when using the Fdisk tool for a CompactFlash device connected to a USB port. In this particular target system, the device node assigned by the physical CompactFlash device is/dev/sdb.

#fdisk/dev/sdb

Command (M for help):p

disk/dev/sdb:49 mb,49349120 bytes

4 heads, Sectors/track, 753 cylinders

Units = cylinders of 128*512 = 65536 bytes

Device Boot Start End Blocks Id System

/DEV/SDB1 * 1 11504 Linux

/DEV/SDB2 181 11520 Linux

/DEV/SDB3 361 540 11520-up Linux

/DEV/SDB4 541 753 13632-up Linux

For the sake of discussion here, we have created 4 partitions on this device using the Fdisk tool. One of them is marked as a bootable partition. This reflects a flag switch that has a boot identifier in the data structure representing the device partition table. After partitioning the CompactFlash in this way, each partition is represented by a device node, and a file system can be selected to format it. If a partition has been formatted with a file system, Linux can mount the corresponding file system from that partition.

Ext2

The section above has been partitioned, and then the partition created by Fdisk needs to be formatted. MKFS.EXT2 creates a file system of type ext2 on the specified partition. MKFS.EXT2 is specifically related to the Ext2 file system, and other types of file systems have their own tools. The following shows the output information during the formatting process.

#mkfs. Ext2/dev/sdb1-l Cflash_boot_vol

MKE2FS 1.40.8 (13-mar-2008)

Filesystem Label=cflash_boot_vol

OS Type:linux

Block size=1024 (log=0)

Fragment size=1024 (log=0)

2880 inodes, 11504 blocks

575 Blocks (5.00%) reserved for the Super user

First Data block=1

Maximum filesystem blocks=11796480

2 Block groups

8192 blocks per group,8192 fragements per group

1440 inodes per group

Superblock backups stored on blocks:

8193

Writing Inode Tables:done

Writing superblocks and filesystem accounting Information:done

This filesystem'll be automatically checked every mounts or 180

Days, whichever comes first, use tune2fs-c or-i to override

The code listing above contains many details about the ext2 file system. It's a good idea to start from here to understand how ext2 works. This partition is formatted as a ext2 type (because we use the ext2 mkfs tool), and the volume label (volume_label) is Cflash_boot_vol. It was created on a Linux partition (OS Type:) with a block size of 1024B. It allocates space for 2,880 Inode, occupying a total of 11,504 blocks. Inode This data structure represents a file.

Looking at the output of MKFS.EXT2 in the code listing above, we can determine some of the organizational characteristics of the storage device. We already know the block size is 1024B. If your application has special needs, you can have mkfs.ext2 use a different block size to format a ext2 file system. The current MKFS.EXT2 implementation supports blocks of 1024, 2048, and 4096B.

Block sizes are always compromised in order to achieve optimal performance. On the one hand, if there are many small files on the disk, the larger block size will waste a lot of space, because each file must be stored by an entire number of blocks. If the size of the file exceeds Block_size*n, the part that is exceeded must be in the other complete block, even if it exceeds 1 B. On the other hand, if a smaller block size is used, this increases the overhead of file system management metadata, which describes the mapping between blocks and files. You need to do some benchmarking of the special hardware implementation and the data format, which is the only way to determine if the best block size is selected.

Mount File System

After the file system has been created, we can mount it on a running Linux system. The kernel must support the type of our particular file system at compile time, either by compiling the support function into the kernel or by compiling it into a dynamically loadable module. Mount by using the Mount command

Mount/dev/sdb1/mnt/flash

/mnt/flash is a directory that is already on the target Linux device and is referred to as a mount point. The device we are going to mount is a flash device, and the device node assigned to it is/DEV/SDB1. A mount point can be any directory path in the file system, which becomes the top-level directory for the new mounted device. In the above example, in order to access the files in the Flash memory device, you must precede the path with/mnt/flash.

The directory contents of a flash device are bin, boot, dev, etc, home, Lib, Lost+found, proc, Root, sbin, tmp, USR, var. This device is configured for an embedded system. From this you can see what the top-level content of the root filesystem on an embedded device looks like.

Check the integrity of the file system

The E2FSCK command is used to check the integrity of a file system. File system corruption can be caused by several reasons. The most common reason is that the system unexpectedly loses power. The Linux distribution shuts down all open documents and unloads the file system when it shuts down (assuming the system shuts down normally and orderly). However, it is common for accidental power outages in embedded systems, so we need some precautions to deal with these situations. E2fsck is the first line of defense.

The following shows the output information when running e2fsck on CompactFlash. He's been properly uninstalled, so no mistake happened.

#e2fsck/DEV/SDB1

E2fsck 1.40.8 (13-mar-2008)

cflash_boot_vol:clean,11/2880 files, 471/11504 blocks

The E2fsck tool does a consistency check on several aspects of the file system. If no problem is found, e2fsck outputs an output similar to the one above. Note that the e2fsck should run on a file system that is not mounted. While it is possible to run it on a mounted file system, doing so can cause serious damage to the internal file system structure of the disk or flash memory device.

We remove the CompactFlash device from the socket in the mounted State, and the following shows the output information at the time the file system is detected.

Check for a damaged file system

#e2fsck-y/dev/sdb1

E2fsck 1.40.8 (13-mar-2008)

/DEV/SDB1 is not cleanly unmounted, check forced.

Pass 1:checking inodes, blocks, and sizes

Inode, I_blocks is, should was 8.fix?yes

/DEV/SDB1: ********file SYSTEM was modified**********

/dev/sdb1:25/2880 files (4% non-contiguous), 488/11504 blocks

Without proper uninstallation, e2fsck 5-wheel traversal of the file system, examining the individual members of the internal file system data structure. Inode 13 has been modified because it contains the-y option.

The embedded designer should be aware of the situation: if the system does not shut down properly, an accidental power outage will take longer to boot, since she will take the time to scan the boot device and fix the errors found. In fact, if these errors are not repairable, the startup of the system terminates and requires human intervention. In addition, if your file system is larger, file system detection (FSCK) can take a few minutes or even a few hours.

Another way to protect against file system corruption is to ensure that write-making can be submitted to disk immediately, which is reflected on the hardware device as soon as it is finished. The Sync tool can be used to force the submission of all I/O requests queued to the corresponding device. There is a strategy that can be used to reduce the likelihood of data corruption when an accidental power outage occurs, either by executing the sync command after each file is written, or by performing a scheduled sync command according to the requirements of the application. Of course, the cost is that performance will be affected. In all modern operating systems, delaying disk writes is a way to optimize system performance. Using the sync command actually offsets this optimization.

Ext3 file System

Ext3 is a powerful, high-performance and robust log file system. Ext3 is an extension to the Ext2 file system that adds logging functionality.

So what is a log? Logging is a technique in which each change to a file system is recorded in a special file so that the file system is likely to recover from a known log point. Ext3 has an advantage, as mentioned earlier, when the system shuts down unexpectedly, such as when a power failure occurs, the system will force a consistency check on the file system, which is a time-consuming operation. If you use the Ext3 file system, you do not need a consistency check, because a simple replay of the log can guarantee file system consistency,

Here's a brief explanation of how the log file system works. A log file system contains a special file that is usually hidden from the user, and is used to store the file system metadata (metadata is data about the file differs from the data stored in the file system, examples of metadata include the date, time, size, number of blocks used, etc.) and the file data itself, This special file is called a log. Once the file system has been modified (such as a write operation), these changes are first written to the log. The driver for the file system guarantees that the write is first committed to the log, after which the actual data changes are committed to the storage medium (such as disk or flash memory). When these changes are recorded in the log, the driver changes the actual files and meta data on the media. If a power failure occurs while writing data to the media, and then the system restarts, in order to restore file system consistency, all we have to do is replay the changes recorded in the log.

You can convert a ext2 file system to a ext3 file system and back again without reformatting and rewriting all the data on the disk,

#mount/dev/sdb1/mnt/flash (Mount ext2 file system)

#tune2fs-j/dev/sdb1 (create log)

TUNE2FS 1.37 (21-mar-2005,2881064151)

Creating Journal Inode:done

This filesystem'll be automatically checked every mounts or 180

Days, whichever comes first. Use Tune2fs-c or-i to override

#

First mount the file system to/mnt/flash (normally, we execute this command on a ext2 partition that is mounted). If the file system is already mounted, TUNE2FS will create a log file named. Journal, which is a hidden file. Ls-al can display all files that contain hidden files.

At this point we have created the log file on the Flash module, and in fact he has been formatted as a ext3 file system. The log file is automatically invisible the next time the system restarts or when the E2fsck tool is running on this partition. His metadata is stored in an inode that is reserved for this purpose. As long as we can see the. Journal in the list of directories, it is dangerous to modify or delete this file.

You can create a log file on another device, which sometimes benefits. For example, if your system has more than one physical device, you can place your ext3 log file system on the first drive and place its log files on a second drive. This approach is possible regardless of whether the physical device is flash-based or spin-on media (disk). If the existing Ext2 file system is on a partition and the log file is on another partition, in order to create a log file system from this file system, the TUNE2FS command needs to be executed in the following way:

#tune2fs-j device=/dev/sda1-j/DEV/SDB1

Ext3 is an extended high Performance log file system for the Ext2 file system

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.