用
fdisk
管理分区
fdisk
命令工具默认将磁盘划分为
mbr
格式的分区
命令:
fdisk
设备名
fdisk
命令以交互方式进行操作的,在菜单中选择相应功能键即可

[root@localhost ~]# fdisk /dev/sda
#
对
sda
进行分区
Command (m for help):
#
进入
fdisk
交互界面进行分区
Command (m for help): m
#
输入
m
可查看帮助信息
Help:
DOS (MBR)
a toggle a bootable flag
b edit nested BSD disklabel
c toggle the dos compatibility flag
Generic
d delete a partition
F list free unpartitioned space
l list known partition types
n add a new partition
p print the partition table
t change a partition type
v verify the partition table
i print information about a partition
Misc
m print this menu
u change display/entry units
x extra functionality (experts only)
Script
I load disk layout from sfdisk script file
O dump disk layout to sfdisk script file
Save & Exit
w write table to disk and exit
q quit without saving changes
Create a new label
g create a new empty GPT partition table
G create a new empty SGI (IRIX) partition table
o create a new empty DOS partition table
s create a new empty Sun partition table
Command (m for help): n
#
输入
n
创建新分区
Partition type
p primary (0 primary, 0 extended, 4 free)
#
输入
p
创建主分区
e extended (container for logical partitions)
#
输入
e
创建扩展分区
Select (default p): p
#
输入
p
创建主分区
Partition number (1-4, default 1): 1
#
选择主分区号,输入
1
表示第一个主分区
First sector (2048-10485759, default 2048):
#
直接按回车从当前第
2048
个扇区开始分区
Last sector, +sectors or +size{K,M,G,T,P} (2048-10485759, default 10485759): +300M
#
设置第一个分区为
300M
Created a new partition 1 of type 'Linux' and of size 300 MiB.
#
一个主分区创建完成,大小为
300M
Command (m for help): p
#
输入
p
查看分区信息
Disk /dev/sda: 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: 0x5bb0744f
Device Boot Start End Sectors Size Id Type
/dev/sda1 2048 616447 614400 300M 83 Linux
Device Boot Start End Sectors Size Id Type
/dev/sda1 2048 616447 614400 300M 83 Linux
/dev/sda2 616448 10485759 9869312 4.7G 0 Empty
#
有两个分区,其中新添加的
sda2
有误,需要删除
Command (m for help): d
#
输入
d
删除分区
Partition number (1,2, default 2): 2
#
输入
2
,选择需要删除的是第二个分区
Partition 2 has been deleted.
Command (m for help): p
Disk /dev/sda: 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: 0x5bb0744f
Device Boot Start End Sectors Size Id Type
/dev/sda1 2048 616447 614400 300M 83 Linux
#
查看现有分区,有误的
sda2
已删除
#
创建一个扩展分区
Command (m for help): n
#
输入
n
创建新分区
Partition type
p primary (1 primary, 0 extended, 3 free)
e extended (container for logical partitions)
Select (default p): e
#
输入
e
创建扩展分区
Partition number (2-4, default 2): 2
#
选择分区号,输入
2
表示第二个分区
First sector (616448-10485759, default 616448):
#
直接按回车从当前第
616448
个扇区开始分区
Last sector, +sectors or +size{K,M,G,T,P} (616448-10485759, default 10485759): +500M
#
添加一个
500M
的分区
Created a new partition 2 of type 'Extended' and of size 500 MiB.
Command (m for help): p
Disk /dev/sda: 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: 0x5bb0744f
Device Boot Start End Sectors Size Id Type
/dev/sda1 2048 616447 614400 300M 83 Linux
/dev/sda2 616448 1640447 1024000 500M 5 Extended
#
输入
p
查看,新增一个
500M
的扩展分区
Command (m for help): w
#
所有分区设置完成后,输入
w
保存,即可退出
fdisk
交互界面
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
使用
gdisk
管理分区
gdisk
命令工具默认将磁盘划分为
GPT
格式的分区
[root@localhost ~]# gdisk /dev/sda
#
进入
gdisk
交互界面
GPT fdisk (gdisk) version 1.0.3
Partition table scan:
MBR: MBR only
BSD: not present
APM: not present
GPT: not present
Command (? for help): ?
#
输入
?
可查看帮助信息
b
back up GPT data to a file
c
change a partition's name
d
delete a partition
i
show detailed information on a partition
l
list known partition types
n
add a new partition
o
create a new empty GUID partition table (GPT)
p
print the partition table
q
quit without saving changes
r
recovery and transformation options (experts only)
s
sort partitions
t
change a partition's type code
v
verify disk
w
write table to disk and exit
x
extra functionality (experts only)
?
print this menu
#gdisk
创建新分区(默认
GPT
格式)
Command (? for help): n
#
输入
n
创建新分区
Partition number (1-128, default 1):
#
输入分区编号,默认为
1
,因为是
/dev/sda
硬盘的第一块分区
First sector (34-10485726, default = 2048) or {+-}size{KMGTP}: #
输入扇区的开始位置,选择默认即
可,也可手动指定
Last sector (2048-10485726, default = 10485726) or {+-}size{KMGTP}: +300M
#
输
入扇区的结束位置,一般都是指定磁盘大小,这里输入
+300M
表示新分区大小为
300M
Current type is 'Linux filesystem'
Hex code or GUID (L to show codes, Enter = 8300):
#
默认即可,分区完成后可以修改
Changed type of partition to 'Linux filesystem'
Command (? for help): p
#
输入
p
查看分区情况
Disk /dev/sda: 10485760 sectors, 5.0 GiB
Model: VMware Virtual S
Sector size (logical/physical): 512/512 bytes
Disk identifier (GUID): 61FA16FB-FAD8-4873-A857-BD387FE0A592
Partition table holds up to 128 entries
Main partition table begins at sector 2 and ends at sector 33
First usable sector is 34, last usable sector is 10485726
Partitions will be aligned on 2048-sector boundaries
Total free space is 9871293 sectors (4.7 GiB)
Number Start (sector) End (sector) Size Code Name
1 2048 616447 300.0 MiB 8300 Linux filesystem
Command (? for help): w
#
输入
w
保存分区并退出
gdisk
交互界面
Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING PARTITIONS!!
Do you want to proceed? (Y/N): y
OK; writing new GUID partition table (GPT) to /dev/sda.
The operation has completed successfully.