The Wayback Machine - https://web.archive.org/web/20240704012232/https://www.geeksforgeeks.org/linux-tune2fs-command-with-examples/
Open In App

Linux tune2fs command With Examples

Last Updated : 04 Nov, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

Linux, as a versatile and powerful operating system, offers a myriad of command-line tools to manage and manipulate various aspects of the file system. Among these tools, the tune2fs command stands out as a crucial utility for fine-tuning the ext2, ext3, and ext4 file systems. This command empowers Linux administrators to customize file system parameters, making it an indispensable part of the Linux toolkit.

The syntax for the `tune2fs` command in linux:

tune2fs [options] device

Here,

[options]: Refers to the various options that you can use to modify specific file system attributes.

device: Specifies the path to the block device representing the file system you want to tune.

Example : tune2fs -c /dev/sda1

Commonly Used Options in the`tune2fs` command in Linux

Options

Description

`-l`

This displays the file structure and current values of the parameters.

`-L`

Used to set the Volume Label of the file system.

`-c`

This option is used to set the maximum count size of the file system.

`-O`

You can disable and enable some specific features using this option.

`-r`

Used to set the reserved block.

1. List the file system files using the `-l` option using the tune2fs command

The ‘-l’ option is used with the ‘tune2fs’ command in Linux to display file system information. When using this option, the command can provide a lot of detailed information about the file system, which can be overwhelming. To make it more manageable, you can use the ‘head’ command to display only the first few lines of the output. Here’s an example :

Example:

sudo tune2fs -l /dev/sda | head

First-Image

2. How to set the label of the drive?

The ‘-L’ option in the ‘tune2fs‘ command is used to change the label (name) of a filesystem on a drive in Linux. Here’s an example of how to use it to set the label of a drive:

Example:

sudo tune2fs -L "New Label" /dev/sda1

Second-Image

To verify that the label of the filesystem has been successfully changed using the ‘-L’ option with the ‘tune2fs’ command, you can use the ‘-l‘ option to display the filesystem information, including the label. Here’s an example of how to do that:

Image-3

3. How to set the count in a file system?

The ‘-c’ option in the ‘tune2fs’ command is used to set the maximum mount count for the filesystem before it should be checked for errors. Here’s an example of how to use it:

Example:

sudo tune2fs -c 40 /dev/sda1

Image1

To check the current maximum mount count setting using the ‘tune2fs’ command, you can use the ‘-l’ option to display the filesystem information and then ‘grep’ for the “Maximum mount count” line. Here’s an example:

sudo tune2fs  -l /dev/sda1 | grep mount

Image2

4. How to enable or disable some specific features of file system?

The ‘-O’ option in the ‘tune2fs’ command is indeed a powerful feature that allows you to enable or disable specific filesystem features on an ext2, ext3, or ext4 filesystem. It’s often used for tuning filesystem options. Here’s an example of how to use the ‘-O’ option:

Example:

sudo tune2fs -O dir_index /dev/sda1

Image3

5. How to set reserved blocks in file system?

The ‘-r‘ option in the ‘tune2fs’ command is used to set the reserved block percentage for a filesystem. The reserved blocks are space on the filesystem that is reserved for use by the system administrator. They can be useful to ensure that there is always some space available for system maintenance, even if the filesystem becomes full.

Here’s an example of how to use the ‘-r’ option to set the reserved block percentage:

Example:

sudo tune2fs -r 5 /dev/sda1   

Image4

To verify whether the reserved block percentage has been successfully set using the ‘-r’ option in the tune2fs command, you can use the ‘-l’ option to display the filesystem information and check the reserved block count. Here’s an example:

Image5

Frequently Asked Questions:

Q1. What is the the tune2fs command?

Answer:

The tune2fs command in Linux is a versatile tool used for changing and manipulating various parameters and settings of ext2, ext3, and ext4 file systems. It allows system administrators to fine-tune and modify various aspects of the filesystem to suit their needs.

Q2. What is the use of the ‘-L’ option in tune2fs command?

Answer:

You can change the label of a filesystem using the ‘-L’ option followed by the desired label, like this: ‘sudo tune2fs ‘-L’ “New_Label” /dev/sda1′. You can then verify the change using the ‘-l’ option.

Q3. What is the purpose of the the ‘-c’ option in tune2fs command?

