$ fdisk -l
Disk /dev/sda: 32.2 GB, 32212254720 bytes
255 heads, 63 sectors/track, 3916 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: 0x000c20c5
Device Boot Start End Blocks Id System
/dev/sda1 * 1 64 512000 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 64 2611 20458496 8e Linux LVM
Disk /dev/mapper/vg_centos6-lv_root: 18.8 GB, 18798870528 bytes
255 heads, 63 sectors/track, 2285 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
Disk /dev/mapper/vg_centos6-lv_swap: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 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
创建新的分区
格式化未使用的磁盘空间
$ fdisk /dev/sda
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
switch off the mode (command 'c') and change display units to
sectors (command 'u').
Command (m for help): n #添加新的分区
Command action
e extended
p primary partition (1-4)
p #主分区
Partition number (1-4): 3 #分区号
First cylinder (2611-3916, default 2611):
Using default value 2611
Last cylinder, cylinders or size{K,M,G} (2611-3916, default 3916):
Using default value 3916
Command (m for help): t #格式化
Partition number (1-4): 3 #需要格式化的分区
Hex code (type L to list codes): 8e #分区格式
Changed system type of partition 3 to 8e (Linux LVM)
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.
查看分区信息
$ fdisk -l
Disk /dev/sda: 32.2 GB, 32212254720 bytes
255 heads, 63 sectors/track, 3916 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: 0x000c20c5
Device Boot Start End Blocks Id System
/dev/sda1 * 1 64 512000 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 64 2611 20458496 8e Linux LVM
/dev/sda3 2611 3916 10483750 8e Linux LVM
Disk /dev/mapper/vg_centos6-lv_root: 18.8 GB, 18798870528 bytes
255 heads, 63 sectors/track, 2285 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
Disk /dev/mapper/vg_centos6-lv_swap: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 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
看到/dev/sda3分区已经成功,但是没法使用,是因为分区表没更新,根据提示使用partprobe命令更新分区表,如果没有此命令,请安装parted包
$ partprobe
Warning: WARNING: the kernel failed to re-read the partition table on /dev/sda (Device or resource busy). As a result, it may notreflect all of your changes until after reboot.Warning: Unable to open /dev/sr0 read-write (Read-only file system). /dev/sr0 has been opened read-only.Warning: Unable to open /dev/sr0 read-write (Read-only file system). /dev/sr0 has been opened read-only.Error: Invalid partition table - recursive partition on /dev/sr0.
$ ll /dev/sda
sda sda1 sda2
此时我们创建的sda3分区根本没显示出来,分区表更新失败
查看官网文档,解决方法:https://access.redhat.com/solutions/57542
官网给出原因:
partprobe在RHEL5中常用于通知操作系统磁盘上的分区表更改。在RHEL6中,只有当那些磁盘上任何分区都没有在使用的磁盘下(例如,mounted)它才会触发OS去更新磁盘的分区表。如果正在使用磁盘上的任何分区,partprobe则不会触发操作系统更新系统中的分区,因为在某些情况下它被认为是不安全的。
推荐解决方法:
- 在修改磁盘上的分区表之前卸载磁盘的所有分区,然后运行partprobe以更新系统中的分区。
- 如果无法做到这一点(例如,挂载的分区是系统分区),请在修改分区表后重新引导系统。重启后将重新读取分区信息。
如果添加了新分区且未修改任何现有分区,请考虑使用该partx命令更新系统分区表
列出分区表
$ partx -l /dev/sda
# 1: 2048- 1026047 ( 1024000 sectors, 524 MB)
# 2: 1026048- 41943039 ( 40916992 sectors, 20949 MB)
# 3: 41943040- 62910539 ( 20967500 sectors, 10735 MB)
# 4: 0- -1 ( 0 sectors, 0 MB)
读取磁盘并尝试将所有分区添加到系统
$ partx -v -a /dev/sda
device /dev/sda: start 0 size 62914560
gpt: 0 slices
dos: 4 slices
# 1: 2048- 1026047 ( 1024000 sectors, 524 MB)
# 2: 1026048- 41943039 ( 40916992 sectors, 20949 MB)
# 3: 41943040- 62910539 ( 20967500 sectors, 10735 MB)
# 4: 0- -1 ( 0 sectors, 0 MB)
BLKPG: Device or resource busy
error adding partition 1
BLKPG: Device or resource busy
error adding partition 2
added partition 3
- 出现添加1,2分区错误是正常的,因为1,2分区已经添加过了
再去查看系统,已经正常/dev/sda3 已经显示
$ ls /dev/sda*
/dev/sda /dev/sda1 /dev/sda2 /dev/sda3