二、让我们来一起见识见识Linux下3款分区工具的能力吧。
老当益壮fdisk。
fdisk在linux是一款非常老的分区工具了,工具虽然老,但是简单便利是fdisk的优点,当然gdisk也继承了这一优点,他们的功能非常相似,不过fdisk工具主要用来对MBR模式的硬盘进行分区,gdisk工具用来对GPT模式的硬盘进行分区,这里就讲一款fdisk工具。fdisk不能对2T以上的磁盘进行分区,是因为MBR模式不支持2T以上的分区格式。
fdisk、gdisk工具
fdisk /dev/sdb
fdisk -l [-u] [device...] 查看硬盘及分区的信息
常用的子命令:
m 帮助列表
p 分区列表
l 查看分区类型
t 更改分区类型
n 创建新分区
d 删除分区
w 保存并退出
fdisk分区后,操作只是在内存中并未真正的对硬盘分区,如果真的需要分区w保存即可
q 不保存并退出
当然如果你后悔了,输入q则不会保存之前的操作
选项介绍完,我来给大家做一个实验。让大家了解一下这款工具的使用方式。
[root@TianRandai ~]#fdisk /dev/sdb #对/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.
Command (m for help): n #建立一个分区
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p #分区类型为主分区,p是主分区,e是扩展分区
Partition number (1-4, default 1): 1 #指定分区号
First sector (2048-41943039, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039): +2G
Partition 1 of type Linux and of size 2 GiB is set
Command (m for help): t #指定分区标记类型
Selected partition 1
Hex code (type L to list all codes): 82
Changed type of partition 'Linux' to 'Linux swap / Solaris'
Command (m for help): w #保存操作
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@TianRandai ~]#parted /dev/sdb mklabel gpt #指定磁盘模式为GPT
Warning: The existing disk label on /dev/sdb will be destroyed and all data on this disk
will be lost. Do you want to continue?
Yes/No? yes
Information: You may need to update /etc/fstab.
[root@TianRandai ~]#parted /dev/sdb mkpart primary 0 2G #创建分区,分区类型为主分区,大小为2G
Warning: The resulting partition is not properly aligned for best performance.
Ignore/Cancel? i
Information: You may need to update /etc/fstab.
[root@TianRandai ~]#parted /dev/sdb print #查看磁盘信息
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
1 17.4kB 2000MB 2000MB primary
[root@TianRandai ~]#parted /dev/sdb rm 1 #删除分区1
Information: You may need to update /etc/fstab.
[root@TianRandai ~]#parted /dev/sdb print #再次查看磁盘信息
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags