在Linux系统中,主分区、逻辑分区和扩展分区都是磁盘分区的方式,它们各自有不同的特点和应用场景。
主分区:主分区是硬盘的启动分区,也称为引导分区,通常对应于计算机的第一个分区。主分区必须是可用的,也就是说它必须包含有效的文件系统,并且该文件系统必须是活动的。在Linux中,主分区可以有多种文件系统类型,如ext4、ntfs、vfat等。主分区通常用于存储操作系统、应用程序和数据,并且是计算机启动时所加载的第一个分区。
逻辑分区:逻辑分区是在扩展分区内部创建的多个分区。扩展分区不能直接使用,必须划分成多个逻辑分区。逻辑分区可以有多种文件系统类型,并用于存储用户数据、应用程序或系统临时文件等。在Linux中,逻辑分区的创建和管理通常使用fdisk、parted等工具进行。
扩展分区:扩展分区是一种特殊类型的分区,用于容纳逻辑分区。扩展分区本身不能直接使用,必须进一步划分成多个逻辑分区。扩展分区的容量等于其包含的所有逻辑分区的容量之和。在Linux中,扩展分区的创建和管理可以使用fdisk、parted等工具进行。
总结来说,主分区是硬盘的启动分区,必须包含有效的文件系统,并且该文件系统必须是活动的;逻辑分区是在扩展分区内部创建的多个分区,用于存储用户数据、应用程序或系统临时文件等;而扩展分区是一种特殊类型的分区,用于容纳逻辑分区,其容量等于其包含的所有逻辑分区的容量之和。
[root@logicfeng ~]# fdisk -l
Disk /dev/sda: 21.5 GB, 21474836480 bytes, 41943040 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
Disk label type: dos
Disk identifier: 0x0009caea
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 41943039 19921920 8e Linux LVM
Disk /dev/mapper/centos-root: 18.2 GB, 18249416704 bytes, 35643392 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
Disk label type: dos
Disk identifier: 0x1c42ed69
Device Boot Start End Blocks Id System
/dev/mapper/centos-root1 2048 8390655 4194304 83 Linux
Disk /dev/mapper/centos-swap: 2147 MB, 2147483648 bytes, 4194304 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
fdisk -l /dev/mapper/centos-root
观察某个分区/硬盘之实体使用情形[root@logicfeng ~]# fdisk -l /dev/mapper/centos-root
Disk /dev/mapper/centos-root: 18.2 GB, 18249416704 bytes, 35643392 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
Disk label type: dos
Disk identifier: 0x1c42ed69
Device Boot Start End Blocks Id System
/dev/mapper/centos-root1 2048 8390655 4194304 83 Linux
Device Boot
(引导):表示引导分区Start
(开始):表示一个分区从哪个柱面开始End
(结束):表示一个分区到哪个柱面结束Blocks
(容量):表示分区容量,单位KB
Id
和System
:确认分区类型fdisk /dev/mapper/centos-root
进入根目录所在磁盘,进入分割硬盘模式[root@logicfeng ~]# fdisk /dev/mapper/centos-root
Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help):
m
,查看命令介绍Command (m for help): m
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
g create a new empty GPT partition table
G create an IRIX (SGI) partition table
l list known partition types
m print this menu
n add a new partition
o create a new empty DOS partition table
p print the partition table
q quit without saving changes
s create a new empty Sun disklabel
t change a partition's system id
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)
m
显示所有命令列示。p
显示硬盘分割情形。a
设定硬盘启动区。n
设定新的硬盘分割区。e
硬盘为[延伸]分割区(extend)。p
硬盘为[主要]分割区(primary)。t
改变硬盘分割区属性。d
删除硬盘分割区属性。q
结束不存入硬盘分割区属性。w
结束并写入硬盘分割区属性p
Command (m for help): p
Disk /dev/mapper/centos-root: 18.2 GB, 18249416704 bytes, 35643392 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
Disk label type: dos
Disk identifier: 0x1c42ed69
Device Boot Start End Blocks Id System
/dev/mapper/centos-root1 2048 8390655 4194304 83 Linux
Command (m for help):
n
Command (m for help): n
Partition type:
p primary (0 primary, 0 extended, 4 free) # 主分区
e extended # 扩展分区
Select (default p): p # 输入p选择主分区,注意到括号中的4free,最多只能建四个主分区(包括扩展分区)
Partition number (1-4, default 1): 1 # 默认选择分区号为1
First sector (2048-35643391, default 2048): # 直接回车,从默认柱面开始划分
Using default value 2048 # 从2048开始划分
Last sector, +sectors or +size{K,M,G} (2048-35643391, default 35643391): +4G # 大小4个G,不能超过该磁盘剩余的空间否则无效
Partition 1 of type Linux and of size 4 GiB is set
Command (m for help): p
Disk /dev/mapper/centos-root: 18.2 GB, 18249416704 bytes, 35643392 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
Disk label type: dos
Disk identifier: 0x1c42ed69
Device Boot Start End Blocks Id System
/dev/mapper/centos-root1 2048 8390655 4194304 83 Linux
n
Command (m for help): n
Partition type:
p primary (1 primary, 0 extended, 3 free)
e extended
Select (default p): e # 选择e为扩展分区
Partition number (2-4, default 2): 2 # 默认第2
First sector (8390656-35643391, default 8390656): # 从默认开始8390656
Using default value 8390656
Last sector, +sectors or +size{K,M,G} (8390656-35643391, default 35643391): +4G # 大小4个G
Partition 2 of type Extended and of size 4 GiB is set
p
Command (m for help): p
Disk /dev/mapper/centos-root: 18.2 GB, 18249416704 bytes, 35643392 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
Disk label type: dos
Disk identifier: 0x1c42ed69
Device Boot Start End Blocks Id System
/dev/mapper/centos-root1 2048 8390655 4194304 83 Linux # 这个是主分区
/dev/mapper/centos-root2 8390656 16779263 4194304 5 Extended # 这个是扩展分区
Command (m for help): n
Partition type:
p primary (1 primary, 1 extended, 2 free)
l logical (numbered from 5)
Select (default p): l # 选择逻辑分区
Adding logical partition 5
First sector (8392704-16779263, default 8392704): # 默认开始位置
Using default value 8392704
Last sector, +sectors or +size{K,M,G} (8392704-16779263, default 16779263): +2G # 大小2个G,不能超过扩展分区的大小
Partition 5 of type Linux and of size 2 GiB is set
p
Command (m for help): p
Disk /dev/mapper/centos-root: 18.2 GB, 18249416704 bytes, 35643392 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
Disk label type: dos
Disk identifier: 0x1c42ed69
Device Boot Start End Blocks Id System
/dev/mapper/centos-root1 2048 8390655 4194304 83 Linux
/dev/mapper/centos-root2 8390656 16779263 4194304 5 Extended
/dev/mapper/centos-root5 8392704 12587007 2097152 83 Linux
w
Command (m for help): w #保存退出
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.