fdisk partition command

fdisk is the most commonly used Linux system partitioning tool, this command can also view all of the available partitions system, but this command only supports the MBR partition table (this sentence should be used only for certain systems, CentOS7-1810 applicable, Debian9 .5 and openSUSE15 should have support GPT partition table, the following operations are in Debian9.5 fdisk under operation), so this command can not be greater than 2T of hard disk partition larger than 2T hard we need to use GPT partition table partitioning, GPT partition we will use gdisk or parted partitioning tool to partition.

How Linux kernel is hard to understand?
As humans, we can easily understand some things; but the computer is not the case, they need to understand the proper nomenclature.

In Linux, peripheral devices located / dev mount point, the kernel is understood by the hard disk in the following manner:

/ dev / hdX [az]: IDE hard disk is designated as hdX
/ dev / sdX [AZ]: the SCSI hard disk is designated as sdX
/ dev / Xdx [AZ]: XT hard disk is named Xdx
/ dev / VDX [AZ]: virtual hard disk is named VDX
/ dev / fdN: floppy disk is named fdN
/ dev / scdN or / dev / srN: CD-ROM is named / dev / scdN or / dev / srN

fdisk allows us to create up to four primary partitions per disk drive. One of them can be used as extended partition, and consists of a plurality of logical partitions. 1-4 sector is retained as the primary partition, logical partitions start from the sector 5.

A, fdisk method parameters:

fdisk [-l] device name

Parameters
-l: display the partition table information for the specified disk device, if you do not specify a disk device, / proc / partitions file information, that is, the system displays all of the disk devices.

Example:
------------------------------------------------ -----------
root @ Debian: # ~ # fdisk the -l did not specify any disk device

Disk / dev / sda: 20 GiB , 21474836480 bytes, 41943040 sectors # of a disk / dev / sda capacity 20G
Units: = 512 sectors of 512 bytes. 1 *
Sector size (Logical / PHYSICAL): 512 bytes / 512 bytes
the I / size O (Minimum / Optimal): 512 bytes / 512 bytes
Disklabel where type: type dos # partition table (MBR partition table indicates dos, gpt represents GPT partition table) for the MBR
Disk identifier: 0xefdc905c

Device Boot Start End Sectors Size Id Type # disk / dev / partition under sda
/ dev / sda1 * 2048 37,748,735 377 466 881 8G 83 Linux
/ dev / sda2 37,750,782 41,940,991 4.19021 million 2G 5 Extended
/ dev / sda5 37,750,784 41,940,991 4,190,208 2G 82 Linux swap / Solaris

Disk /dev/sdb: 5 GiB, 5368709120 bytes, 10485760 sectors      #第二块磁盘/dev/sdb容量5G
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

Debian @ root: ~ #
-------------------------------------------- ---------------
use "fdisk -l" to view partition information, different releases may differ from the information displayed by the information above to see us add two hard drives (/ dev / sda and / dev / sdb) information. We explain this information, which is the upper half of the overall state of the hard disk, the total size of / dev / sda hard drive is 20GB and other information.

The lower half of the partition information is information, a total of seven, the following meanings:

Device: device file name of the partition.
Boot: whether the boot partition, where / dev / sda1 as the boot partition.
Start: starting cylinder, on behalf of the partition where to start.
End: to terminate cylinders, on behalf of the partition where the end.
Sectors: size of the partition, the unit is sectors.
Size: partition size
id: ID partition file system.
Type: What partition filesystem.


Two, fdisk partition interactive mode

Command "fdisk device file name" fdisk can enter the interactive mode program in interactive mode operation can be done by inputting a corresponding command fdisk program provided, for example as follows

-----------------------------------------------------------
root@debian:~# fdisk /dev/sdb

