Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to manage the health status of EXT2, EXT3 and EXT4 file systems in Linux

2025-03-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

Editor to share with you how to manage the health status of EXT2, EXT3 and EXT4 file systems in Linux. I believe most people don't know much about it, so share this article for your reference. I hope you can learn a lot after reading this article. Let's learn about it together.

How to view EXT2/EXT3/EXT4 file system information

Dumpe2fs is a command-line tool for dumping ext2/ext3/ext4 file system information, which means it can display super block and block group information for file systems on the device.

Before running dumpe2fs, run the df-hT command to make sure you know the device name of the file system.

$sudo dumpe2fs / dev/sda10

Sample output:

Dumpe2fs 1.42.13 (17-May-2015) Filesystem volume name: Last mounted on: / Filesystem UUID: bb29dda3-bdaa-4b39-86cf-4a6dc9634a1b Filesystem magic number: 0xEF53 Filesystem revision #: 1 (dynamic) Filesystem features: has_journal ext_attr resize_inode dir_index filetype needs_recovery extent flex_bg sparse_super large_file huge_file uninit_bg dir_nlink extra_isize Filesystem flags: signed_directory_hash Default mount Options: user_xattr acl Filesystem state: clean Errors behavior: Continue Filesystem OS type: Linux Inode count: 21544960 Block count: 86154752 Reserved block count: 4307737 Free blocks: 22387732 Free inodes: 21026406 First block: 0 Block size: 4096 Fragment size: 4096 Reserved GDT blocks: 1003 Blocks per group: 32768 Fragments per group: 32768 Inodes per group: 8192 Inode blocks per group: 512 Flex block group size: 16 Filesystem created: Sun Jul 31 16:19:36 2016 Last mount time: Mon Nov 6 10:25:28 2017 Last write time: Mon Nov 6 10:25:19 2017 Mount count: 432 Maximum mount count:-1 Last checked: Sun Jul 31 16:19:36 2016 Check interval: 0 () Lifetime writes: 2834 GB Reserved blocks uid: 0 (user root) Reserved blocks gid: 0 (group root) First inode: 11 Inode size: 256 Required extra isize: 28 Desired extra isize: 28 Journal inode: 8 First orphan inode: 6947324 Default directory hash: half_md4 Directory Hash Seed: 9da5dafb-bded-494d-ba7f-5c0ff3d9b805 Journal backup: inode blocks Journal features: journal_incompat_revoke Journal size: 128M Journal length: 32768 Journal sequence: 0x00580f0c Journal start: 12055

You can use the-b option to display any reserved blocks in the file system, such as bad blocks (no output means no bad blocks):

$sudo dumpe2fs-b

Check for errors in the EXT2/EXT3/EXT4 file system

E2fsck is used to check the ext2/ext3/ext4 file system for errors. Fsck can check and optionally repair the Linux file system; it is actually a front-end program for a series of file system inspectors (fsck.fstype, such as fsck.ext3, fsck.sfx, and so on) provided by the underlying Linux.

Remember, when the system boots, Linux automatically runs e2fsck/fsck for the partition marked "check" in the / etc/fstab configuration file. It is also generally run when a file system is not cleanly unmounted.

Note: do not run e2fsck or fsck on a mounted file system, first unmount the partition before you run these tools, as shown below.

$sudo unmount / dev/sda10 $sudo fsck / dev/sda10

In addition, you can use the-V switch to enable verbose output and-t to specify the file system type, like this:

$sudo fsck-Vt ext4 / dev/sda10

Tuning the EXT2/EXT3/EXT4 file system

As we mentioned earlier, one of the factors leading to file system corruption is incorrect tuning. You can use the tune2fs utility to change the tunable parameters of the ext2/ext3/ext4 file system, as described below.

To view the super block of the file system, including the current value of the parameter, use the-l option, as shown below.

$sudo tune2fs-l / dev/sda10

Sample output:

Tune2fs 1.42.13 (17-May-2015) Filesystem volume name: Last mounted on: / Filesystem UUID: bb29dda3-bdaa-4b39-86cf-4a6dc9634a1b Filesystem magic number: 0xEF53 Filesystem revision #: 1 (dynamic) Filesystem features: has_journal ext_attr resize_inode dir_index filetype needs_recovery extent flex_bg sparse_super large_file huge_file uninit_bg dir_nlink extra_isize Filesystem flags: signed_directory_hash Default mount Options: user_xattr acl Filesystem state: clean Errors behavior: Continue Filesystem OS type: Linux Inode count: 21544960 Block count: 86154752 Reserved block count: 4307737 Free blocks: 22387732 Free inodes: 21026406 First block: 0 Block size: 4096 Fragment size: 4096 Reserved GDT blocks: 1003 Blocks per group: 32768 Fragments per group: 32768 Inodes per group: 8192 Inode blocks per group: 512 Flex block group size: 16 Filesystem created: Sun Jul 31 16:19:36 2016 Last mount time: Mon Nov 6 10:25:28 2017 Last write time: Mon Nov 6 10:25:19 2017 Mount count: 432 Maximum mount count:-1 Last checked: Sun Jul 31 16:19:36 2016 Check interval: 0 () Lifetime writes: 2834 GB Reserved blocks uid: 0 (user root) Reserved blocks gid: 0 (group root) First inode: 11 Inode size: 256 Required extra isize: 28 Desired extra isize: 28 Journal inode: 8 First orphan inode: 6947324 Default directory hash: half_md4 Directory Hash Seed: 9da5dafb-bded-494d-ba7f-5c0ff3d9b805 Journal backup: inode blocks

