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:~#

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM