Linux 主分区_扩展分区_逻辑分区

Posted Vincen_shen

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Linux 主分区_扩展分区_逻辑分区相关的知识,希望对你有一定的参考价值。

目录:

  1、Linux分区介绍

  2、创建主分区

  3、创建扩展分区

  4、创建逻辑分区  

 

1、Linux分区介绍

  1.1 分区规定:

  每个磁盘设备最多4个主分区,或者3个主分区+1个扩展分区,是因为MBR(主引导记录)的分区表主分区表)只能存放4个分区。

  扩展分区只能有一个。

  逻辑分区可以有多个。

  可以从扩展分区中再次划分多个逻辑分区,逻辑分区编号直接从5开始。

  1.2 分区作用:

  主分区:主要是用来启动操作系统的,它主要放的是操作系统的启动或引导程序,/boot分区最好放在主分区上;

  扩展分区是不能使用的,它只是做为逻辑分区的容器存在的,先创建一个扩展分区,在扩展分区之上创建逻辑分区;

  我们真正存放数据的是主分区和逻辑分区,大量数据都放在逻辑分区中。

 

2、创建主分区

[root@servera ~]# fdisk /dev/vdb

Command (m for help): n  # 创建新分区 Partition type p primary (0 primary, 0 extended, 4 free) e extended (container for logical partitions) Select (default p): p  # 创建主分区 Partition number (1-4, default 1):   # 回车 First sector (2048-10485759, default 2048):   # 回车,设置起始扇区 Last sector, +sectors or +size{K,M,G,T,P} (2048-10485759, default 10485759): 409600  # 设置结尾扇区 Created a new partition 1 of type Linux and of size 199 MiB. Command (m for help): n Partition type p primary (1 primary, 0 extended, 3 free) e extended (container for logical partitions) Select (default p): p  # 创建主分区 Partition number (2-4, default 2):   # 回车 First sector (409601-10485759, default 411648):   # 回车,设置起始扇区 Last sector, +sectors or +size{K,M,G,T,P} (411648-10485759, default 10485759): 819200  # 设置结尾扇区 Created a new partition 2 of type Linux and of size 199 MiB.
Command (m for help): w  # 保存配置 The partition table has been altered. Calling ioctl() to re-read partition table. Syncing disks. [root@servera ~]# fdisk -l /dev/vdb Disk /dev/vdb: 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: 0x03864530 Device Boot Start End Sectors Size Id Type /dev/vdb1 2048 409600 407553 199M 83 Linux /dev/vdb2 411648 819200 407553 199M 83 Linux

 

3、创建扩展分区

[root@servera ~]# fdisk /dev/vdb

Command (m for help): n  # 创建新分区 Partition type p primary (2 primary, 0 extended, 2 free) e extended (container for logical partitions) Select (default p): e  # 创建扩展分区 Partition number (3,4, default 3):   # 选择分区号 First sector (409601-10485759, default 821248):   # 起始扇区 Last sector, +sectors or +size{K,M,G,T,P} (821248-10485759, default 10485759):   # 结尾扇区 Created a new partition 3 of type Extended and of size 4.6 GiB. Command (m for help): w  # 保存配置 The partition table has been altered. Calling ioctl() to re-read partition table. Syncing disks. [root@servera ~]# fdisk -l /dev/vdb Disk /dev/vdb: 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: 0x03864530 Device Boot Start End Sectors Size Id Type /dev/vdb1 2048 409600 407553 199M 83 Linux  # 主分区 /dev/vdb2 411648 819200 407553 199M 83 Linux  # 主分区 /dev/vdb3 821248 10485759 9664512 4.6G 5 Extended  # 扩展分区

 

4、创建逻辑分区

[root@servera ~]# fdisk /dev/vdb

Command (m for help): n  # 创建新分区
All space for primary partitions is in use.  # 提示所有空间都已经分配给主分区使用
Adding logical partition 5  # 从扩展分区中,自动划分逻辑分区
First sector (823296-10485759, default 823296):   # 起始扇区
Last sector, +sectors or +size{K,M,G,T,P} (823296-10485759, default 10485759):   # 结尾扇区

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

Command (m for help): t  # 分区类型
Partition number (1-3,5, default 5): 
Hex code (type L to list all codes): 8e   # LVM类型

Changed type of partition Linux to Linux LVM.

Command (m for help): w  # 保存配置
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.


[root@servera ~]# fdisk -l /dev/vdb
Disk /dev/vdb: 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: 0x03864530

Device     Boot  Start      End Sectors  Size Id Type
/dev/vdb1         2048   409600  407553  199M 83 Linux
/dev/vdb2       411648   819200  407553  199M 83 Linux
/dev/vdb3       821248 10485759 9664512  4.6G  5 Extended
/dev/vdb5       823296 10485759 9662464  4.6G 8e Linux LVM

[root@servera ~]# mkfs.xfs /dev/vdb5  # 格式化逻辑分区
meta-data=/dev/vdb5              isize=512    agcount=4, agsize=301952 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=1, sparse=1, rmapbt=0
         =                       reflink=1
data     =                       bsize=4096   blocks=1207808, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0, ftype=1
log      =internal log           bsize=4096   blocks=2560, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
[root@servera ~]# mount /dev/vdb5 /var/tmp  # 挂载逻辑分区

 

以上是关于Linux 主分区_扩展分区_逻辑分区的主要内容,如果未能解决你的问题,请参考以下文章

Linux基础系列:常用命令_系统监控

0_Linux_虚拟机安装

第2章 Linux系统安装_Linux系统分区及文件系统

linux 学习1

Linux 磁盘--主分区、扩展分区与逻辑分区

Linux 磁盘--主分区、扩展分区与逻辑分区