天天看點

parted磁盤分區與GPT

parted磁盤分區方式:通常我們用的比較多的一般都是fdisk工具來進行分區,但是現在由于磁盤越來越

廉價,而且磁盤空間越來越大;而fdisk工具他對分區是有大小限制的,它隻能劃分小于2T的磁盤。但是

現在的磁盤空間很多都已經是遠遠大于2T了,甚至達到2.5T和3T,就需要通過Parted工具來實作對GPT磁

盤進行分區操作。

GUID磁碟分割表(GUID Partition Table,縮寫:GPT)其含義為“全局唯一辨別磁盤分區表”,是一

個實體硬碟的分區表的結構布局的标準。它是可擴充固件接口标準(被Intel用于替代個人計算機的

BIOS)的一部分,被用于替代BIOS系統中的一32bits來存儲邏輯塊位址和大小資訊的主開機紀錄(MBR)

分區表。

  GPT格式的磁盤相當于原來MBR磁盤中原來保留4個partition table的4*16個位元組,隻留第一個16個字

節,類似于擴充分區,真正的partitiontable在512位元組之後,GPT磁盤沒有四個主分區的限制。

parted指令詳解

用法:parted [選項]... [裝置 [指令 [參數]...]...] 

将帶有“參數”的指令應用于“裝置”。如果沒有給出“指令”,則以互動模式運作.  

幫助選項:

-h, --help                    顯示此求助資訊 

-l, --list                    列出所有裝置的分區資訊

-i, --interactive             在必要時,提示使用者 

-s, --script                  從不提示使用者 

-v, --version                 顯示版本

help                    #列印通用求助資訊,或關于 COMMAND 的資訊 

mklabel 标簽類型             #建立新的磁盤标簽 (分區表) 

mkfs  建立檔案系統類型        #在建立類型為“檔案系統類型”的檔案系統 

mkpart 分區類型 [檔案系統類型]    #建立一個分區 

mkpartfs 分區類型 檔案系統類型     #建立一個帶有檔案系統的分區 

move  起始點 終止點           #移動編号為的分區 

name  名稱                  #将編号為的分區命名為“名稱” 

print                       #列印分區表,或者分區 

quit                       #退出程式 

rescue 起始點 終止點             #挽救臨近“起始點”、“終止點”的遺失的分區 

resize  起始點 終止點           #改變位于編号為的分區中檔案系統的大小 

rm                         #删除編号為 MINOR 的分區 

select 裝置                   #選擇要編輯的裝置 

set标志 狀态                  #改變編号為的分區的标志

操作:

1、使用方法

  1.1 進入Parted的方法(在指令行輸入Parted指令即可)

[[email protected] /]# parted
GNU Parted 2.1
Using /dev/sda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted)      

  1.2 擷取parted工具幫助的方法:(隻需輸入help即可)

(parted) help                                                             
  align-check TYPE N                        check partition N for TYPE(min|opt) alignment
  check NUMBER                             do a simple check on the file system
  cp [FROM-DEVICE] FROM-NUMBER TO-NUMBER   copy file system to another partition
  help [COMMAND]                           print general help, or help on COMMAND
  mklabel,mktable LABEL-TYPE               create a new disklabel (partition table)      

…………

OPTIONs:
  -h, --help displays this help message
  -i, --interactive where necessary, prompts for userintervention
  -l, --list lists partition tables ofall detected devices
  -s, --script never prompts for userintervention
  -v, --version displays the version      

…………

   -h, --help                    顯示此求助資訊 

   -l, --list                    列出所有裝置的分區資訊

   -i, --interactive             在必要時,提示使用者 

   -s, --script                  從不提示使用者 

   -v, --version                 顯示版本

   此處與fdisk基本一緻,都是在指令菜單内部,輸入指令

  1.3 退出parted工具(隻需輸入quit即可)

(parted) quit                                                             
[[email protected] /]#      

2、通過parted工具對磁盤進行操作

  2.1檢視單個磁盤狀态 parted /dev/sdc(我用的是額外新增的一塊硬碟c)

[[email protected] ~]# ll /dev
......
brw-rw---- 1 root disk      8,   0 Mar 13 21:13 sda
brw-rw---- 1 root disk      8,   1 Mar 13 21:13 sda1
brw-rw---- 1 root disk      8,   2 Mar 13 21:13 sda2
brw-rw---- 1 root disk      8,  16 Mar 13 21:15 sdb
brw-rw---- 1 root disk      8,  17 Mar 13 21:13 sdb1
brw-rw---- 1 root disk      8,  18 Mar 13 21:13 sdb2
brw-rw---- 1 root disk      8,  19 Mar 13 21:13 sdb3
brw-rw---- 1 root disk      8,  20 Mar 13 21:13 sdb4
brw-rw---- 1 root disk      8,  21 Mar 13 21:13 sdb5
brw-rw---- 1 root disk      8,  22 Mar 13 21:13 sdb6
brw-rw---- 1 root disk      8,  32 Mar 13 21:13 sdc
......      
[[email protected] ~]# parted /dev/sdc
GNU Parted 2.1
Using /dev/sdc
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted)      

 2.2退出再執行:parted -l,可列出所有磁盤的狀态

[[email protected] ~]# parted -l
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sda: 129GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos

