parted分區詳解 查看UUID兩種方式 blkid 和 ls -l /dev/disk/by-uuid

 

一般咱們用的比較多的通常都是fdisk工具來進行分區,可是如今因爲磁盤愈來愈廉價,並且磁盤空間愈來愈大;而fdisk工具他對分區是有大小限制的,它只能劃分小於2T的磁盤。可是如今的磁盤空間不少都已是遠遠大於2T了,甚至達到2.5T和3T,那要怎麼辦能,有兩個方法,其一是經過卷管理來實現,其二就是經過咱們今天談到的Parted工具來實現對GPT磁盤進行分區操做。app

 

GPT格式的磁盤至關於原來MBR磁盤中原來保留4partition table4*16個字節,只留第一個16個字節,相似於擴展分區,真正的partitiontable512字節以後,GPT磁盤沒有四個主分區的限制。工具

 

 

 

一、            Parted工具詳解:oop

 

1.1    進入Parted的方法(在命令行輸入Parted命令便可)ui

 

[root@jetsen ~]# partetthis

 

Warning: Unable to open/dev/hdc read-write (Read-only file system). /dev/hdc has beenspa

 

opened read-only.命令行

 

GNU Parted 1.8.1orm

 

Using /dev/hdctoken

 

Welcome to GNU Parted! Type'help' to view a list of commands.ip

 

(parted)

 

 

 

1.2    獲取parted工具幫助的方法:(只需輸入help便可)

 

(parted) help                                                            

 

  check NUMBER                             do a simple checkon the file system

 

  cp [FROM-DEVICE] FROM-NUMBER TO-NUMBER   copy file system to another partition

 

  help [COMMAND]                           prints general help,or help on COMMAND

 

  mklabel,mktable LABEL-TYPE               create a new disklabel(partition table)

 

  mkfs NUMBER FS-TYPE                      make a FS-TYPE filesystem on partititon

 

        NUMBER

 

  mkpart PART-TYPE [FS-TYPE] START END     make a partition

 

  mkpartfs PART-TYPE FS-TYPE START END     make a partition with a file system

 

  move NUMBER START END                    move partition NUMBER

 

  name NUMBER NAME                         name partition NUMBERas NAME

 

  print [free|NUMBER|all]                  display the partition table,a partition, or

 

        all devices

 

  quit                                     exit program

 

  rescue START END                         rescue a lostpartition near START and END

 

  resize NUMBER START END                  resize partition NUMBER andits file system

 

  rm NUMBER                                deletepartition NUMBER

 

  select DEVICE                            choose the deviceto edit

 

  set NUMBER FLAG STATE                    change the FLAG onpartition NUMBER

 

  toggle [NUMBER [FLAG]]                   toggle the state of FLAG onpartition NUMBER

 

  unit UNIT                                set the defaultunit to UNIT

 

  version                                  displays thecurrent version of GNU Parted

 

        and copyright information

 

(parted)

 

 

 

 

[root@jetsen ~]# parted--help

 

Usage: parted [OPTION]...[DEVICE [COMMAND [PARAMETERS]...]...]

 

Apply COMMANDs withPARAMETERS to DEVICE.  If no COMMAND(s)are given, run in

 

interactive mode.

 

 

 

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

 

 

 

COMMANDs:

 

  check NUMBER                             do a simple checkon the file system

 

  cp [FROM-DEVICE] FROM-NUMBER TO-NUMBER   copy file system to another partition

 

  help [COMMAND]                           prints general help,or help on COMMAND

 

  mklabel,mktable LABEL-TYPE               create a new disklabel(partition table)

 

  mkfs NUMBER FS-TYPE                      make a FS-TYPE filesystem on partititon NUMBER

 

  mkpart PART-TYPE [FS-TYPE] START END     make a partition

 

  mkpartfs PART-TYPE FS-TYPE START END     make a partition with a file system

 

  move NUMBER START END                    move partition NUMBER

 

  name NUMBER NAME                         name partition NUMBERas NAME

 

  print [free|NUMBER|all]                  display the partition table, apartition, or all devices

 

  quit                                     exitprogram

 

  rescue START END                         rescue a lostpartition near START and END

 

  resize NUMBER START END                  resize partition NUMBER andits file system

 

  rm NUMBER                                deletepartition NUMBER

 

  select DEVICE                            choose the deviceto edit

 

  set NUMBER FLAG STATE                    change the FLAG onpartition NUMBER

 

  toggle [NUMBER [FLAG]]                   toggle the state of FLAG onpartition NUMBER

 

  unit UNIT                                set the defaultunit to UNIT

 

  version                                  displays thecurrent version of GNU Parted and copyright information

 

