4.3-磁盘分区(上)添加磁盘然后创建主分区、扩展分区、逻辑分区

在分区前,我们先来增加一块虚拟磁盘。先关闭正在运行的linux系统。关机命令为:init 0

关机

[root@evan-01 ~]# init 0

增加虚拟磁盘
《4.3-磁盘分区(上)添加磁盘然后创建主分区、扩展分区、逻辑分区》《4.3-磁盘分区(上)添加磁盘然后创建主分区、扩展分区、逻辑分区》《4.3-磁盘分区(上)添加磁盘然后创建主分区、扩展分区、逻辑分区》《4.3-磁盘分区(上)添加磁盘然后创建主分区、扩展分区、逻辑分区》《4.3-磁盘分区(上)添加磁盘然后创建主分区、扩展分区、逻辑分区》《4.3-磁盘分区(上)添加磁盘然后创建主分区、扩展分区、逻辑分区》《4.3-磁盘分区(上)添加磁盘然后创建主分区、扩展分区、逻辑分区》《4.3-磁盘分区(上)添加磁盘然后创建主分区、扩展分区、逻辑分区》《4.3-磁盘分区(上)添加磁盘然后创建主分区、扩展分区、逻辑分区》

查看磁盘

[root@evan-01 ~]# fdisk
Usage:
 fdisk [options] <disk>    change partition table
 fdisk [options] -l <disk> list partition table(s)
 fdisk -s <partition>      give partition size(s) in blocks

Options:
 -b <size>             sector size (512, 1024, 2048 or 4096)
 -c[=<mode>]           compatible mode: 'dos' or 'nondos' (default)
 -h                    print this help text
 -u[=<unit>]           display units: 'cylinders' or 'sectors' (default)
 -v                    print program version
 -C <number>           specify the number of cylinders
 -H <number>           specify the number of heads
 -S <number>           specify the number of sectors per track

[root@evan-01 ~]#

展示出fdisk的很多选项,可以根据需求,自己使用

fdisk -l 列出分区表


[root@evan-01 ~]# 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: 0x000c973a

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200    41943039    19921920   8e  Linux LVM

Disk /dev/sdb: 10.7 GB, 10737418240 bytes, 20971520 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 /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 /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
I/O size (minimum/optimal): 512 bytes / 512 bytes

[root@evan-01 ~]#

我们已经能看到有了一个磁盘 /dev/sdb:10.7 GB了,这个就是我们刚才添加的磁盘

磁盘分区

[root@evan-01 ~]# fdisk /dev/sdb
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.

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

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)

Command (m for help):
命令含义
n (new)添加一个新分区
p (print)打印分区表
w (write)添将表写入磁盘并退出
d (delete)删除一个分区

p 打印分区列表

Command (m for help): p     

Disk /dev/sdb: 10.7 GB, 10737418240 bytes, 20971520 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: 0x4ce7226c

   Device Boot      Start         End      Blocks   Id  System

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 主分区:
都用主分区的话,最多可以划分4个。如果想划分多个的话,可以划分3个主分区。另外一个划分为扩展分区。在扩展分区里面再接着划分逻辑分区。

e 扩展分区

创建主分区
创建第一个主分区(+2G)
n创建新分区,p选择主分区,回车(默认分区号1),回车(默认磁盘扇区从2048开始),+2G(设置分区大小为2G),p(查看分区)发现已经有了1个主分区了

Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
Partition number (1-4, default 1): 
First sector (2048-20971519, default 2048): 
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519): +2G
Partition 1 of type Linux and of size 2 GiB is set

Command (m for help): p

Disk /dev/sdb: 10.7 GB, 10737418240 bytes, 20971520 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: 0x4ce7226c

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048     4196351     2097152   83  Linux

Command (m for help):

创建第二个主分区(+2G)
n创建新分区,p选择主分区,回车(默认分区号2),回车(默认磁盘扇区从4196352开始),+2G(设置分区大小为2G),p(查看分区)发现已经有了2个主分区了

Command (m for help): n
Partition type:
   p   primary (1 primary, 0 extended, 3 free)
   e   extended
Select (default p): p
Partition number (2-4, default 2): 
First sector (4196352-20971519, default 4196352): 
Using default value 4196352
Last sector, +sectors or +size{K,M,G} (4196352-20971519, default 20971519): +2G
Partition 2 of type Linux and of size 2 GiB is set

Command (m for help): p

Disk /dev/sdb: 10.7 GB, 10737418240 bytes, 20971520 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: 0x4ce7226c

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048     4196351     2097152   83  Linux
/dev/sdb2         4196352     8390655     2097152   83  Linux

Command (m for help):

创建第三个主分区(+1G)
n创建新分区,p选择主分区,回车(默认分区号3),回车(默认磁盘扇区从8390656开始),+1G(设置分区大小为1G),p(查看分区)发现已经有了3个主分区了

Command (m for help): n
Partition type:
   p   primary (2 primary, 0 extended, 2 free)
   e   extended
Select (default p): p
Partition number (3,4, default 3): 
First sector (8390656-20971519, default 8390656): 
Using default value 8390656
Last sector, +sectors or +size{K,M,G} (8390656-20971519, default 20971519): +1G
Partition 3 of type Linux and of size 1 GiB is set

Command (m for help): p

Disk /dev/sdb: 10.7 GB, 10737418240 bytes, 20971520 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: 0x4ce7226c

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048     4196351     2097152   83  Linux
/dev/sdb2         4196352     8390655     2097152   83  Linux
/dev/sdb3         8390656    10487807     1048576   83  Linux

Command (m for help):

创建第四个主分区(+1G)
n创建新分区,p选择主分区,回车(默认分区号4),回车(默认磁盘扇区从10487808开始),+1G(设置分区大小为1G),p(查看分区)发现已经有了4个主分区了

Command (m for help): n
Partition type:
   p   primary (3 primary, 0 extended, 1 free)
   e   extended
Select (default e): p
Selected partition 4
First sector (10487808-20971519, default 10487808): 
Using default value 10487808
Last sector, +sectors or +size{K,M,G} (10487808-20971519, default 20971519): +1G
Partition 4 of type Linux and of size 1 GiB is set

Command (m for help): p

Disk /dev/sdb: 10.7 GB, 10737418240 bytes, 20971520 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: 0x4ce7226c

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048     4196351     2097152   83  Linux
/dev/sdb2         4196352     8390655     2097152   83  Linux
/dev/sdb3         8390656    10487807     1048576   83  Linux
/dev/sdb4        10487808    12584959     1048576   83  Linux

Command (m for help): 

接着再创建主分区

翻译:如果要创建四个以上的分区,则必须替换
首先用扩展分区进行主分区

Command (m for help): n
If you want to create more than four partitions, you must replace a
primary partition with an extended partition first.

Command (m for help): 

删除一个主分区
d删除分区,回车(默认删除分区号4),p(查看分区)发现已经还剩3个主分区了

Command (m for help): d
Partition number (1-4, default 4): 
Partition 4 is deleted

Command (m for help): p

Disk /dev/sdb: 10.7 GB, 10737418240 bytes, 20971520 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: 0x4ce7226c

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048     4196351     2097152   83  Linux
/dev/sdb2         4196352     8390655     2097152   83  Linux
/dev/sdb3         8390656    10487807     1048576   83  Linux

Command (m for help): 

创建扩展分区
n创建新分区,e选择扩展分区,回车(默认分区号4),回车(默认磁盘扇区从10487808开始),+4G(设置分区大小为4G),p(查看分区)发现已经有了3个主分区、1个扩展分区

Command (m for help): n           
Partition type:
   p   primary (3 primary, 0 extended, 1 free)
   e   extended
Select (default e): e
Selected partition 4
First sector (10487808-20971519, default 10487808): 
Using default value 10487808
Last sector, +sectors or +size{K,M,G} (10487808-20971519, default 20971519): +4G
Partition 4 of type Extended and of size 4 GiB is set

Command (m for help): p

Disk /dev/sdb: 10.7 GB, 10737418240 bytes, 20971520 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: 0x4ce7226c

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048     4196351     2097152   83  Linux
/dev/sdb2         4196352     8390655     2097152   83  Linux
/dev/sdb3         8390656    10487807     1048576   83  Linux
/dev/sdb4        10487808    18876415     4194304    5  Extended

Command (m for help): 

创建逻辑分区
n创建新分区,回车(默认分区号5),回车(默认磁盘扇区从10489856开始),+1G(设置分区大小为1G),p(查看分区)发现已经有了3个主分区、1个扩展分区、1个逻辑分区

Command (m for help): n
All primary partitions are in use
Adding logical partition 5
First sector (10489856-18876415, default 10489856): 
Using default value 10489856
Last sector, +sectors or +size{K,M,G} (10489856-18876415, default 18876415): +1G
Partition 5 of type Linux and of size 1 GiB is set

Command (m for help): p

Disk /dev/sdb: 10.7 GB, 10737418240 bytes, 20971520 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: 0x4ce7226c

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048     4196351     2097152   83  Linux
/dev/sdb2         4196352     8390655     2097152   83  Linux
/dev/sdb3         8390656    10487807     1048576   83  Linux
/dev/sdb4        10487808    18876415     4194304    5  Extended
/dev/sdb5        10489856    12587007     1048576   83  Linux

Command (m for help): 

再接着创建一个逻辑分区(+1G)
n创建新分区,回车(默认分区号6),回车(默认磁盘扇区从12589056开始),+1G(设置分区大小为1G),p(查看分区)发现已经有了3个主分区、1个扩展分区、2个逻辑分区


Command (m for help): n
All primary partitions are in use
Adding logical partition 6
First sector (12589056-18876415, default 12589056): 
Using default value 12589056
Last sector, +sectors or +size{K,M,G} (12589056-18876415, default 18876415): +1G
Partition 6 of type Linux and of size 1 GiB is set

Command (m for help): p

Disk /dev/sdb: 10.7 GB, 10737418240 bytes, 20971520 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: 0x4ce7226c

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048     4196351     2097152   83  Linux
/dev/sdb2         4196352     8390655     2097152   83  Linux
/dev/sdb3         8390656    10487807     1048576   83  Linux
/dev/sdb4        10487808    18876415     4194304    5  Extended
/dev/sdb5        10489856    12587007     1048576   83  Linux
/dev/sdb6        12589056    14686207     1048576   83  Linux

Command (m for help):
    原文作者:Evan's
    原文地址: https://blog.csdn.net/u010148669/article/details/99677448
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