Number  Start   End     Size    Type     File system  Flags
 1      1049kB  211MB   210MB   primary  ext4         boot
 2      211MB   64.6GB  64.4GB  primary               lvm


Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 53.7GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos

Number  Start   End     Size    Type      File system  Flags
 1      32.3kB  10.7GB  10.7GB  primary
 2      10.7GB  21.5GB  10.7GB  primary      

  2.3通過parted工具來建立大于2T的分區

[[email protected] ~]# parted /dev/sdc
GNU Parted 2.1
Using /dev/sdc
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted)      

   接着建立磁盤标簽

(parted) mklabel
New disk label type? gpt      #此處設定類型                                       
(parted) p                                                                
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdc: 1095GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt

Number  Start  End  Size  File system  Name  Flags

(parted)      

使用mkpart指令進行分區和設定檔案系統類型

(parted) mkpart
Partition name?  []? gpt2     #名字                                            
File system type?  [ext2]? ext3 #檔案系統類型
Start? 1                         #從哪開始                                         
End? 300G                  到哪結束,可以用大小                                          
(parted) p                 #檢視清單                                               
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdc: 1095GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt

Number  Start   End    Size   File system  Name  Flags
 1      1049kB  300GB  300GB               gpt2      
(parted) Q                                       #退出                         
Information: You may need to update /etc/fstab.  #不要忘記更新/etc/fstab      

通過mkpart指令可以建立多個分區,part1,part2,part3,……

(parted) mkpart                                                           
Partition name?  []? gpt2                                                 
File system type?  [ext2]? ext4                                           
Start? 300G                                                               
End? 600G                                                                 
(parted) mkpart
Partition name?  []? gpt3                                                 
File system type?  [ext2]? ext4                                           
Start? ^C                                                                 
(parted) mkpart                                                           
Partition name?  []? gpt3                                                 
File system type?  [ext2]? xfs                                            
Start? 600                                                                
End? -1                                                                   
Warning: You requested a partition from 600MB to 1095GB.  #仔細                
The closest location we can manage is 600GB to 1095GB.
Is this still acceptable to you?
Yes/No? n                                                                 
(parted) mkpart
Partition name?  []? gpt3                                                 
File system type?  [ext2]? xfs         #建立了一個XFS                                   
Start? 600G                                                               
End? -1                                                                   
(parted) p                                                                
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdc: 1095GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt

Number  Start   End     Size   File system  Name  Flags
 1      1049kB  300GB   300GB               gpt2
 2      300GB   600GB   300GB               gpt2
 3      600GB   1095GB  495GB               gpt3

(parted)                #多分區結束      

通過parted删除分區指令:

Number  Start   End     Size   File system  Name  Flags
 1      1049kB  300GB   300GB               gpt2
 2      300GB   600GB   300GB               gpt2
 3      600GB   1095GB  495GB               gpt3

(parted) rm 3                                                            
(parted) p                                                                
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdc: 1095GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt

Number  Start   End    Size   File system  Name  Flags
 1      1049kB  300GB  300GB               gpt2
 2      300GB   600GB  300GB               gpt2

(parted)      

通過parted工具來建立檔案系統:

(parted) mkfs 2ext3                                                       
WARNING: you are attempting to use parted to operate on (mkfs) a file system.
parted's file system manipulation code is not as robust as what you'll find in
dedicated, file-system-specific packages like e2fsprogs.  We recommend
you use parted only to manipulate partition tables, whenever possible.
Support for performing most operations on most types of file systems
will be removed in an upcoming release.
Warning: The existing file system will be destroyed and all data on the partition will be lost. Do you want to continue?
parted: invalid token: 2ext3
Yes/No? y                                                                 
Partition number? 2                                                       
File system type?  [ext2]? ext3                                           
No Implementation: Support for creating ext3 file systems is not implemented yet.
(parted) mkfs 2ext2                                                       
WARNING: you are attempting to use parted to operate on (mkfs) a file system.
parted's file system manipulation code is not as robust as what you'll find in
dedicated, file-system-specific packages like e2fsprogs.  We recommend
you use parted only to manipulate partition tables, whenever possible.
Support for performing most operations on most types of file systems
will be removed in an upcoming release.
Warning: The existing file system will be destroyed and all data on the partition will be lost. Do you want to continue?
parted: invalid token: 2ext2
Yes/No? y                                                                 
Partition number? 2                                                       
File system type?  [ext2]?      

上面有犯的幾個錯誤,我也列在裡面了,改正

關于挂載同fdisk,實在不願意寫了,用mount umount指令,需要注意的事:第一,需要事先存在的目

錄,第二,此目錄最好以後用不到,第三如果目錄裡面有檔案,可能會被隐藏

注意:比fdisk多了個功能,就是可以恢複删除掉的分區

rm 2
rescue   #可以用來對剛剛删除的分區進行恢複,并且可以把資料一同恢複出來      

check指令的使用:

check 1    #對分區的檢查

(parted) check 1                                                          
WARNING: you are attempting to use parted to operate on (check) a file system.
parted's file system manipulation code is not as robust as what you'll find in
dedicated, file-system-specific packages like e2fsprogs.  We recommend
you use parted only to manipulate partition tables, whenever possible.
Support for performing most operations on most types of file systems
will be removed in an upcoming release.
Error: Could not detect file system.                                      
(parted)      

轉載于:https://blog.51cto.com/123122492/1750687

繼續閱讀