[root@jetsen ~]#

 

1.3    退出parted工具(只需輸入quit便可)

 

(parted) quit                                                            

 

Information: Don't forget toupdate /etc/fstab, if necessary.                           

 

而且同時會提示及時更新/etc/fstab文件

 

 

 

二、            開始經過parted工具來對磁盤進行操做

 

  2.1 查看單個磁盤狀態

 

[root@jetsen ~]#parted /dev/sdb

 

GNU Parted 1.8.1

 

Using /dev/sdb

 

Welcome to GNUParted! Type 'help' to view a list of commands.

 

(parted) p                                                               

 

 

 

Model: VMware,VMware Virtual S (scsi)

 

Disk /dev/sdb:16.1GB

 

Sector size(logical/physical): 512B/512B

 

Partition Table:msdos

 

 

 

Number  Start  End     Size    Type    File system  Flags

 

 1     32.3kB  16.1GB  16.1GB primary  ext3             

 

 

 

(parted)                                                                  

 

 

 

2.2 查看全部磁盤狀態

 

[root@jetsen ~]#parted -l

 

Warning: Unable toopen /dev/hdc read-write (Read-only file system).  /dev/hdc has been

 

opened read-only.

 

Error: Unable toopen /dev/hdc - unrecognised disk label.                

 

 

 

Model: VMware,VMware Virtual S (scsi)

 

Disk /dev/sda:21.5GB

 

Sector size(logical/physical): 512B/512B

 

Partition Table:msdos

 

 

 

Number  Start  End     Size    Type    File system  Flags

 

 1     32.3kB  107MB   107MB  primary  ext3         boot

 

 2     107MB   21.5GB  21.4GB primary               lvm 

 

 

 

Model: VMware,VMware Virtual S (scsi)

 

Disk /dev/sdb:16.1GB

 

Sector size(logical/physical): 512B/512B

 

Partition Table:msdos

 

 

 

Number  Start  End     Size    Type    File system  Flags

 

 1     32.3kB  16.1GB  16.1GB primary  ext3             

 

 

 

Model: VMware,VMware Virtual S (scsi)

 

Disk /dev/sdc:16.1GB

 

Sector size(logical/physical): 512B/512B

 

Partition Table:loop

 

Number  Start  End     Size    File system Flags

 

 1     0.00kB  16.1GB  16.1GB ext3             

 

 

 

Error: Unable toopen /dev/sdd - unrecognised disk label.                

 

Error: Unable toopen /dev/sde - unrecognised disk label.                

 

Error: Unable toopen /dev/md0 - unrecognised disk label.                

 

  2.2 經過parted工具來建立大於2T的分區

 

[root@jetsen ~]#parted /dev/sde

 

GNU Parted 1.8.1     ---Parted的軟件版本號

 

Using /dev/sde       ---將執行下面操做盤

 

Welcome to GNUParted! Type 'help' to view a list of commands.    –歡迎信息

 

(parted) mklabel                                           ----建立建立磁盤標籤

 

New disk labeltype? gpt

 

(parted) p                                                ----查看分區狀態

 

 

 

Model: VMware,VMware Virtual S (scsi)

 

Disk /dev/sde:2190GB

 

Sector size(logical/physical): 512B/512B

 

Partition Table:gpt

 

 

 

Number  Start End  Size  File system Name  Flags

 

(parted) mkpart

 

Partition name?  []? gpt2t      ---指定分區名稱

 

File system type? [ext2]ext3    ----指定分區類型

 

Start? 1                      ---指定開始位置

 

End? 2190GB                 ---指定結束位置

 

(parted) P                    ----顯示分區信息                                                           

 

 

 

Model: VMware, VMware Virtual S (scsi)

 

Disk /dev/sde: 2190GB

 

Sector size (logical/physical): 512B/512B

 

Partition Table: gpt

 

 

 

Number  Start   End    Size    File system  Name  Flags

 

 1      17.4kB 2190GB  2190GB               gpt2t      

 

 

 

(parted) Q                              ---退出                                                          

 

Information: Don't forget to update /etc/fstab, if necessary.    -----提示不要忘記更新/etc/fstab文件

 

2.3 經過parted工具來實現單磁盤多分區

 

[root@jetsen ~]#parted /dev/sdd

 

