gdisk分区命令

GPT fdisk(由gdisk、cgdisk、sgdisk和fixparts程序组成)是一组用于Linux、FreeBSD、Mac OS X和Windows的文本模式分区工具。gdisk、cgdisk和sgdisk程序在全局惟一标识符(GUID)分区表(GPT)磁盘上工作,而不是在旧的(也是最常见的)主引导记录(MBR)分区表上工作。fixparts程序修复MBR磁盘的某些类型的损坏,并允许将分区类型从主分区更改为逻辑分区,反之亦然。这个命令用来对GPT分区进行操作,请不要在MBR分区上操作,先通过parted /dev/sdb print 命令查看分区表的类型(/dev/sdb换成要操作的磁盘)。

如果相了解更多内容可以查看这个网站:http://www.rodsbooks.com/gdisk/

现在大部分发行版都默认自带了gdisk,如果没有自带自行安装,CentOS7-1810、Debian9.5搜索软件gdisk安装,openSUSE15搜索gptfdisk 安装

一、gdisk参数使用方法:

# gdisk 设备名

使用这个命令前应该先用lsblk命令查看系统上可用的磁盘,因为这个命令不能查看系统上可用的磁盘有那些。
-----------------------------------------------
root@debian:~# gdisk /dev/sdc            #对/dev/sdc进行分区
GPT fdisk (gdisk) version 1.0.1            #GPT fdisk版本

Partition table scan:                  #分区表扫描:
MBR: not present                 #MBR:不存在
BSD: not present                  #BSD:不存在
APM: not present                 #APM:不存在
GPT: not present                  #GPT:不存在

Creating new GPT entries.             #创建新的GPT条目

Command (? for help): ?                 #输入?号查看可用的指令
b   back up GPT data to a file                       #将GPT数据备份到文件中
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)       #创建一个新的空GUID分区表(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                   #查看可用的指令

Command (? for help):

二、gdisk交互模式磁盘分区

1、新建分区

root@debian:~# gdisk /dev/sdc       #对磁盘/dev/sdc进行分区
GPT fdisk (gdisk) version 1.0.1                               #GPT fdisk版本

Partition table scan:
MBR: not present
BSD: not present
APM: not present
GPT: not present

Creating new GPT entries.           #自动创建GPT分区表

Command (? for help): n              #输入n新建分区,默认已经创建了分区表
Partition number (1-128, default 1):     #输入分区号,直接回车就行,默认为1
First sector (34-10485726, default = 2048) or {+-}size{KMGTP}:       #输入起始扇区,直接回车就行,默认2048最前面开始
Last sector (2048-10485726, default = 10485726) or {+-}size{KMGTP}: +1G          #这里输入新增分区的大小可以通过扇区数来增加,也可以通过+size{KMGTP}方式来增加,这里要增加1G的容量就表示为+1G
Current type is 'Linux filesystem'
Hex code or GUID (L to show codes, Enter = 8300):               #这里要求输入分区的类型,直接回车就行,也可以输入l回车查看所有分区的类型
Changed type of partition to 'Linux filesystem'

2、查看剩余可用的空间等信息

Command (? for help): p                     #输入p查看创建的分区
Disk /dev/sdc: 10485760 sectors, 5.0 GiB         #磁盘总容量
Logical sector size: 512 bytes
Disk identifier (GUID): AC08E842-007B-4604-9545-B0BFF427F928 #分区类型为GPT
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 10485726
Partitions will be aligned on 2048-sector boundaries
Total free space is 8388541 sectors (4.0 GiB)          #磁盘可用剩余空间

Number    Start (sector)   End (sector)    Size      Code    Name
1        2048       2099199    1024.0 MiB   8300    Linux filesystem        #已经创建的分区


3、删除分区

Command (? for help): d        #输入d删除分区
Partition number (1-2): 2       #删除分区2

4、修改分区类型

Command (? for help):  l

#回车可以查看更多的信息,其中8200为Linux swap分区、8300为Linux分区、8e00为LinuxLVM分区

Command (? for help): t        #输入t更改分区类型,这里输入l也可以查看分区的类型
Partition number (1-2): 2      #输入要更改的分区
Current type is 'Linux filesystem'
Hex code or GUID (L to show codes, Enter = 8300): 8e00     #输入分区类型的编号
Changed type of partition to 'Linux LVM'               #更改成功

Command (? for help): p
Disk /dev/sdc: 10485760 sectors, 5.0 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): 170FC283-67F2-4188-A687-6882B68F3C3C
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 10485726
Partitions will be aligned on 2048-sector boundaries
Total free space is 8388540 sectors (4.0 GiB)

Number    Start (sector)    End (sector)    Size        Code    Name
1        2048       2099199     1024.0 MiB    8300    Linux filesystem
2        2099200      2099200      512 bytes       8E00    Linux LVM       #更改成功

Command (? for help):

5、更改分区名称

 

Command (? for help): c                             #输入c更改分区名称
Partition number (1-2): 2                            #输入要更改的分区
Enter name: pv1 LVM                                    #输入更改后的名称

 

Command (? for help): p
Disk /dev/sdc: 10485760 sectors, 5.0 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): 170FC283-67F2-4188-A687-6882B68F3C3C
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 10485726
Partitions will be aligned on 2048-sector boundaries
Total free space is 8388540 sectors (4.0 GiB)

 

Number    Start (sector)   End (sector)    Size      Code    Name
1       2048        2099199     1024.0 MiB   8300    Linux filesystem
2       2099200       2099200      512 bytes     8E00    pv1 LVM                       #分区名称已经更改

 

Command (? for help):

 


6、保存修改的结果

Command (? for help): w          #输入w保存配置,如果不想保存可以输入q退出

Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!

Do you want to proceed? (Y/N): y              #问你是否相想继续,输入y继续
OK; writing new GUID partition table (GPT) to /dev/sdc.
The operation has completed successfully.         #写入成功
root@debian:~#

  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值