使用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