[Linux] Detailed explanation of fdisk command parameters (super detailed graphics and texts, the content comes from official documents)

Table of contents

0. Environment

1. Background

2. Content--The official document introduces fdisk

1) name

2) Description

 3) Specific parameters/options

4) For example, I want to check the version of fdisk


0. Environment

windows + linux virtual machine

1. Background

I published an article before that Linux uses fdisk for disk partitioning (graphic process) , which uses the fdisk command to partition the disk, and uses a lot of fdisk's built-in commands.

Today (2023-6-29) when looking back at the article, I feel that some friends may not know much about the detailed commands of fdisk, so refer to the official fdisk documentation to organize this article, hoping to help.

2. Content--The official document introduces fdisk

Note: All English translations of this article come from web translation software, if there are any mistakes, please correct me, thank you.

1) name

fdisk - manipulate disk partition table

2) Description

Use the following format

fdisk [options] device fdisk [options] device
fdisk -l [device...] fdisk -l [device...]

        fdisk is a dialog-driven program for creating and manipulating partition tables. It understands GPT, MBR, Sun, SGI and BSD partition tables.

        Block devices can be divided into one or more logical disks called partitions. This partition is recorded in the partition table, usually in sector 0 of the disk. (In the BSD world, people talk about "disk slices" and "disk labels".)

        By default, all partitions are driven by device I/O limits (topology). fdisk is able to optimize disk layouts for 4K sector sizes and use alignment offsets on modern devices with MBR and GPT. It is always a good idea to follow fdisk's defaults, since defaults (e.g., first and last partition sectors) and partition sizes specified by +/-<size>{M,g,...} notation are always Align according to device properties.

        CHS (Cylinder Head Sector) addressing is deprecated and is not used by default. Please don't follow old articles and suggestions that suggest "fdisk -S<n>-H<n>" for SSD or 4K sector devices.


        Note that partx(8) provides a rich interface for scripting to print disk layouts, fdisk is primarily designed for humans. Backward compatibility of fdisk output is not guaranteed. Input (commands) should always be backward compatible.

 3) Specific parameters/options

parameter/option (abbreviation) parameter/option (full meaning) Instructions/Explanation
-b --sector size sector size

Specifies the sector size of the disk. Valid values ​​are 512, 1024, 2048, and 4096. (Recent kernels know the sector size. Only use this option on older kernels, or override the kernel's idea.) Since util-linux-2.17, fdisk distinguishes between logical and physical sector sizes. This option changes both sector sizes to sector sizes.

-B --protect start

When creating a new disk label, do not erase the beginning of the first disk sector. GPT and MBR support this feature.

-c --compatibility[=mode]

Specifies compatibility mode "dos" or "nondos". The default is non-DOS mode. For backwards compatibility, the option can be used without a mode argument, then the default value is used. Note that optional mode parameters cannot be separated from the -c option by spaces, the correct form is e.g. "-c=dos".

-h --help

Display help text and exit.

-L

--color[=when]

Colorizes the output. The optional parameter when can be auto, never or always. If the when parameter is omitted, it defaults to auto. Colors can be disabled; see --help output for current built-in defaults. See also the color section.
-l -- list

List the partition table of the specified device and exit. If no device is given, the device mentioned in /proc/partitions is used (if that file exists).

-o -- output list

Specifies the output columns to print. Use --help to get a list of all supported columns. The default column list can be extended if the list is of the form +list (e.g. -o+UUID).

-s

 --Obtain

Print the size of each 512-byte sector for the given block device. This option has been deprecated in favor of blockdev(1).

-t

 -- type type

Enables support only for disklabels of the specified type, and disables support for all other types.
-u --units[=units]

When listing the partition table, the size is shown in "sectors" or "cylinders". The default is to display the size in sectors. For backwards compatibility, it is possible to use the option without a unit argument, and then use the default value. Note that the optional units parameter cannot be separated with a space with the -u option, the correct form is e.g. "-u=cylinders".

-C -- Number of cylinders

Specifies the number of cylinders of the disk. I don't know why anyone would want to do this.

-H

--Head count

Specifies the number of heads for the disk. (Not a physical number, of course, but the number used for the partition table.) Reasonable values ​​are 255 and 16.
-S -- sector number

Specifies the number of sectors per track on the disk. (Not the physical number of course, but the number used for the partition table.) A reasonable value is 63

-w -- when wiping

Wipes filesystem, RAID and partition table signatures from the device to avoid possible conflicts. The parameter when can be auto, never or always. If this option is not given, it defaults to 'auto', in which case the signature will only be erased in interactive mode. In all cases, detected signatures are reported with a warning message before a new partition table is created. See also the wipefs(8) command.

-W -- When erasing a partition

Wipes filesystem, RAID and partition table signatures from newly created partitions to avoid possible conflicts. The parameter when can be auto, never or always. If this option is not given, it defaults to 'auto', in which case the signature will only be erased in interactive mode and after user confirmation. In all cases, detected signatures are reported with a warning message before the new partition is created. See also the wipefs(8) command.

-V --Version

Display version information and exit.

 

 

4) For example, I want to check the version of fdisk

 Command: fdisk -V

result:

 

--END--

Guess you like

Origin blog.csdn.net/qq_41539778/article/details/131449165