Answer:

The ‘-c’ option is used to set the maximum mount count before the filesystem should be checked for errors during system startup. For example, ‘sudo tune2fs -c 40 /dev/sda1’ sets the maximum mount count to 40.

Q4. How can you enable or disable specific features of a filesystem using the ‘tune2fs’ command?

Answer:

The ‘-O’ option allows you to enable or disable specific filesystem features. For example, ‘sudo tune2fs -O dir_index /dev/sda1’ enables the “dir_index” feature, while ‘sudo tune2fs -O ^has_journal /dev/sda1‘ disables the “has_journal” feature.

Q5. What is the purpose of the the ‘-r’ option in tune2fs command?

Answer:

The ‘-r’ option in tune2fs command is used to set the reserved block for the file system.

For example : ‘tune2fs -r 5 /dev/sda’

Conclusion

The tune2fs command in Linux empowers administrators with the ability to fine-tune various parameters and attributes of ext2, ext3, and ext4 file systems. By using this versatile tool, you can enhance performance, customize file system properties, and meet specific requirements to ensure the smooth operation of your Linux system. Understanding and utilizing the tune2fs command is essential for Linux administrators, as it enables them to maintain and optimize file systems effectively.



Similar Reads

Ccat – Colorize Cat Command Output command in Linux with Examples
ccat is a command-line tool for Linux and OSX, which is similar to the cat command in Linux. But the difference between cat and ccat is that the ccat shows the content of the file with the syntax highlighted. Currently, ccat supports the following programming languages. JavaScriptJavaRubyPythonGoCJSONInstallation of Ccat First, we are going to see
2 min read
How to Display Command History in Linux | history Command
The command-line interface in Linux provides powerful tools for users, and mastering command history is essential for efficient navigation and retrieval of previously executed commands. The history command is a valuable utility that allows users to view and search through their command history. In this comprehensive guide, we will explore the vario
4 min read
select command in Linux with examples
select command in Linux is used to create a numbered menu from which a user can select an option. If the user enters a valid option then it executes the set of command written in select block and then ask again to enter a number, if a wrong option is entered it does nothing. If user enters nothing and simply press 'enter' the option menu gets print
1 min read
ZIP command in Linux with examples
ZIP is a compression and file packaging utility for Unix. Each file is stored in a single .zip {.zip-filename} file with the extension .zip. Zip is used to compress files to reduce file size and is also used as a file package utility. Zip is available in many operating systems like Unix, Linux, windows, etc.If you have limited bandwidth between two
7 min read
atrm command in Linux with examples
atrm command is used to remove the specified jobs. To remove a job, its job number is passed in the command. A user can only delete jobs that belong to him. Only superuser can delete any job even if that belongs to another user. Syntax: atrm [-V] job [job...] Options: -V : Used to print the version number atrm -V job : Job number of the job which i
1 min read
comm command in Linux with examples
comm compare two sorted files line by line and write to standard output; the lines that are common and the lines that are unique. Suppose you have two lists of people and you are asked to find out the names available in one and not in the other, or even those common to both. comm is the command that will help you to achieve this. It requires two so
5 min read
cmp Command in Linux with examples
cmp command in Linux/UNIX is used to compare the two files byte by byte and helps you to find out whether the two files are identical or not. When cmp is used for comparison between two files, it reports the location of the first mismatch to the screen if difference is found and if no difference is found i.e the files compared are identical.cmp dis
5 min read
expand Command in LINUX with examples
Whenever you work with files in LINUX there can be a situation when you are stuck with a file containing many tabs and whatever you need to do with a file requires that file with no tabs but with spaces. In this situation, the task looks quite simple if you are dealing with a small file but what if the file you are dealing with is very big or you n
3 min read
df Command in Linux with examples
There might come a situation while using Linux when you want to know the amount of space consumed by a particular file system on your LINUX system or how much space is available on a particular file system. LINUX being command friendly provides a command line utility for this i.e df command that displays the amount of disk space available on the fi
8 min read
tee command in Linux with examples
tee command reads the standard input and writes it to both the standard output and one or more files. The command is named after the T-splitter used in plumbing. It basically breaks the output of a program so that it can be both displayed and saved in a file. It does both the tasks simultaneously, copies the result into the specified files or varia
2 min read