GNU Parted 1.8.1

 

Using /dev/sdd

 

Welcome to GNUParted! Type 'help' to view a list of commands.

 

(parted) p                                        ---列出分區信息

 

Error:Unable to open /dev/sdd - unrecognised disk label.  ----因爲沒有打上磁盤標籤,因此表現信息沒法列出

 

(parted)mklabel                                   ----建立磁盤標籤

 

New disk labeltype? gpt                             ---輸入磁盤表情名

 

(parted) p                                        ----再次列出磁盤分區

 

 

 

Model: VMware,VMware Virtual S (scsi)               ---顯示磁盤類型爲SCSI磁盤

 

Disk /dev/sdd:1100GB                             ---磁盤大小爲1100GB

 

Sector size(logical/physical): 512B/512B              ---扇區大小爲512B

 

Partition Table:gpt                                ----顯示標籤名爲我剛纔輸入的標籤名稱

 

 

 

Number  Start End  Size  File system Name  Flags  ----如今是一新硬盤尚未建立分區

 

 

 

(parted)mkpart                                   ---建立分區

 

Partitionname?  []? part1                           ---指定分區名稱

 

File systemtype?  [ext2]? ext2                       ---定義分區類型

 

Start? 1G                                         ---指定起始位置

 

End? 10G                                         ----指定終止位置

 

(parted)mkpart                                   ---建立分區

 

Partitionname?  []? part2                           ---指定分區名稱

 

File systemtype?  [ext2]? ext2                       ---定義分區類型

 

Start? 11G                                        ---指定起始位置

 

End? 100G                                       ---指定終止位置

 

(parted)mkpart                                                

 

Partitionname?  []? part3                             

 

File systemtype?  [ext2]?                        

 

Start? 101G                                    ----指定分區其實位置

 

End? -1                                        ----指定到分區最後                          

 

(parted) p                                     ----顯示分區信息

 

 

 

Model: VMware,VMware Virtual S (scsi)           

 

Disk /dev/sdd:1100GB

 

Sector size (logical/physical):512B/512B

 

Partition Table:gpt

 

 

 

Number  Start  End     Size     File system  Name  Flags      ---查看到下面共有三個分區

 

 1     17.4kB  10.0GB  10000MB               part1      

 

 2     10.0GB  100GB   90.0GB                part2      

 

 3     100GB   1100GB  1000GB                part3      

 

 

 

(parted) rm 3                                     ------刪除分區3

 

(parted) p                                        ------再次查看分區狀態                       

 

 

 

Model: VMware,VMware Virtual S (scsi)

 

Disk /dev/sdd:1100GB

 

Sector size(logical/physical): 512B/512B

 

Partition Table:gpt

 

 

 

Number  Start  End     Size     File system  Name  Flags      ----顯示分區刪除成功,只剩下兩個分區

 

 1     17.4kB  10.0GB  10000MB               part1      

 

 2     10.0GB  100GB   90.0GB                part2      

 

 

 

(parted) quit                                                            

 

Information: Don'tforget to update /etc/fstab, if necessary.            

 

 

 

[root@jetsen ~]#ls -l /dev/sdd*

 

brw-r----- 1 rootdisk 8, 48 May 10 16:48 /dev/sdd

 

brw-r----- 1 rootdisk 8, 49 May 10 16:48 /dev/sdd1

 

brw-r----- 1 rootdisk 8, 50 May 10 16:48 /dev/sdd2

 

[root@jetsen ~]#

 

  2.3 經過parted工具來刪除分區

 

[root@jetsen ~]# parted /dev/sde

 

GNU Parted 1.8.1

 

Using /dev/sde

 

Welcome to GNU Parted! Type 'help' to view a list of commands.

 

(parted) p                                                               

 

Model: VMware, VMware Virtual S (scsi)

 

Disk /dev/sde: 2190GB

 

Sector size (logical/physical): 512B/512B

 

Partition Table: gpt

 

 

 

Number  Start   End    Size    File system  Name  Flags

 

 1      17.4kB 2190GB  2190GB               gpt2t      

 

 

 

(parted) rm 1            ----刪除分1號分區                                                         

 

(parted) p              ----顯示分區信息,看以下是沒有分區的                                                  

 

Model: VMware, VMware Virtual S (scsi)

 

Disk /dev/sde: 2190GB

 

Sector size (logical/physical): 512B/512B

 

Partition Table: gpt

 

 

 