Next, using the-c flag, you can set how many times the file system will be e2fsck checked after mounting. The following command instructs the system to run e2fsck on / dev/sda10 after every four mounts.

$sudo tune2fs-c 4 / dev/sda10 tune2fs 1.42.13 (17-May-2015) Setting maximal mount count to 4

You can also use the-I option to define the interval between two file system checks. The following command sets a 2-day interval between two file system checks.

$sudo tune2fs-I 2d / dev/sda10 tune2fs 1.42.13 (17-May-2015) Setting interval between checks to 172800 seconds

Now, if you run the following command, you can see that the file system check interval has been set for / dev/sda10.

$sudo tune2fs-l / dev/sda10

Sample output:

Filesystem created: Sun Jul 31 16:19:36 2016 Last mount time: Mon Nov 6 10:25:28 2017 Last write time: Mon Nov 6 13:49:50 2017 Mount count: 432 Maximum mount count: 4 Last checked: Sun Jul 31 16:19:36 2016 Check interval: 172800 (2 days) Next check after: Tue Aug 2 16:19:36 2016 Lifetime writes : 2834 GB Reserved blocks uid: 0 (user root) Reserved blocks gid: 0 (group root) First inode: 11 Inode size: 256 Required extra isize: 28 Desired extra isize: 28 Journal inode: 8 First orphan inode: 6947324 Default directory hash: half_md4 Directory Hash Seed: 9da5dafb-bded-494d-ba7f-5c0ff3d9b805 Journal backup: inode blocks

To change the default log parameters, you can use the-J option. This option also has suboptions: size=journal-size (set the size of the log), device=external-journal (specify the device on which the log is stored), and location=journal-location (define the location of the log).

Note that only one log size or device option can be set for the file system at a time:

$sudo tune2fs-J size=4MB / dev/sda10

Just as important, you can use the-L option to set the volume label of the file system, as shown below.

$sudo tune2fs-L "ROOT" / dev/sda10

Debug EXT2/EXT3/EXT4 file system

Debugfs is a simple, interactive command-line debugger based on the ext2/ext3/ext4 file system. It allows you to interactively modify file system parameters. Input? View subcommands or requests.

$sudo debugfs / dev/sda10

By default, the file system opens in read-only mode and uses the-w flag to open it in read-write mode. Use the-c option to open it in catastrophic mode.

Sample output:

Debugfs 1.42.13 (17-May-2015) debugfs:? Available debugfs requests: show_debugfs_params, params Show debugfs parameters open_filesys, open Open a filesystem close_filesys, close Close the filesystem freefrag, e2freefrag Report free space fragmentation feature, features Set/print superblock features dirty_filesys, dirty Mark the filesystem as dirty init_filesys Initialize a filesystem (DESTROYS DATA) show_super_stats, stats Show superblock statistics ncheck Do inode- > name translation icheck Do block- > inode translation change_root_directory Chroot....

To show fragments of unused space, use a freefrag request, like this:

Debugfs: freefrag

Sample output:

Device: / dev/sda10 Blocksize: 4096 bytes Total blocks: 86154752 Free blocks: 22387732 (26.0%) Min. Free extent: 4 KB Max. Free extent: 2064256 KB Avg. Free extent: 2664 KB Num. Free extent: 33625 HISTOGRAM OF FREE EXTENT SIZES: Extent Size Range: Free extents Free Blocks Percent 4K... 8K -: 4883 4883 0.02% 8K. 16K -: 4029 9357 0.04% 16K. 32K -: 3172 15824 0.07% 32K. 64K -: 2523 27916 0.12% 64K. 128K -: 2041 45142 0.20% 128K. 256K -: 2088 95442 0.43% 256K. 512K -: 2462 218526 0.98% 512K. 1024K -: 3175 571055 2.55% 1m. 2m -: 4551 1609188 7.19% 2m. 4m -: 2870 1942177 8.68% 4m. 8m -: 1065 1448374 6.47% 8m. 16m -: 364 891633 3.98% 16m. 32m -: 194 984448 4.40% 32m. 64m -: 86 873181 3.90% 64m. 128M -: 77 1733629 7.74% 128m. 256m -: 11 490445 2.19% 256m. 512M -: 10 889448 3.97% 512M. 1024M -: 2 343904 1.54 1G. 2G -: 22 10217801 45.64% debugfs:

By simply browsing the brief description it provides, you can try more requests, such as creating or deleting files or directories, changing the current working directory, and so on. To exit debugfs, use Q.

That's all for now! We have collected related articles under different categories, in which you can find useful content for you.

File system usage information:

12 Useful "df" Commands to Check Disk Space in Linux

Pydf an Alternative "df" Command to Check Disk Usage in Different Colours

10 Useful du (Disk Usage) Commands to Find Disk Usage of Files and Directories

Check the health of the disk or partition:

3 Useful GUI and Terminal Based Linux Disk Scanning Tools

How to Check Bad Sectors or Bad Blocks on Hard Disk in Linux

How to Repair and Defragment Linux System Partitions and Directories

These are all the contents of the article "how to manage the health of EXT2, EXT3, and EXT4 file systems in Linux". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

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.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report