天天看點

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

gdisk分區指令

#回車可以檢視更多的資訊,其中8200為Linux swap分區、8300為Linux分區、8e00為LinuxLVM分區

Command (? for help): t        #輸入t更改分區類型,這裡輸入l也可以檢視分區的類型

Partition number (1-2): 2      #輸入要更改的分區

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

Disk identifier (GUID): 170FC283-67F2-4188-A687-6882B68F3C3C

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       #更改成功

5、更改分區名稱

Command (? for help): c                             #輸入c更改分區名稱

Partition number (1-2): 2                            #輸入要更改的分區

Enter name: pv1 LVM                                    #輸入更改後的名稱

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                       #分區名稱已經更改

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

繼續閱讀