Master Linux Disk Partitioning: From MBR to GPT and Mounting Filesystems
This guide explains how to classify storage devices, compare MBR and GPT partition tables, use Linux commands such as lsblk, fdisk, and gdisk to create partitions, format them with ext4 or XFS, and permanently mount them via /etc/fstab, providing a complete workflow for disk management.
1 Storage Types
Classify disks by working principle: HDD (mechanical) and SSD (solid‑state).
Classify by hot‑plug capability: hot‑plug and non‑hot‑plug.
Classify by interface: IDE‑SATA (serial ATA), SCSI‑SAS (serial SCSI), PCIe, and FC (fiber‑channel).
Classify by connection: local storage, external storage, and network storage.
Classify by partition scheme: MBR and GPT.
MBR (Master Boot Record)
MBR是MSDOS;
兼容windows的MBR(Master boot record);
只能处理小于2TB的磁盘;
用fdisk工具分区;
最多只能有14个分区(4个主分区,扩展分区,逻辑分区);
磁盘的第一扇区,第一扇区有512bytes,存放两类数据:MBR和分区表
MBR: 安装有开机管理程序,占446bytes
分区表: 记录整颗磁盘分区的状态,占64bytes
由于分区表只有64bytes,所以只能最多有四组记录区(每个记录占用16bytes),每组记录区记录了该区段的起始和结束扇区号码;
所以每块磁盘只能有四个分区槽;
这四个分区槽是主分区Primary和扩展分区Extended;
每个分区的前面都有一个启动扇区,用于存放操作系统的启动程序;
扩展分区的前面有一个扩展分区启动记录区占用多个扇区,用于存放里面的所有逻辑分区的起止扇区号码;
扩展分区不能格式化,只能再分成若干个逻辑分区槽;
扩展分区利用多个扇区来记录逻辑分区信息,由于是用多个扇区来记录,所以支持大于4个逻辑分区; 逻辑分区的槽号是从5开始,1-4是保留给主分区和扩展分区的
P1: /dev/sda1
P2: /dev/sda2
L1: /dev/sda5
L2: /dev/sda6
L3: /dev/sda7
L4: /dev/sda8
L5: /dev/sda9MBR中主分区、扩展分区、逻辑分区总结 主分区和扩展分区最多有4个; 扩展分区最多只能有1个; 逻辑分区由扩展分区生成; 能被格式化后使用的分区为主分区和逻辑分区;扩展分区不能直接使用; 逻辑分区的数量由操作系统决定。
GPT(GUID Partition Table)
可以处理大于或小于2TB的磁盘;
在CentOS6中用parted工具分区;在CentOS7中用gdisk工具分区;
最多只能有128个分区;没有扩展分区和逻辑分区的概念,都是主分区
GPT将磁盘所有区块以LBA来规划;LBA:Logical Block Address,预设每个LBA为512bytes,第一个LBA称为LBA0;
GPT使用前面的34个LBA;除此之外还使用了最后的33个LBA做备份;
GPT分区中没有主分区、扩展分区、逻辑分区的概念,每个分区都能使用;
磁盘管理程序中fdisk不识别GPT分区;gdisk和parted可以识别;
grub第一版不识别GPTLBA0: 与MBR兼容。这个LBA0块也分两部分,第一部分是和MBR相似的446bytes块区,存储了第一阶段的开机管理程序;第二部分放置了一个特殊标志的分区用来表示此块磁盘为GPT分区格式磁盘,不能识别GPT分区表的磁盘管理程序是不能修改此分区信息的
LBA1: 记录GPT分区表的表头数据,内容为:分区表本身的位置和大小;备份GPT(最后34个LBA区块)放置的位置;放置了分区表检验机制码CRC32,操作系统根据这个码来判断GPT是否正确,如果错误,从备份GPT恢复。
LBA2-33: 实际记录分区信息的地方,每个LBA可以记录4个分区槽信息,所以一共可以有128个分区槽2 Basic Partitioning
7.2.1 Adding a New Disk
Use lsblk to view the current block devices and their partitions.
[root@localhost boot]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 30G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 29G 0 part
├─centos-root 253:0 0 26G 0 lvm /
└─centos-swap 253:1 0 3G 0 lvm [SWAP]
sdb 8:16 0 20G 0 disk
└─sdb1 8:17 0 8G 0 part
sr0 11:0 1 4.4G 0 rom /run/media/root/CentOS 7 x86_647.2.2 MBR Partition
Use fdisk -l to list disks and their partition tables.
[root@localhost boot]# fdisk -l /dev/sda
磁盘 /dev/sda:32.2 GB, 32212254720 字节,62914560 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
磁盘标签类型:dos
磁盘标识符:0x000a533f
设备 Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 62914559 30407680 8e Linux LVMCreating a new partition on /dev/sdb with fdisk :
# fdisk /dev/sdb
命令(输入 m 获取帮助):
n # new partition
p # primary
2 # partition number (default 2)
16779264 # first sector (default)
+100M # last sector (+size)
w # write changesAfter creating partitions, view the updated table:
# fdisk -l /dev/sdb
磁盘 /dev/sdb:21.5 GB, 21474836480 字节,41943040 个扇区
磁盘标签类型:dos
设备 Boot Start End Blocks Id System
/dev/sdb1 2048 16779263 8388608 83 Linux
/dev/sdb2 16779264 16984063 102400 83 Linux7.2.3 GPT Partition
Use gdisk to create a GPT partition table.
# gdisk /dev/sdb
Command (? for help): n
Partition number (3-128, default 3):
First sector (34-41943006, default = 16984064):
Last sector (16984064-41943006, default = 41943006): +100M
Current type is 'Linux filesystem'
Changed type to 'Linux filesystem'
Command (? for help): w
Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING PARTITIONS!!
Do you want to proceed? (Y/N): y
OK; writing new GUID partition table (GPT) to /dev/sdb.2.4 Creating Filesystems
Format the newly created partitions with the desired filesystem.
# mkfs.ext4 /dev/sdb1
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size = 4096 (log = 2)
... # mkfs.xfs /dev/sdb2
meta-data=/dev/sdb2 isize=512 agcount=4, agsize=6400 blks
...2.5 Mounting Partitions
Create mount points and mount the formatted partitions.
# mkdir /date01
# mkdir /date02
# mount /dev/sdb1 /date01
# mount /dev/sdb2 /date02Verify with df -h :
# df -h
文件系统 容量 已用 可用 已用% 挂载点
/dev/sdb1 7.8G 36M 7.3G 1% /date01
/dev/sdb2 97M 5.3M 92M 6% /date02Obtain UUIDs with blkid and add them to /etc/fstab for persistent mounts.
# blkid
/dev/sdb1: UUID="67e9447b-a6dd-47d2-a738-55983bc3c915" TYPE="ext4" PARTLABEL="Linux filesystem" PARTUUID="fbc32bc2-b7da-4912-a191-920413125325"
/dev/sdb2: UUID="570e001f-162e-4ecd-8873-6d2c82c0edfb" TYPE="xfs" PARTLABEL="Linux filesystem" PARTUUID="1254b3e7-55be-40ca-b198-0b57f29dbf6a" # /etc/fstab
UUID=67e9447b-a6dd-47d2-a738-55983bc3c915 /date01 xfs defaults 0 0
UUID=570e001f-162e-4ecd-8873-6d2c82c0edfb /date02 auto ro 0 03 Chapter Summary
This chapter introduced storage classifications, explained the differences between MBR and GPT partition tables, and demonstrated how to create basic partitions, format them with ext4 or XFS, and mount them permanently on a Linux system.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
MaGe Linux Operations
Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