Number  Start  End Size  File system  Name Flags

 

 

 

(parted) q                                                               

 

Information: Don't forget to update /etc/fstab, if necessary.            

 

[root@jetsen ~]#

 

  2.4 經過parted工具來建立文件系統

 

[root@jetsen ~]#parted /dev/sdd                         -----選擇要格式化的磁盤

 

GNU Parted 1.8.1

 

Using /dev/sdd

 

Welcome to GNUParted! Type 'help' to view a list of commands.

 

(parted) mkfs 2ext3                                   ----格式化的類型爲ext3分區號爲2-

 

Warning: Theexisting file system will be destroyed and all data on the partition will

 

be lost. Do youwant to continue?

 

parted: invalidtoken: 2

 

Yes/No? yes                                          ----再次確認是否格式化

 

Partition number?2                                   -----再次輸入磁盤分區號                   

 

File system?  [ext2]?                                  ----格式化的類型

 

(parted)                                                               

 

查看格式化是否成功:

 

(parted) p                                           -----查看文件系統是否被格式化

 

Model: VMware,VMware Virtual S (scsi)

 

Disk /dev/sdd:1100GB

 

Sector size(logical/physical): 512B/512B

 

Partition Table:gpt

 

 

 

Number  Start  End     Size     File system  Name  Flags

 

 1     17.4kB  10.0GB  10000MB               part1      

 

 2     10.0GB  100GB   90.0GB  ext2         part2       -------能夠看到文件系統類型爲ext2,可肯定文件系統已經被格式化了。

 

 

 

(parted)    

 

掛載剛纔格式化後的文件系統

 

[root@jetsen ~]#cd /                                         -----退到根目錄

 

[root@jetsen /]#mkdir part2                                  -----建立part目錄

 

[root@jetsen /]#mount /dev/sdd2 /part2                        -----將/dev/sdd2掛載到/part2

 

[root@jetsen /]#df –h                                         -----查看分區信息

 

Filesystem            Size  Used Avail Use% Mounted on

 

/dev/mapper/VolGroup00-LogVol00

 

                       18G  5.8G  11G  35% /

 

/dev/sda1              99M   12M  82M  13% /boot

 

tmpfs                 506M  4.0K 506M   1% /dev/shm

 

/dev/sdd2             83G  52K   79G   1% /part2       ------能夠看到已經被掛載上來              

 

[root@jetsen /]#cd /part2

 

[root@jetsenpart2]# mkdir 1111                              ------而且能夠訪問

 

[root@jetsenpart2]# ls

 

1111  lost+found

 

[root@jetsen part2]#

 

刪除和恢復分區

 

[root@jetsen /]#umount /dev/sdd2                     ----卸載分區

 

[root@jetsen /]#parted /dev/sdd                       ---經過parted選擇/dev/sdd磁盤進入操做

 

GNU Parted 1.8.1

 

Using /dev/sdd

 

Welcome to GNUParted! Type 'help' to view a list of commands.

 

(parted) rm 2                                      ------刪除磁盤分區

 

(parted) rescue                        -------對磁盤分區進行恢復

 

Start? 10G                                                               

 

End? 100G                                                                

 

Information: A ext2 primary partitionwas found at 10.0GB -> 100GB. Do youwant to add

 

it to the partition table?

 

Yes/No/Cancel? Yes                    ----告訴

 

(parted) print                                                           

 

 

 

Model: VMware, VMware Virtual S (scsi)

 

Disk /dev/sdd: 1100GB

 

Sector size (logical/physical):512B/512B

 

Partition Table: gpt

 

 

 

Number Start   End     Size    File system  Name   Flags

 

 1     17.4kB  10.0GB  10000MB               part1      

 

 2     10.0GB  100GB   90.0GB  ext2                    

 

 

 

(parted)

 

[root@jetsen/]# cd /part2                           ----神奇吧,數據也被恢復回來了

 

[root@jetsenpart2]# ls

 

1111  lost+found                                                          

 

 

 

  2.6 經過parted工具來驗證和維護文件系統及分區。

 

驗證文件系統的完整性:

 

(parted)check 1                                                         

 

Error:File system was not cleanly unmounted! You should run e2fsck.  Modifyingan

 

uncleanfile system could cause severe corruption.

 

Ignore/Cancel?ignore                                                     

 

Information:The ext2 file system passed a basic check. For a more comprehensive check,

 

use thee2fsck program.

 

(parted)        

相關文章
相關標籤/搜索