[root@localhost ~]# fdisk -l [root@localhost ~]# fdisk /dev/sdb Command (m forhelp): m #输入m列出常用的命令 Command action a toggle a bootable flag #切换分区启动标记 b edit bsd disklabel #编辑sdb磁盘标签 c toggle the dos compatibility flag #切换dos兼容模式 d delete a partition #删除分区 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 #创建新的Sun磁盘标签 t change a partitions system id #修改分区ID,可以通过l查看id u change display/entry units #修改容量单位,磁柱或扇区 v verify the partition table #检验分区表 w write table to disk and exit#保存退出 x extra functionality (experts only) #拓展功能
1). fdisk创建主分区
1 2 3 4 5 6 7 8 9
Command (m forhelp): 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-2097151, default 2048): #默认扇区回车 Using default value 2048 Last sector, +sectors or +size{K,M,G} (2048-2097151, default 2097151): +50M #分配50MB
2). fdisk创建扩展分区
1 2 3 4 5 6 7 8 9
Command (m forhelp): n #新建分区 Partition type: p primary (1 primary, 0 extended, 3 free) e extended Select (default p): e #创建扩展分区 Partition number (2-4, default 2): First sector (104448-2097151, default 104448): Using default value 104448 Last sector, +sectors or +size{K,M,G} (104448-2097151, default 2097151): #空间都给到扩展分区
3). fdisk创建逻辑分区
1 2 3 4 5 6 7 8 9
Command (m forhelp): 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 (106496-2097151, default 106496): Using default value 106496 Last sector, +sectors or +size{K,M,G} (106496-2097151, default 2097151): +100M #分配100MB空间
4). fdisk查看分区情况,并保存
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
Command (m forhelp): p #查看分区创建 Device Boot Start End Blocks Id System /dev/sdb1 2048 104447 51200 83 Linux /dev/sdb2 104448 2097151 996352 5 Extended /dev/sdb5 106496 311295 102400 83 Linux
#保存分区 Command (m forhelp): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks.
#检查磁盘是否是MBR分区方式 [root@localhost ~]# fdisk /dev/sdb -l|grep type Disk label type: dos
#2.创建一个新分区,500MB大小 [root@localhost ~]# gdisk /dev/sdb Command (? forhelp): n #创建新分区 Partition number (1-128, default 1): First sector (34-2097118, default = 2048) or {+-}size{KMGTP}: Last sector (2048-2097118, default = 2097118) or {+-}size{KMGTP}: +500M #分配500M大小
Command (? forhelp): p #打印查看 Number Start (sector) End (sector) Size Code Name 1 2048 1026047 500.0 MiB 8300 Linux filesystem
Command (? forhelp): w #保存分区 Do you want to proceed? (Y/N): y #确认 OK; writing new GUID partition table (GPT) to /dev/sdb. The operation has completed successfully.
#3.创建完成后,可以尝试检查磁盘是否为gpt格式 [root@localhost-node1 /]# fdisk /dev/sdb -l|grep type Disk label type: gpt
#3.umount不能卸载的情况 [root@localhost db1]# umount /db1 umount: /db1: device is busy. (In some cases useful info about processes that use the device is found by lsof(8) or fuser(1)