Welcome to fdisk (util-linux 2.29.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table.
Created a new DOS disklabel with disk identifier 0xe3779e93.

Command (m for help): m # m input can get help

Help:

DOS (the MBR)
A Toggle A Bootable In Flag Set # bootable flag
b edit nested BSD disklabel # bsd disk label editing
c toggle the dos compatibility flag # DOS operating system compatible flag set

Eneric G
D A Delete Partition # delete a partition
F list free unpartitioned space # unpartitioned space list free
l list known partition types # known partition type display. 82 is a Linux swap partition, Linux partition 83
n add a new partition # New Partition
p print the partition table # current disk partition listing
t change a partition type # change the partition type
v verify the partition table # verification partition table
i print information about a partition # print information on partitioning

Misc
m Print the this display the MENU # Help menu
u change display / entry units # changing the display recording unit
x extra functionality (experts only) # additional functionality (experts only)

Script
the I Disk layout from the Load Script File # sfdisk loaded from disk layout sfdisk script file
O dump disk layout to sfdisk script file # sfdisk to dump the disk layout script file

& Exit the Save
w the Write to Disk and the Table Exit # save and exit
q quit without saving changes # exit without saving

A new new label the Create
G new new empty the Create A New Blank GPT Partition the Table # GPT partition table, this should have to show that support GPT fdisk, need further certification.
G create a new empty SGI (IRIX ) partition table # IRIX new blank partition table
o create a new empty DOS partition table # New Blank DOS tables
s create a new empty Sun partition table # new blank disk label SUN


Command (m for help):
-----------------------------------------------------------

Third, partition management

1, the new primary partition

root @ debian: ~ # fdisk / dev / sdb # To create a new disk partition / dev / sdb Do not add numbers plus the number becomes a partition

Welcome to fdisk (util-linux 2.29.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table.
Created a new DOS disklabel with disk identifier 0xd9b1702f.

Command (m for help): n # n to create a new partition, the default directly create MBR partition table
the Partition type
P Primary (0 Primary, 0 Extended,. 4 Free) # primary partition
e extended (container for logical partitions) # extended partition
Select ( default p): p # p input new primary partition
partition number (1-4, default 1) : # partition number, direct the transport line, by default. 1
First a SECTOR (2048-10485759, default 2048): enter the starting # sector, direct the transport line, the default start foremost 2048
Last sector, + sectors or + size {K, M, G, T, P} (2048-10485759, default 10485759): + 1G # entered here new partition size may be increased by the number of sectors may be increased by + size {K, M, G , T, P} way to increase this capacity is expressed as the 1G 1G +       

the Created Partition. 1 a new new type of 'the Linux' and of size 1 GiB. # 1G prompted to create a partition

Command (m for help): p # input partition p view created
Disk / dev / SDB:. 5 GiB, 5,368,709,120 bytes, 10485760 sectors
Units: sectors of. 1 * 512 = 512 bytes
Sector size (Logical / PHYSICAL): 512 bytes / bytes 512
the I / O size (Minimum / Optimal): 512 bytes / 512 bytes
Disklabel where type: # DOS partition table type the MBR
Disk identifier: 0xd9b1702f

Device    Boot   Start   End     Sectors   Size   Id   Type
/dev/sdb1      2048   2099199   2097152   1G   83   Linux

2, the remaining available space

Command (m for help): F # input F View remaining available space
Unpartitioned Space / dev / SDB:. 4 GiB, 4,293,918,720 bytes, 8.38656 million sectors
Units: sectors of. 1 * 512 = 512 bytes
Sector size (Logical / PHYSICAL): 512 bytes / 512 bytes

Sectors Size End Start
2.0992 million 10,485,759 8.38656 million 4G # can see the available space for 4G

3, create an extended partition and logical partitions

Command (m for help): n # n to continue to create partitions
Partition type
P Primary (. 1 Primary, 0 Extended,. 3 Free)
e Extended (Container for Logical Partitions)
the Select (default P): e # e to create an extended partition
Partition number (2-4, default 2): # enter the extended partition number, can directly enter
First sector (2099200-10485759, default 2099200) : # enter the starting sector number, can directly enter
Last sector, + sectors or + size {K, M, G, T, P} (2099200-10485759, default 10485759): + 2G # increase the capacity of 2G

created a new partition 2 of type ' extended' and of size 2 GiB # create an extended partition. success

Command (m for help): n # n to continue to create partitions
Partition of the type
the p-Primary (1 Primary, Extended 1, 2 as Free)
L the Logical (Numbered. From 5) # only create an extended partition will have the option
Select (default p ): l # l input to create logical partitions

Adding logical partition 5 # 5 starts from an extended partition No.
First a SECTOR (2101248-6293503, default 2,101,248):
Last a SECTOR, sectors or + size + {K, M, G, T, P} (2101248-6293503, default 6,293,503): + 1G

Created a new partition 5 of type 'Linux' and of size 1 GiB.

Command (m for help):  p
Disk /dev/sdb: 5 GiB, 5368709120 bytes, 10485760 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xd9b1702f

Size the Boot Sectors the Start End Device Id the Type
/ dev / sdb1 2048 2099199 2097152. 1G # 83 the Linux primary partition
/ dev / sdb2 2099200 6293503 4194304 2G 5 Extended # extended partition
/ dev / sdb5 2101248 4198399 2097152 1G 83 Linux # logical partition

4, delete partition

Command (m for help): d # d Delete input partition
Partition number (1,2,5, default 5) : 2 # Amplification Delete Partition 2, the above logical partition is also deleted together

Partition 2 has been deleted.

Command (m for help): p
Disk /dev/sdb: 5 GiB, 5368709120 bytes, 10485760 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xd9b1702f

Device Boot Start End Sectors Size Id Type
/dev/sdb1 2048 2099199 2097152 1G 83 Linux

Command (m for help):

5, modified partition type

Command (m for help): l # View available partition type


# 82 is a Linux swap partitions, 83 partitions for Linux, 8e is LinuxLVM partition, b is Windows FAT32 partition, e is Windows FAT16 partition.

Command (m for help): t # t change the partition type input
Partition number (1,2,5, default 5) : 5 # 5 to change the partition type of

Partition type (type L to list all types): 8e # input to change the partition type 8e, l entered here can also see the type of partition

Changed type of partition 'Linux' to 'Linux LVM'. # Prompt changed successfully

Command (m for help): p
Disk /dev/sdb: 5 GiB, 5368709120 bytes, 10485760 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xd9b1702f

The Boot Start End Sectors Size Device Id Type
/ dev / sdb1 1G 2048 2099199 2097152 83 Linux
/ dev / 2G sdb2 2.0992 million 6293503 4194304 5 Extended
/ dev / sdb5 2,101,248 4,198,399 2097152 1G after Linux LVM # 8E change the partition type

Command (m for help):

6. Save the modified results

Command (m for help): w # w Enter to save the configuration, if not want to save enter q exit
of The Partition Table has been Altered.
The Calling the ioctl () to Re-Read Partition Table.
Syncing Disks.


After use w command to save, it is done in fdisk all operations will take effect, and can not be rolled back. If the partition table is busy, you will need to restart the machine only after the new partition table to take effect.

Fourth, the new GPT partition

Not all releases are supported with the fdisk GPT partitions here Please note

1, the new zoning

Command (m for help): p

Disk /dev/sdb: 5 GiB, 5368709120 bytes, 10485760 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos                  #现在的分区类型为MBR
Disk identifier: 0xd9b1702f

Command (m for help): g # g create input GPT partition
Created a new GPT disklabel (GUID: 8C0F4613-2830-40E1-8D23-596D1B7F5DDB).

Command (m for help): n # new partition
Partition number (1-128, default 1) : # can be seen that there is no concept of partitioning the extended
First a SECTOR (2048-10485726, default 2048):
Last a SECTOR, sectors or + + size {K, M, G , T, P} (2048-10485726, default 10485726): + 1G

Created a new partition 1 of type 'Linux filesystem' and of size 1 GiB.

Command (m for help): p
Disk /dev/sdb: 5 GiB, 5368709120 bytes, 10485760 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: 8C0F4613-2830-40E1-8D23-596D1B7F5DDB

Under input p displayed under the Device Start End Sectors Size Type #GPT MBR and partition information is slightly different, there is no partition type id option
/ dev / sdb1 2048 2099199 2097152 1G Linux filesystem # successfully created a primary partition

Command (m for help):

 

2, a modified type of partition

Command (m for help): l # view partition type, at the same GPT partition type corresponding to different numbers here to note

 Above only shows part of the press the space bar to display more information

 

Command (m for help): t # t change the partition type of the input, the input can also see where l type partition
Partition number (1,2, default 2) : 2 # entered to change the partition
Hex code (type L to list all codes): 31 # enter the partition type number 

 

Changed type of partition 'Linux filesystem' to 'Linux LVM'. # Change the partition type success

 

Command (m for help): p                                      
Disk /dev/sdb: 5 GiB, 5368709120 bytes, 10485760 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: 836D334F-D0EE-4AD3-8581-EC9ABFF31F50

 

Sectors Start End Size Type Device
/ dev / sdb1 2048 2,099,199 2097152 1G Linux filesystem
/ dev / sdb2 2.0992 million 4,196,351 2097152 # 1G Linux LVM partition type has changed

 

Command (m for help):

 

Published 136 original articles · won praise 38 · views 260 000 +

Guess you like

Origin blog.csdn.net/Pipcie/article/details/104964743