CentOS Linux下的3款分区工具详解

2020-01-30 17:33:10于丽

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.

 

强大的分区工具parted

parted

parted工具的分区是即时操作的,所以分区的时候要小心慎用,因为可能一个不小心就把再用的硬盘给分区了,所以使用时,一定要谨慎谨慎再谨慎。

用法:parted [选项]... [设备[命令[参数]...]...]

parted /dev/sdb mklabel gpt|msdos 为磁盘指定模式

parted /dev/sdb print   显示磁盘信息

parted /dev/sdb mkpart primary/extended/logical 0 200 (默认M)创建分区类型及大小

parted /dev/sdb rm 1  删除分区

parted -l   显示所有磁盘的信息

选项介绍完,我来给大家做一个实验。让大家了解一下这款工具的使用方式。


[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