使用parted和gdisk工具對硬盤進行GPT分區的最後效果差不多。
如果是固態硬盤,使用parted對硬盤分區默認會進行4K對齊。
但是使用parted分區,是直接修改分區表,實際環境中配置容錯率很低。
基本配置舉例:
配置前,使用fdisk -l 確認你的linux系統有一塊空的硬盤
[root@localhost ~]# parted /dev/sdb
GNU Parted 3.1
Using /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) help # 使用help可以查看parted支持的命令參數
align-check TYPE N check partition N for TYPE(min|opt) alignment
help [COMMAND] print general help, or help on COMMAND
mklabel,mktable LABEL-TYPE create a new disklabel (partition table)
mkpart PART-TYPE [FS-TYPE] START END make a partition
name NUMBER NAME name partition NUMBER as NAME
print [devices|free|list,all|NUMBER] display the partition table, available devices, free space, all found partitions, or a particular partition
quit exit program
rescue START END rescue a lost partition near START and END
rm NUMBER delete partition NUMBER
select DEVICE choose the device to edit
disk_set FLAG STATE change the FLAG on selected device
disk_toggle [FLAG] toggle the state of FLAG on selected device
set NUMBER FLAG STATE change the FLAG on partition NUMBER
toggle [NUMBER [FLAG]] toggle the state of FLAG on partition NUMBER
unit UNIT set the default unit to UNIT
version display the version number and copyright information of GNU Parted
(parted) mklabel gpt # 使用GPT分區,支持2T以上的硬盤
Warning: The existing disk label on /dev/sdb will be destroyed and all data on this disk will be lost. Do you want to continue?
Yes/No? yes # 輸入yes
(parted) mkpart # 該命令進行分區
Partition name? []? # 設置分區名字
File system type? [ext2]? xfs # 設置分區類型
Start? 1 # 1表示從最開始分區,也可以用百分比表示,比如Start? 0% , End? 50%
End? -1 # -1表示到磁盤末尾;也可以分成多個磁盤,寫要分配的大小
# 如果想分兩個分區,大小均分,可以這樣寫
# Start? 1
# End? 50%
# 另一個分區
# Start? 50%
# End? 100%
(parted) print # 檢查
Model: VMware Virtual disk (scsi)
Disk /dev/sdb: 215GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
1 1049kB 215GB 215GB xfs
(parted) quit
Information: You may need to update /etc/fstab.
You have new mail in /var/spool/mail/root
# 下面是刪除分區示例
(parted) rm 1 #rm後面使用分區的號碼,就是用print打印出來的Number
(parted) print
Model: VBOX HARDDISK (ide)
Disk /dev/vdb: 2147GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Number Start End Size File system Name Flags
使用parted分完區後,可以直接格式化
[root@localhost ~]# mkfs.xfs -f /dev/sdb1
meta-data=/dev/sdb1 isize=256 agcount=4, agsize=13107072 blks
= sectsz=512 attr=2, projid32bit=1
= crc=0 finobt=0
data = bsize=4096 blocks=52428288, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=0
log =internal log bsize=4096 blocks=25599, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
然後/etc/fstab進行掛載
[root@localhost ~]# vim /etc/fstab
/dev/sdb1 /lewis xfs defaults 0 0