分區管理工具-gdisk命令實戰案例


          分區管理工具-gdisk命令實戰案例

                              作者:尹正傑 

版權聲明:原創作品,謝絕轉載!否則將追究法律責任。

 

 

  gdisk工具擅長管理GPT分區。接下來我們就簡單介紹一下該工具的使用。

 

一.分區表概述

  博主推薦閱讀:
    https://www.cnblogs.com/yinzhengjie/p/12347792.html

 

二.安裝gdisk

  gdisk工具和fdisk很類似,都是對磁盤進行分區管理的開源工具。如下圖所示,fdisk對於GPT分區方式目前只是實驗性的,因此生成環境建議大家謹慎使用。

  我們的gdisk工具很擅長處理GPT分區方式,不僅如此還支持MBR以及APM和BSD分區方式(雖說后兩者分區方式使用相對較少,感興趣的同學可以自行查閱相關資料)。

  綜上所述,如果生產環境您使用GPT分區推薦使用gdisk工具,最小化安裝的系統需要手動安裝喲~
[root@yinzhengjie.com ~]# yum -y install gdisk
Loaded plugins: fastestmirror
Determining fastest mirrors
 * base: mirror.bit.edu.cn
 * extras: mirrors.bfsu.edu.cn
 * updates: mirror.bit.edu.cn
base                                                                                                                                                 | 3.6 kB  00:00:00     
extras                                                                                                                                               | 2.9 kB  00:00:00     
updates                                                                                                                                              | 2.9 kB  00:00:00     
(1/4): updates/7/x86_64/primary_db                                                                                                                   | 168 kB  00:00:00     
(2/4): extras/7/x86_64/primary_db                                                                                                                    | 190 kB  00:00:00     
(3/4): base/7/x86_64/group_gz                                                                                                                        | 153 kB  00:00:01     
(4/4): base/7/x86_64/primary_db                                                                                                                      | 6.1 MB  00:00:03     
Resolving Dependencies
--> Running transaction check
---> Package gdisk.x86_64 0:0.8.10-3.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

============================================================================================================================================================================
 Package                                Arch                                    Version                                         Repository                             Size
============================================================================================================================================================================
Installing:
 gdisk                                  x86_64                                  0.8.10-3.el7                                    base                                  190 k

Transaction Summary
============================================================================================================================================================================
Install  1 Package

Total download size: 190 k
Installed size: 660 k
Downloading packages:
gdisk-0.8.10-3.el7.x86_64.rpm                                                                                                                        | 190 kB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : gdisk-0.8.10-3.el7.x86_64                                                                                                                                1/1 
  Verifying  : gdisk-0.8.10-3.el7.x86_64                                                                                                                                1/1 

Installed:
  gdisk.x86_64 0:0.8.10-3.el7                                                                                                                                               

Complete!
[root@yinzhengjie.com ~]# 
[root@yinzhengjie.com ~]# yum -y install gdisk          #安裝gdisk工具

 

三.gdisk工具使用案例

[root@yinzhengjie.com ~]# gdisk /dev/sdc         #進入到gdisk工具的管理界面
GPT fdisk (gdisk) version 0.8.10

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

Creating new GPT entries.

Command (? for help): 

1>.查看幫助信息

Command (? for help): ?
b    back up GPT data to a file
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)
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): 

2>.新建分區

Command (? for help): n                #執行新建分區的指令
Partition number (1-128, default 1): 
First sector (34-838860766, default = 2048) or {+-}size{KMGTP}: 
Last sector (2048-838860766, default = 838860766) or {+-}size{KMGTP}: +100G        #這里的結束位置我這里寫+100G
Current type is 'Linux filesystem'
Hex code or GUID (L to show codes, Enter = 8300):       #我們可以自定義創建分區的代碼(默認是8300),輸入字母"l"可以查看所有的代碼標簽喲~通常情況下我們直接回車即可。
Changed type of partition to 'Linux filesystem'

Command (? for help): 

3>.查看分區信息

Command (? for help): p
Disk /dev/sdc: 838860800 sectors, 400.0 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): 37B1331C-C436-48CA-B5A6-B157D0BB9AD0
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 838860766
Partitions will be aligned on 2048-sector boundaries
Total free space is 629145533 sectors (300.0 GiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048       209717247   100.0 GiB   8300  Linux filesystem

Command (? for help): 

4>.保存分區信息並退出

Command (? for help): w            #保存分區信息到磁盤(默認所有的修改都放在內存中,直到執行當前的寫入指令才會寫入到磁盤。)

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@yinzhengjie.com ~]# 

5>.命令行中查看gpt的分區信息

[root@yinzhengjie.com ~]# gdisk -l /dev/sdc
GPT fdisk (gdisk) version 0.8.10

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

Found valid GPT with protective MBR; using GPT.
Disk /dev/sdc: 838860800 sectors, 400.0 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): C4A5426E-BE89-46EE-B842-3CAC96156388
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 838860766
Partitions will be aligned on 2048-sector boundaries
Total free space is 629145533 sectors (300.0 GiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048       209717247   100.0 GiB   8300  Linux filesystem
[root@yinzhengjie.com ~]# 
[root@yinzhengjie.com ~]# fdisk -l /dev/sdc
WARNING: fdisk GPT support is currently new, and therefore in an experimental phase. Use at your own discretion.

Disk /dev/sdc: 429.5 GB, 429496729600 bytes, 838860800 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: gpt
Disk identifier: C4A5426E-BE89-46EE-B842-3CAC96156388


#         Start          End    Size  Type            Name
 1         2048    209717247    100G  Linux filesyste Linux filesystem
[root@yinzhengjie.com ~]# 
[root@yinzhengjie.com ~]# 
[root@yinzhengjie.com ~]# fdisk -l /dev/sdc          #對於GPT分區的磁盤雖然也可以使用fdisk工具查看,但還是推薦大家使用gdisk去管理GPT分區。

 


免責聲明!

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



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