Welcome: Hunan Intelligent Applications Tecgnology CO.,ltd.-HNIAT.com
Language: Chinese ∷  English

Basic knowledge

Detailed explanation of Linux disk format command

Command: mke2fs mke2fs [options] filesystem diskletter=

Notes:

1. Although the disk has been partitioned, it cannot be used yet. It needs to be formatted on each partition. The so-called format is actually to install the file system. The file system under Windows includes Fat32, NTFS, and the file system used by CentOS. For ext, the previous centOS5 version used ext3 as the default file system, while CentOS6 used ext4 as the default file system;

2. When you use man to query the help documents of these four commands, you will find that we see the same help document, which means that the four commands are the same;

3. Specify the file system format as ext4. This command is equivalent to mkfs ext4 /dev/sdb5. When we encounter Yuyao format disk partitions in the future, we can directly specify the format as ext4, or we can decide the format according to the version of the operating system. what format?

Options:

-b: Set the size of the space occupied by each data block when partitioning, currently supports 1024, 2048 and 4096 bytes per block;

-i: Set the size of the inode;

-N: Set the number of inodes, sometimes using the default number of inodes is not enough, so you need to customize the number of inodes;

-c: Check whether the disk has problems before formatting, it will be very slow after adding this option;

-L: Preset the label of the partition;

-j: Create a partition in ext3 format, if you use mkfs.ext3, you don't need to add this option;

-t: used to specify what type of file system, it can be ext2, ext3 or ext4;

-m: When formatting, specify the proportion of the disk reserved for the administrator, which is a percentage, only for the mke2fs command;

For example: mke2fs -t ext4 -b 4096 /dev/sdb5

Note: One of the indicators is "block size = 4096". This involves the concept of a "block". When the disk is formatted, the size of each block will be pre-specified, and then all the space will be divided into one by one. If you store data in small blocks, it is also faster to write faster when storing data, so if your disk stores all very small and very small files, such as 1k or 2k, it is recommended to specify the block when formatting the disk. The value is smaller. The default block size of the ext file system is 4096, which is 4k. When formatting, you can specify a block size of 1024, 2048 or 4096 (they are multiplied), although you can specify when formatting. The block size exceeds 4096, but once it exceeds 4096, it cannot be mounted normally;

Specify the block size: mke2fs -t ext4 -b 8192 /dev/sdb5


Note: You can use -L to specify the label, the label will be used when the disk is mounted, and it can also be written to the configuration file. Regarding this part of formatting, I suggest that you do not need to specify the block size unless you need it. That is, you only need to remember these two options: -t and -L.

More basic sharing about Linux disk formatting:

Basic skills, formatting commands, take formatting /dev/sda1 partition as an example:

$ sudo umount /dev/sda1

# The partition must be unmounted first

# format as FAT partition

$ sudo mkfs.vfat -F 32 /dev/sda1 # The -F parameter must be uppercase. The parameters are 12, 16 and 32, corresponding to FAT12, FAT16, and FAT32 respectively.

# To format as an NTFS partition, first install ntfsprogs, take Ubuntu / Debian as an example:

$ sudo apt-get install ntfsprogs

#Then execute the format command, take formatting the /dev/sda1 partition as an example:

$ sudo umount /dev/sda1 # This partition must be unmounted first
$ sudo mkfs.ntfs /dev/sda1 # Formatting to ntfs is a bit slow.

# Format to ext4/3/2, take formatting /dev/sda1 partition as an example:

$ sudo umount /dev/sda1 # This partition must be unmounted first
$ sudo mkfs.ext4 /dev/sda1 # format as ext4 partition
$ sudo mkfs.ext3 /dev/sda1 # format as ext3 partition
$ sudo mkfs.ext2 /dev/sda1 # format as ext2 partition

Since the partitions of the ext series have a reserved space for the super user, they must occupy a certain percentage. The default is 5%. In this way, I don’t feel that formatting a partition with a small capacity, 5% is not much, but if it is a few hundred G , 1T partition will have problems, in this case, 5% is not a small amount!

"Solution"

1. For the partition to be formatted, take ext3 as an example:

$ sudo umount /dev/sda1 # The partition must be unmounted first, here is the /dev/sda1 partition to be formatted.

$ sudo mkfs.ext3 -m 0.05 /dev/sda1 # Note that the parameter after -m is already set to percentile, here it is set to 0.05, which is 0.05%, which is 5/10,000!

Well, take a 1T partition as an example, 1T=1024GB=1048576MB (all are multiplied by 1024), 1048576MB*0.0005=524.288MB.

That is to say, after setting the -m parameter, the reserved area is about 524MB. Of course you can set it according to your liking.

2. For a partition that has been formatted and you do not want to wipe out the data in the partition, you can use the method of tune2fs -m:

# This command does not need to unmount the partition first.

$ sudo tune2fs -m 0.05 /dev/sda2 # This example is to convert the super user reserved area of the /dev/sda2 partition, which is also set to 0.05. In a reminder, it is 0.05%, which is 5/10,000.

The above is the detailed content of the Linux disk format command. For more details, please pay attention to other related articles on the html Chinese website!

CONTACT US

Contact: Manager Xu

Phone: 13907330718

Tel: 0731-22222718

Email: hniatcom@163.com

Add: Room 603, 6th Floor, Shifting Room, No. 2, Orbit Zhigu, No. 79 Liancheng Road, Shifeng District, Zhuzhou City, Hunan Province

Scan the qr codeClose
the qr code