[root@centos6 ~]#fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x769c63d5.
........
Command (m for help): m
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
l list known partition types
m print this menu
n add a new partition
o create a new empty DOS partition table
p print the partition table
q quit without saving changes
s create a new empty Sun disklabel
t change a partition's system id
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-2610, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-2610, default 2610): +1G
Command (m for help): p
Disk /dev/sdb: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
.......
Device Boot Start End Blocks Id System
/dev/sdb1 1 132 1060258+ 83 Linux
3、parted 的操作都是实时生效的,小心使用
用法:parted [ 选项 ].....[ 设备 [ 命令 [参数]...]...]
# 要对当前设备/dev/sdb 做gpt格式分区
#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.
# 查看当前/dev/sdb信息
[root@centos6 ~]#parted /dev/sdb 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 Flags
# 直接对/dev/sdb 分主分区 立马生效
[root@centos6 ~]#parted /dev/sdb mkpart primary 1 200
# 删除/dev/sdb 下的第2个分区
[root@centos6 ~]#parted /dev/sdb rm 2
# 列出分区信息
[root@centos6 ~]#parted -l
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sda: 215GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Number Start End Size Type File system Flags
1 1049kB 1075MB 1074MB primary ext4 boot
2 1075MB 53.5GB 52.4GB primary ext4
3 53.5GB 85.0GB 31.5GB primary ext4
4 85.0GB 215GB 130GB extended
5 85.0GB 88.2GB 3228MB logical linux-swap(v1)
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
..........
4、分区创建好之后,需要同步分区表,用到的命令有partx、partprobe
1、partx 用于CentOS6 系统
[root@centos6 ~]#partx -a /dev/sba
[root@centos6 ~]#kpartx -a -f /dev/sda
# 删除其中某一个分区
[root@centos6 ~]#lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 200G 0 disk
├─sda1 8:1 0 1G 0 part /boot
├─sda2 8:2 0 48.8G 0 part /
├─sda3 8:3 0 29.3G 0 part /data
├─sda4 8:4 0 1K 0 part
├─sda5 8:5 0 3G 0 part [SWAP]
├─sda6 8:6 0 1G 0 part
└─sda7 8:7 0 1G 0 part
sdb 8:16 0 20G 0 disk
sdc 8:32 0 20G 0 disk
sr0 11:0 1 3.7G 0 rom
[root@centos6 ~]#partx -d --nr 7 /dev/sda
[root@centos6 ~]#lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 200G 0 disk
├─sda1 8:1 0 1G 0 part /boot
├─sda2 8:2 0 48.8G 0 part /
├─sda3 8:3 0 29.3G 0 part /data
├─sda4 8:4 0 1K 0 part
├─sda5 8:5 0 3G 0 part [SWAP]
└─sda6 8:6 0 1G 0 part
sdb 8:16 0 20G 0 disk
sdc 8:32 0 20G 0 disk
sr0 11:0 1 3.7G 0 rom
2、partprobe centos5、7系统使用
Command (m for help): p
Disk /dev/sda: 214.7 GB, 214748364800 bytes, 419430400 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: 0x000bcc63
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 176179199 87040000 8e Linux LVM
/dev/sda3 176179200 178276351 1048576 5 Extended
/dev/sda5 176181248 177205247 512000 83 Linux
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
#直接使用partprobe命令
[root@centos7 ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 200G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 83G 0 part
├─centos-root 253:0 0 50G 0 lvm /
├─centos-swap 253:1 0 3G 0 lvm [SWAP]
└─centos-data 253:2 0 30G 0 lvm /data
sr0 11:0 1 8.8G 0 rom
[root@centos7 ~]# partprobe
Warning: Unable to open /dev/sr0 read-write (Read-only file system). /dev/sr0 has been opened read-only.
[root@centos7 ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 200G 0 disk
├─sda1 8:1 0 1G 0 part /boot
├─sda2 8:2 0 83G 0 part
│ ├─centos-root 253:0 0 50G 0 lvm /
│ ├─centos-swap 253:1 0 3G 0 lvm [SWAP]
│ └─centos-data 253:2 0 30G 0 lvm /data
├─sda3 8:3 0 512B 0 part
└─sda5 8:5 0 500M 0 part
sr0 11:0 1 8.8G 0 rom