fdisk创建分区

fdisk创建分区

[root@centos8 ~]# fdisk /dev/sdb

Welcome to fdisk (util-linux 2.32.1).
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.
Created a new DOS disklabel with disk identifier 0x127ea212.

#打印当前情况
Command (m for help): p
Disk /dev/sdb: 20 GiB, 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
Disklabel type: dos
Disk identifier: 0x127ea212

#创建新分区
Command (m for help): n
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
#创建扩展分区
Select (default p): e
Partition number (1-4, default 1): 3
First sector (2048-41943039, default 2048): 
Last sector, +sectors or +size{K,M,G,T,P} (2048-41943039, default 41943039): +2G

Created a new partition 3 of type 'Extended' and of size 2 GiB.

#创建新分区
Command (m for help): n
Partition type
   p   primary (0 primary, 1 extended, 3 free)
   l   logical (numbered from 5)
#创建主分区
Select (default p): p
Partition number (1,2,4, default 1): 2
First sector (4196352-41943039, default 4196352): 
Last sector, +sectors or +size{K,M,G,T,P} (4196352-41943039, default 41943039): +2G

Created a new partition 2 of type 'Linux' and of size 2 GiB.

#打印当前情况
Command (m for help): p
Disk /dev/sdb: 20 GiB, 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
Disklabel type: dos
Disk identifier: 0x127ea212

Device     Boot   Start     End Sectors Size Id Type
/dev/sdb2       4196352 8390655 4194304   2G 83 Linux
/dev/sdb3          2048 4196351 4194304   2G  5 Extended

Partition table entries are not in disk order.

#创建新分区
Command (m for help): n
Partition type
   p   primary (1 primary, 1 extended, 2 free)
   l   logical (numbered from 5)
#创建主分区
Select (default p): p
Partition number (1,4, default 1): 4
First sector (8390656-41943039, default 8390656): 
Last sector, +sectors or +size{K,M,G,T,P} (8390656-41943039, default 41943039): +2G

Created a new partition 4 of type 'Linux' and of size 2 GiB.

#创建新分区
Command (m for help): n
Partition type
   p   primary (2 primary, 1 extended, 1 free)
   l   logical (numbered from 5)
#创建逻辑分区
Select (default p): l

Adding logical partition 5
First sector (4096-4196351, default 4096): 
Last sector, +sectors or +size{K,M,G,T,P} (4096-4196351, default 4196351): +100M

Created a new partition 5 of type 'Linux' and of size 100 MiB.

#创建新分区
Command (m for help): n
Partition type
   p   primary (2 primary, 1 extended, 1 free)
   l   logical (numbered from 5)
#创建逻辑分区
Select (default p): l

Adding logical partition 6
First sector (210944-4196351, default 210944): 
Last sector, +sectors or +size{K,M,G,T,P} (210944-4196351, default 4196351): +200M

Created a new partition 6 of type 'Linux' and of size 200 MiB.

#打印当前情况
Command (m for help): p
Disk /dev/sdb: 20 GiB, 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
Disklabel type: dos
Disk identifier: 0x127ea212

Device     Boot   Start      End Sectors  Size Id Type
/dev/sdb2       4196352  8390655 4194304    2G 83 Linux
/dev/sdb3          2048  4196351 4194304    2G  5 Extended
/dev/sdb4       8390656 12584959 4194304    2G 83 Linux
/dev/sdb5          4096   208895  204800  100M 83 Linux
/dev/sdb6        210944   620543  409600  200M 83 Linux

Partition table entries are not in disk order.

#创建新分区
Command (m for help): n
Partition type
   p   primary (2 primary, 1 extended, 1 free)
   l   logical (numbered from 5)
#创建主分区
Select (default p): p

Selected partition 1
First sector (12584960-41943039, default 12584960): 
Last sector, +sectors or +size{K,M,G,T,P} (12584960-41943039, default 41943039): +2G

Created a new partition 1 of type 'Linux' and of size 2 GiB.

#打印当前情况
Command (m for help): p
Disk /dev/sdb: 20 GiB, 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
Disklabel type: dos
Disk identifier: 0x127ea212

Device     Boot    Start      End Sectors  Size Id Type
/dev/sdb1       12584960 16779263 4194304    2G 83 Linux        #4
/dev/sdb2        4196352  8390655 4194304    2G 83 Linux        #2
/dev/sdb3           2048  4196351 4194304    2G  5 Extended     #1
/dev/sdb4        8390656 12584959 4194304    2G 83 Linux        #3
/dev/sdb5           4096   208895  204800  100M 83 Linux        #1-1
/dev/sdb6         210944   620543  409600  200M 83 Linux        #1-2

Partition table entries are not in disk order.

#保存退出
Command (m for help):w

gdisk创建分区和以上类似

对现有磁盘进行分区之后不同步的问题

#除CentOS6以外
partprobe

#CentOS6(增加用a,删除用d)
partx -a /dev/sda

非交互式创建分区

echo -e 'n\np\n\n+2G\nw\n'|fdisk /dev/sdc
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容