fdisk命令是针对MBR分区进行操作,MBR分区因为自身设计原因,不能处理大于2TB的硬盘,并且只能有4个分区。
针对大于2TB的硬盘,需要采用GPT分区,使用parted命令进行操作
parted命令使用
print [free|all | NUMBER] | 查看分区状态信息 |
mkpart PART-TYPE START END | 创建新分区, PART-TYPE: primary extended logical START, END 开始,结束为止 |
set NUMBER FLAG STATE | 对编号为NUMBER的进行标记。 FLAG: boot 引导, hidden 隐藏, raid 软raid, lvm 逻辑卷, STATE: on| off |
mkfs NUMBER FS-TYPE | 对NUMBER指定文件系统。FS-Type有:ext2、fat16、fat32、linuxswap、NTFS、reiserfs、ufs 等 |
cp [FROM-DEV] FROM-NUMBER TO-NUMBER | 将分区 FROM-NUMBER 上的文件系统完整地复制到分区TO-NUMBER 中,作为可选项还可以指定一个来源硬盘的设备名称FROM-DEVICE,若省略则在当前设备上进行复制。 |
move NUMBER START END | 将指定编号 NUMBER 的分区移动到从 START 开始 END 结束的位置上。注意:(1)只能将分区移动到空闲空间中。(2)虽然分区被移动了,但它的分区编号是不会改变的 |
resize NUMBER START END | 对指定编号 NUMBER 的分区调整大小。分区的开始位置和结束位置由 START 和 END 决定 |
check NUMBER | 检查指定编号 NUMBER 分区中的文件系统是否有什么错误 |
rescue START END | rescue START END |
mklabel,mktable LABELTYPE | 创建一个新的 LABEL-TYPE 类型的空磁盘分区表,对于PC而言 msdos 是常用的 LABELTYPE。 若是用 GUID 分区表,LABEL-TYPE 应该为 gpt |
实例:
1. 对/dev/sdb分区进行操作
[root@localhost ~]# parted /dev/sdb
GNU Parted 3.1
Using /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
2. 制定磁盘格式为gpt
(parted) mklabel
New disk label type? gpt
3. 查看磁盘分区信息
(parted) print
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 1074MB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
4. 制作分区
(parted) mkpart
Partition name? []? d1
File system type? [ext2]? ext4
Start? 0
End? 512M
Warning: The resulting partition is not properly aligned for best performance. #注意这个警告。采用这种方式分区只是测试,后边又把相关分区删除了。
Ignore/Cancel? i
5. 查看新增分区后的状态
(parted) prin
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 1074MB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
1 17.4kB 512MB 512MB d1
6. 删除分区1(Number号)
(parted) rm 1
7. 新增分区 primary 分区,起始2048sector ,结束磁盘大小的50%
(parted) mkpart primary 2048s 50%
(parted) print
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 1074MB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
1 1049kB 537MB 536MB primary
8. 新增另一个分区,primary分区,起始磁盘的50%,结束100%大小。
(parted) mkpart primary 50% 100%
(parted) p
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 1074MB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
1 1049kB 537MB 536MB primary
2 537MB 1073MB 536MB primary
9. 退出parted
(parted) q
Information: You may need to update /etc/fstab.
10. fdisk查看磁盘状态。能够发现新增磁盘分区状态。
[root@localhost ~]# fdisk -l
Disk /dev/sda: 21.5 GB, 21474836480 bytes, 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000c0b7f
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 1026047 512000 83 Linux
/dev/sda2 1026048 41943039 20458496 8e Linux LVM
Disk /dev/mapper/rhel-root: 18.8 GB, 18798870528 bytes, 36716544 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk /dev/mapper/rhel-swap: 2147 MB, 2147483648 bytes, 4194304 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
WARNING: fdisk GPT support is currently new, and therefore in an experimental phase. Use at your own discretion.
Disk /dev/sdb: 1073 MB, 1073741824 bytes, 2097152 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: gpt
# Start End Size Type Name
1 2048 1048575 511M Microsoft basic primary
2 1048576 2095103 511M Microsoft basic primary
11. 新增完成后,建议重新格式化分区。
[root@localhost ~]# mkfs.ext4 /dev/sdb1
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
131072 inodes, 523264 blocks
26163 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=34078720
64 block groups
8192 blocks per group, 8192 fragments per group
2048 inodes per group
Superblock backups stored on blocks:
8193, 24577, 40961, 57345, 73729, 204801, 221185, 401409
Allocating group tables: done
Writing inode tables: done
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done
[root@localhost ~]# mkfs.ext4 /dev/sdb2
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
131072 inodes, 523264 blocks
26163 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=34078720
64 block groups
8192 blocks per group, 8192 fragments per group
2048 inodes per group
Superblock backups stored on blocks:
8193, 24577, 40961, 57345, 73729, 204801, 221185, 401409
Allocating group tables: done
Writing inode tables: done
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done
12. 修改/etc/fstab实现自动挂载
建议使用UUID进行挂在
blkid /dev/sdb1 (或者blkid)
/dev/sdb1: UUID="bc95b330-5eb9-4b68-9f9f-71c52247a1b4" TYPE="ext4"
修改/etc/fstab
UUID=bc95b330-5eb9-4b68-9f9f-71c52247a1b4 /opt ext4 defaults 0 0