磁盘分区-gdisk用法

前端之家收集整理的这篇文章主要介绍了磁盘分区-gdisk用法前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

gdisk用法

 

gdisk - InteractiveGUIDpartitiontable (GPT) manipulator

GPTfdisk (akagdisk) isatext-modemenu-drivenprogramforcreationandmanipulation

ofpartitiontables.

1 使用gdisk的原因

1)由于fdisk命令不能很好的支持GPT分区

  1. [root@local ~]# fdisk /dev/sdb
  2. WARNING: fdiskGPTsupportiscurrentlynew,andthereforeinanexperimentalphase. Useatyourowndiscretion.
  3. Welcometofdisk (util-linux 2.23.2).
  4.  
  5.  
  6. Changeswillremaininmemoryonly,untilyoudecidetowritethem.
  7. Becarefulbeforeusingthewritecommand.
  8. Command (mforhelp):

MBR分区不支持大于2T的分区,所有对于现在打的硬盘分区来说只能使用GPT分区,所以就要使用gdisk命令

2gdisk也可以处理MBR分区的硬盘,不管你硬盘多大,都不在话下。

2 gdisk对硬盘就行分区,这里以vmware虚拟机为例

1)查看为分区之前的磁盘信息,这里以/dev/sdc为例

  1. [root@local ~]# gdisk -l /dev/sdd
  2. GPT fdisk (gdisk) version 0.8.6
  3.  
  4. Partition table scan:
  5. MBR: not present
  6. BSD: not present
  7. APM: not present
  8. GPT: not present
  9.  
  10. Creating new GPT entries.
  11. Disk /dev/sdd: 10485760 sectors,5.0 GiB
  12. Logical sector size: 512 bytes
  13. Disk identifier (GUID): 5ECA06B5-A105-4DCB-B6DD-96A13D0C1A93
  14. Partition table holds up to 128 entries
  15. First usable sector is 34,last usable sector is 10485726
  16. Partitions will be aligned on 2048-sector boundaries
  17. Total free space is 10485693 sectors (5.0 GiB)
  18.  
  19. Number Start (sector) End (sector) Size Code Name

当然也可用fdis命令查看

  1. [root@local ~]# fdisk -l /dev/sdc
  2. Disk /dev/sdc: 5368 MB,5368709120 bytes,10485760 sectors
  3. Units = sectors of 1 * 512 = 512 bytes
  4. Sector size (logical/physical): 512 bytes / 512 bytes
  5. I/O size (minimum/optimal): 512 bytes / 512 bytes 

2gdisk命令对磁盘进行操作

  1. [root@local ~]# gdisk /dev/sdc
  2. GPTfdisk (gdisk) version 0.8.6
  3.  
  4. Partitiontablescan:
  5. MBR: notpresent
  6. BSD: notpresent
  7. APM: notpresent
  8. GPT: notpresent
  9.  
  10. CreatingnewGPTentries.
  11.  
  12. Command (? forhelp):

3)根据提示,输入?获得帮助

  1. Command (? forhelp): ?
  2. b backupGPTdatatoafile
  3. c changeapartition'sname
  4. d deleteapartition #删除分区
  5. i showdetailedinformationonapartition
  6. l listknownpartitiontypes #列出分区类型
  7. n addanewpartition #添加新分区
  8. o createanewemptyGUIDpartitiontable (GPT)
  9. p printthepartitiontable #打印分区列表
  10. q quitwithoutsavingchanges #不保存退出
  11. r recoveryandtransformationoptions (expertsonly)
  12. s sortpartitions
  13. t changeapartition'stypecode #修改分区类型
  14. v verifydisk
  15. w writetabletodiskandexit #保存退出
  16. x extrafunctionality (expertsonly)
  17. ? printthismenu 

4添加一个新分区

  1. Command (? forhelp): n
  2.  
  3. Partitionnumber (1-128,default 1): 1 #输入分区编号,默认为1,因为是/dev/sdc硬盘的第一块分区。
  4. Firstsector (34-10485726,default = 2048) or {+-}size{KMGTP}: #输入扇区的开始位置,选择默认即可,也可手动指定。
  5. Lastsector (2048-10485726,default = 10485726) or {+-}size{KMGTP}:+2G #输入扇区的结束位置,当然一般都是指定磁盘大小,这里输入+2G表示新分区大小为2G。
  6. Currenttypeis 'Linuxfilesystem'
  7. HexcodeorGUID (Ltoshowcodes,Enter = 8300): #指定文件系统,默认即可,分区完成后可以修改
  8.  
  9. Changedtypeofpartitionto 'Linuxfilesystem' 

5)查看分区后的分区列表

  1. Command (? forhelp): p #查看分区列表
  2. Disk /dev/sdc: 10485760 sectors,5.0 GiB
  3. Logicalsectorsize: 512 bytes
  4. Diskidentifier (GUID): 428D4D72-0C16-4AD6-80A3-7BCACED6F40C
  5. Partitiontableholdsupto 128 entries
  6. Firstusablesectoris 34,lastusablesectoris 10485726
  7. Partitionswillbealignedon 2048-sectorboundaries
  8. Totalfreespaceis 6291389 sectors (3.0 GiB)
  9. NumberStart (sector) End (sector) SizeCodeName
  10. 1 2048 4196351 2.0 GiB 8300 Linuxfilesystem #看到分区已经添加成功 

6)保存分区并退出

  1. Command (? forhelp):w
  2.  
  3. Finalcheckscomplete. AbouttowriteGPTdata. THISWILLOVERWRITEEXISTING
  4. PARTITIONS!!
  5.  
  6. Doyouwanttoproceed? (Y/N): y
  7. OK; writingnewGUIDpartitiontable (GPT) to /dev/sdc.
  8. Theoperationhascompletedsuccessfully. 

可以看到分区以添加成功

3 创建文件系统

  1. [root@local ~]# mkfs.xfs /dev/sdc1
  2. Meta-data=/dev/sdc1 isize=512 agcount=4,agsize=131072 blks
  3. = sectsz=512 attr=2,projid32bit=1
  4. = crc=1 finobt=0,sparse=0
  5. data = bsize=4096 blocks=524288,imaxpct=25
  6. = sunit=0 swidth=0 blks
  7. naming =version 2 bsize=4096 ascii-ci=0 ftype=1
  8. log =internal log bsize=4096 blocks=2560,version=2
  9. = sectsz=512 sunit=0 blks,lazy-count=1
  10. realtime =none extsz=4096 blocks=0,rtextents=0

到此分区、文件系统创建成功,通过挂载就可以使用磁盘了

猜你在找的Linux相关文章