background
When using fdisk to create a partition, we can only create a maximum size of 2TB partition. If you want to create a partition larger than 2T, you need to use the GPT disk mode. The following supplements the basic knowledge of GPT and MBR and the method of dividing more than 2T partitions.
basic concept
MBR
1. MBR, this disk mode is our common mode, the English full name is Master Boot Record, abbreviation: MBR, the Chinese name is the master boot record, also known as the master boot sector.
2. The hard disk with MBR type partition structure (the disk volume label type is MS-DOS) can only recognize 4 main partitions at most. So for a hard disk with this partition structure, it is impossible to get more than 4 main partitions. This is where the extended partition needs to be introduced. The extended partition is also a type of primary partition, but it is different from the primary partition in that it can theoretically be divided into an infinite number of logical partitions, and each logical partition has an extended boot record (EBR) similar to the MBR structure. There are at most 4 primary partitions or 3 primary partitions + 1 extended partition in the MBR partition table, that is to say, there can only be one extended partition, and then it can be subdivided into multiple logical partitions.
3. In the Linux system, the hard disk partition is named sda1-sda4 or hda1-hda4 (where a indicates that the hard disk number may be a, b, c, etc.). In MBR hard disks, partition numbers 1-4 are primary partitions (or extended partitions), and logical partition numbers can only start from 5. In the MBR partition table, the maximum capacity of a partition is 2T, and the starting cylinder of each partition must be within the first 2T of the disk. You have a 3T hard disk. According to the requirements, you should divide it into at least 2 partitions, and the starting sector of the last partition should be located in the first 2T space of the hard disk. If the hard drive is too large you must use GPT instead.
GPT
1. GPT, the English full name is GUID Partition Table, abbreviation: GPT, the Chinese name is the global unique identification partition table. It is part of EFI (Extensible Firmware Interface) and is used to replace the Master Boot Record partition table in BIOS.
2. In the MBR hard disk, the partition information is directly stored in the master boot record (MBR) (the system boot program is also stored in the master boot record). But in GPT hard drives, the location information of the partition table is stored in the GPT header. But for compatibility reasons, the first sector of the hard disk is still used as the MBR, and then the GPT header.
Comparison of MBR and GPT
category | master boot | Number of primary partitions | Maximum capacity | How many bit systems are supported | partition method |
---|---|---|---|---|---|
MBR | BIOS+MBR | 4 | 2T | 32 and 64 | fdisk |
GPT | UEFI+GPT | 128 | 18EB(1EB=1024PB=1048576TB) | 64 | parted |
Partitioning method and practical case of GPT
GPT partition mainly uses the parted command to realize the case: the 20GB hard disk is divided into two partitions, one is 10GB and the other is 5.5GB, and is formatted as ext4 to mount.
1. Check the disk number
fdisk -l
The disk number of the case is /dev/sdb
2, using parted partition
[root@Demo ~]# parted /dev/sdb //Enter parted command + disk number
GNU Parted 2.1
Using /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands. //prompt help will list commands
(parted) help
align-check TYPE N check partition N for TYPE(min|opt) alignment check NUMBER do a simple check on the file system cp [FROM-DEVICE] FROM-NUMBER TO-NUMBER copy file system to another partition help [COMMAND] print general help, or help on COMMAND mklabel,mktable LABEL-TYPE create a new disklabel (partition table) mkfs NUMBER FS-TYPE make a FS-TYPE file system on partition NUMBER mkpart PART-TYPE [FS-TYPE] START END make a partition mkpartfs PART-TYPE FS-TYPE START END make a partition with a file system move NUMBER START END move partition NUMBER name NUMBER NAME name partition NUMBER as NAME print [devices|free|list,all|NUMBER] display the partition table, available devices, free space, all found partitions, or a particular partition quit exit program rescue START END rescue a lost partition near START and END resize NUMBER START END resize partition NUMBER and its file system rm NUMBER delete partition NUMBER select DEVICE choose the device to edit set NUMBER FLAG STATE change the FLAG on partition NUMBER toggle [NUMBER [FLAG]] toggle the state of FLAG on partition NUMBER unit UNIT set the default unit to UNIT version display the version number and copyright information of GNU Parted
(parted) mklabel gpt //Format the MBR disk as GPT
(parted) mkpart /dev/sdb1 //Partition 1
File system type? [ext2]? ext4 //File system type
Start? 0 //The beginning of the bar
End? 10GB //Partition end position
Warning: The resulting partition is not properly aligned for best performance.
Ignore/Cancel? Ignore
(parted) print //print partition
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Number Start End Size File system Name Flags
1 17.4kB 10.0GB 10000MB /dev/sdb1
(parted) mkpart /dev/sdb2 //Partition 2
File system type? [ext2]? ext4 //Partition file type
Start? 10GB //Partition start location
End? 15.5GB //Partition end position
(parted) print
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Number Start End Size File system Name Flags
1 17.4kB 10.0GB 10000MB /dev/sdb1 2 10.0GB 15.5GB 5500MB /dev/sdb2
3. Formatting
[root@Demo ~]# mkfs.ext4 /dev/sdb1
[root@Demo ~]# mkfs.ext4 /dev/sdb2
4. Mount
[root@Demo ~]# mount /dev/sdb1 /home/test1
[root@Demo ~]# mount /dev/sdb2 /home/test2
5. Add boot self-mounting
vim / ets / fstab
Add to
/dev/sdb1 /home/test1 ext4 defaults 0 0
/dev/sdb2 /home/test2 ext4 defaults 0 0