- 环境
- 虚拟机:VMware-10.0.7 build-2844087
- Linux系统:CentOS 6.8
- 远程工具:Xshell 6 (Build 0197)
CentOS6.8 使用 parted命令 手动硬盘分区 GPT分区
一、前言
实际生产环境中,大于2.1个TB的硬盘较为多见,我们熟知的MBR分区表(主引导分区表)已无法完成分区的任务,此时我们要用另外一种分区表来解决此问题,即GPT分区表。
二、GPT分区表
2.1 什么是GPT
- GPT:全局唯一标识分区表
- GUID Partition table,缩写GPT
- 全局唯一标识磁盘分区表格式。
2.2 GPT优缺点
- 优点
- 最大看可支持128个主分区,而MBR分区表只有4个主分区;
- 无主分区、扩展分区、逻辑分区概念,都是主分区;
- 最大支持18个EB的磁盘,而MBR分区表只支持2.1TB;
- GPT分区会在磁盘头部和尾部都存留一份分区表备份,方便恢复。
- 缺点:
- 自己去发现吧,笑脸。
- 换算:1EB=1024PB=1024*1024TB
三、parted 命令
3.1 parted 命令与 fdisk 命令的区别
- fdisk命令:只应用于MBR磁盘分区
- parted命令:只应用于GPT磁盘分区
3.2 parted命令 参数
align-check TYPE N check partition N for TYPE(min|opt) alignment
check NUMBER do a simple check on the file system
cp [FROM-DEVICE] FROM-NUMBER TO-NUMBER copy file system to another partition
help [COMMAND] print general help, or help on COMMAND
mklabel,mktable LABEL-TYPE create a new disklabel (partition table)
mkfs NUMBER FS-TYPE make a FS-TYPE file system on partition 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 NUMBER as NAME
print [devices|free|list,all|NUMBER] display the partition table, available or a
devices, free space, all found
partitions, particular partition
quit exit program
rescue START END rescue a lost partition near START and END
resize NUMBER START END resize partition NUMBER and its file system
rm NUMBER delete partition NUMBER
select DEVICE choose the device to edit
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
说明:参数没有翻译成中文,如感觉不方便可自行翻译一下。
四、GPT分区
4.1、分区前准备
- 准备一块新磁盘
- 已经挂载过的磁盘
- 取消自动挂载,通过修改配置文件 /etc/fstab 来实现 ,修改完毕 reboot;
- 手动取消挂载,通过umount 来实现,也可以reboot。
4.2、开始分区
- 进入 parted 交互命令脚本程序
[root@localhost ~]# parted /dev/sdb
GNU Parted 2.1
使用 /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted)
说明:我的第二块磁盘 /dev/sdb 准备用GPT分区
- 查看一下分区情况
(parted) print
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Number Start End Size Type File system 标志
(parted)
说明:默认状态没有分区,分区格式为 msdos。
- 修改分区表
(parted) mklabel gpt
警告: 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
(parted) print
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt <--已经是gpt分区表,修改成功
Number Start End Size File system Name 标志
(parted)
- 分区
(parted) mkpart
分区名称? []? disk1
文件系统类型? [ext2]? <--选择默认ext2文件系统,因为parted只支持此文件系统
起始点? 1MB
结束点? 5GB
(parted) print
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Number Start End Size File system Name 标志
1 1049kB 5000MB 4999MB disk1
(parted)
说明:刚分完区, File system 为空,需要格式化才能显示文件系统
- 格式化
(parted) mkfs
WARNING: you are attempting to use parted to operate on (mkfs) a file system.
parted's file system manipulation code is not as robust as what you'll find in
dedicated, file-system-specific packages like e2fsprogs. We recommend
you use parted only to manipulate partition tables, whenever possible.
Support for performing most operations on most types of file systems
will be removed in an upcoming release.
警告: The existing file system will be destroyed and all data on the partition will be lost. Do you want to continue?
是/Yes/否/No? Yes
分区编号? 1
文件系统类型? [ext2]?
(parted) print
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Number Start End Size File system Name 标志
1 1049kB 5000MB 4999MB ext2 disk1
说明:现在我们看到 File system 是 ext2 。
- 查看格式化后设备名字
[root@localhost ~]# fdisk -l
Disk /dev/sda: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000db990
Device Boot Start End Blocks Id System
/dev/sda1 * 1 131 1048576 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 131 392 2097152 82 Linux swap / Solaris
Partition 2 does not end on cylinder boundary.
/dev/sda3 392 2611 17824768 83 Linux
WARNING: GPT (GUID Partition Table) detected on '/dev/sdb'! The util fdisk doesn't support GPT. Use GNU Parted.
Disk /dev/sdb: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Device Boot Start End Blocks Id System
/dev/sdb1 1 2611 20971519+ ee GPT
[root@localhost ~]#
说明:通过 fdisk命令 查看,设备文件名为 /dev/sdb1
- 修改 /dev/sdb1 的文件系统为 ext4
[root@localhost ~]# mkfs -t ext4 /dev/sdb1
mke2fs 1.41.12 (17-May-2010)
文件系统标签=
操作系统:Linux
块大小=4096 (log=2)
分块大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
305216 inodes, 1220352 blocks
61017 blocks (5.00%) reserved for the super user
第一个数据块=0
Maximum filesystem blocks=1249902592
38 block groups
32768 blocks per group, 32768 fragments per group
8032 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736
正在写入inode表: 完成
Creating journal (32768 blocks): 完成
Writing superblocks and filesystem accounting information: 完成
This filesystem will be automatically checked every 37 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@localhost ~]#
- 挂载 + 验证
[root@localhost ~]# mount /dev/sdb1 /disk1
[root@localhost ~]# mount
/dev/sda3 on / type ext4 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw,rootcontext="system_u:object_r:tmpfs_t:s0")
/dev/sda1 on /boot type ext4 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
/dev/sdb1 on /disk1 type ext4 (rw) <--验证挂载成功
[root@localhost ~]#
4.3、注意点
- 分区时,分配足够的分区容量,尽量不要调整大小;
- 实在需要调整大小,请在修改文件系统前,完成 resize (调整大小)
五、小结
- 知识点总结
- parted命令 和 fdisk命令区别
- GPT分区表
- 分区及格式化
- 调整分区大小慎重
六、写在最后
以上内容,如有不足之处,欢迎在评论区指出,我会加以改正。如对您有所帮助,欢迎点赞+评论+关注,三连支持一下。