parted是常见的分区工具,能够支持TB级分区,而fdisk不行。

用法格式:

parted [options] [device [command [options...]...]]


1.创建分区

[root@Nodes03 ~]# parted /dev/sdb mkpart primary ext4 0G 5G


mkpart PART-TYPE [FS-TYPE] START END   make a partition


part-type:

       primary(主分区)、extended(扩展分区)、logical(逻辑分区)、

fs-type:

       ext2 ext3 ext4 ....

start  end:

        START和END是新分区开始和结束的具体位置

注:如果是一块新磁盘,还得指定分区表格式 gpt(支持2TB以上的磁盘) msdos,mklabel gpt

[root@Nodes03 ~]# parted /dev/sdb mklabel gpt
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
Information: You may need to update /etc/fstab.


2.查看分区信息

[root@Nodes03 ~]# parted /dev/sdb print
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 5369MB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Number  Start   End     Size    File system  Name     Flags
 1      1049kB  5368MB  5367MB  ext3         primary


3.挂载分区

[root@Nodes03 ~]# mount /dev/sdb1 /mnt/
[root@Nodes03 ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sdb1             2.8G   69M  2.6G   3% /mnt


3.删除分区表

[root@Nodes03 ~]# parted /dev/sdb rm 1


4.使新分区生效

[root@nodes02 ~]# partx -a /dev/sda   重新读取分区表
BLKPG: Device or resource busy
error adding partition 1
BLKPG: Device or resource busy
error adding partition 2
BLKPG: Device or resource busy
error adding partition 3
BLKPG: Device or resource busy
error adding partition 4
BLKPG: Device or resource busy
error adding partition 5
[root@nodes02 ~]# ls /dev/sda*
/dev/sda  /dev/sda1  /dev/sda2  /dev/sda3  /dev/sda4  /dev/sda5  /dev/sda6
[root@nodes02 ~]# mkfs -t ext4 /dev/sda6   格式分区