磁碟分割-gdisk用法,磁碟分割-gdisk
gdisk用法
gdisk - InteractiveGUIDpartitiontable (GPT) manipulator
GPTfdisk (akagdisk) isatext-modemenu-drivenprogramforcreationandmanipulation
ofpartitiontables.
1 使用gdisk的原因
(1)由於fdisk命令不能很好的支援GPT分區
[root@local ~]# fdisk /dev/sdbWARNING: fdiskGPTsupportiscurrentlynew, andthereforeinanexperimentalphase. Useatyourowndiscretion.Welcometofdisk (util-linux 2.23.2).Changeswillremaininmemoryonly, untilyoudecidetowritethem.Becarefulbeforeusingthewritecommand.Command (mforhelp):
而MBR分區不支援大於2T的分區,所有對於現在打的硬碟分區來說只能使用GPT分區,所以就要使用gdisk命令
(2)gdisk也可以處理MBR分區的硬碟,不管你硬碟多大,都不在話下。
2 用gdisk對硬碟就行分區,這裡以vmware虛擬機器為例
(1)查看為分區之前的磁碟資訊,這裡以/dev/sdc為例
[root@local ~]# gdisk -l /dev/sddGPT fdisk (gdisk) version 0.8.6Partition table scan:MBR: not presentBSD: not presentAPM: not presentGPT: not presentCreating new GPT entries.Disk /dev/sdd: 10485760 sectors, 5.0 GiBLogical sector size: 512 bytesDisk identifier (GUID): 5ECA06B5-A105-4DCB-B6DD-96A13D0C1A93Partition table holds up to 128 entriesFirst usable sector is 34, last usable sector is 10485726Partitions will be aligned on 2048-sector boundariesTotal free space is 10485693 sectors (5.0 GiB)Number Start (sector) End (sector) Size Code Name
當然也可用fdis命令查看
[root@local ~]# fdisk -l /dev/sdcDisk /dev/sdc: 5368 MB, 5368709120 bytes, 10485760 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytes
(2)gdisk命令對磁碟進行操作
[root@local ~]# gdisk /dev/sdcGPTfdisk (gdisk) version 0.8.6Partitiontablescan:MBR: notpresentBSD: notpresentAPM: notpresentGPT: notpresentCreatingnewGPTentries.Command (? forhelp):
(3)根據提示,輸入?獲得協助
Command (? forhelp): ?b backupGPTdatatoafilec changeapartition'snamed deleteapartition #刪除分區i showdetailedinformationonapartitionl listknownpartitiontypes #列出分區類型n addanewpartition #添加新分區o createanewemptyGUIDpartitiontable (GPT)p printthepartitiontable #列印分區列表q quitwithoutsavingchanges #不儲存退出r recoveryandtransformationoptions (expertsonly)s sortpartitionst changeapartition'stypecode #修改分區類型v verifydiskw writetabletodiskandexit #儲存退出x extrafunctionality (expertsonly)? printthismenu
(4)添加一個新分區
Command (? forhelp): nPartitionnumber (1-128, default 1): 1 #輸入分區編號,預設為1,因為是/dev/sdc硬碟的第一塊分區。Firstsector (34-10485726, default = 2048) or {+-}size{KMGTP}: #輸入扇區的開始位置,選擇預設即可,也可手動指定。Lastsector (2048-10485726, default = 10485726) or {+-}size{KMGTP}:+2G #輸入扇區的結束位置,當然一般都是指定磁碟大小,這裡輸入+2G表示新分區大小為2G。Currenttypeis 'Linuxfilesystem'HexcodeorGUID (Ltoshowcodes, Enter = 8300): #指定檔案系統,預設即可,分區完成後可以修改。Changedtypeofpartitionto 'Linuxfilesystem'
(5)查看分區後的分區列表
Command (? forhelp): p #查看分區列表Disk /dev/sdc: 10485760 sectors, 5.0 GiBLogicalsectorsize: 512 bytesDiskidentifier (GUID): 428D4D72-0C16-4AD6-80A3-7BCACED6F40CPartitiontableholdsupto 128 entriesFirstusablesectoris 34, lastusablesectoris 10485726Partitionswillbealignedon 2048-sectorboundariesTotalfreespaceis 6291389 sectors (3.0 GiB)NumberStart (sector) End (sector) SizeCodeName1 2048 4196351 2.0 GiB 8300 Linuxfilesystem #看到分區已經添加成功
(6)儲存分區並退出
Command (? forhelp):wFinalcheckscomplete. AbouttowriteGPTdata. THISWILLOVERWRITEEXISTINGPARTITIONS!!Doyouwanttoproceed? (Y/N): yOK; writingnewGUIDpartitiontable (GPT) to /dev/sdc.Theoperationhascompletedsuccessfully.
可以看到分區以添加成功
3 建立檔案系統
[root@local ~]# mkfs.xfs /dev/sdc1meta-data=/dev/sdc1 isize=512 agcount=4, agsize=131072 blks= sectsz=512 attr=2, projid32bit=1= crc=1 finobt=0, sparse=0data = bsize=4096 blocks=524288, imaxpct=25= sunit=0 swidth=0 blksnaming =version 2 bsize=4096 ascii-ci=0 ftype=1log =internal log bsize=4096 blocks=2560, version=2= sectsz=512 sunit=0 blks, lazy-count=1realtime =none extsz=4096 blocks=0, rtextents=0
到此分區、檔案系統建立成功,通過掛載就可以使用磁碟了