partproble在RHEL 6下无法更新分区信息

 

在RHEL5.x版本下面,在添加磁盘分区等操作后,一直使用partproble命令使内核重新读取分区表信息,从而不用重新启动。

但是最近在RHEL 6(Red Hat Enterprise Linux Server release 6.6 (Santiago))下,使用partprobe出现错误。

[root@localhost ~]# lsof /dev/sda
[root@localhost ~]# partprobe /dev/sda
Warning: WARNING: the kernel failed to re-read the partition table on /dev/sda (Device or resource busy). As a result, it may not reflect all of your changes until after reboot.

 

后面查了一下资料发现,在官方文档How to use a new partition in RHEL6 without reboot中有如下介绍:

partprobe was commonly used in RHEL 5 to inform the OS of partition table changes on the disk. In RHEL 6, it will only trigger the OS to update the partitions on a disk that none of its partitions are in use (e.g. mounted). If any partition on a disk is in use, partprobe will not trigger the OS to update partitions in the system because it is considered unsafe in some situations.


翻译如下:
partprobe通常在RHEL 5中用来通知操作系统的磁盘上的分区表变化或更改。在RHEL 6中,只有当那些磁盘上任何分区都没有在使用的磁盘下(例如,mounted)它才会触发OS去更新磁盘的分区表。如果磁盘上的任何分区正在使用中,partprobe命令不会触发操作系统去更新分区表的信息,因为在某些情况下,它被认为是不安全的。


解决方案: 


1:重启操作系统。万能的重启,哈哈,不过,在很多情况下是不现实的,因为重启会中断业务,重启只能是下下策。

2:使用partx命令来解决这个。

[root@localhost ~]# partx -l /dev/sdb          #查看当前硬盘分区情况
# 1:     63-314568764 (314568702 sectors, 161059 MB)
# 2:     314568765-356514479 ( 41945715 sectors, 21476 MB)
# 3:     0- -1 ( 0 sectors, 0 MB)
# 4:     0- -1 ( 0 sectors, 0 MB)


[root@localhost ~]# partx -v -a /dev/sdb        #重读硬盘分区
device /dev/sdb: start 0 size 356515840
gpt: 0 slices
dos: 4 slices
# 1:     63-314568764 (314568702 sectors, 161059 MB)
# 2:     314568765-356514479 ( 41945715 sectors, 21476 MB)
# 3:     0- -1 ( 0 sectors, 0 MB)
# 4:     0- -1 ( 0 sectors, 0 MB)
BLKPG: Device or resource busy
error adding partition 1

 

BLKPG: Device or resource busy 这个提示信息是正常,表示分区1在分区2添加前已经存在了。

Read disk and try to add all partitions to the system:

Raw

# partx -v -a /dev/sdb 
device /dev/sdb: start 0 size 2097152 
gpt: 0 slices 
dos: 4 slices 
# 1: 63- 505007 ( 504945 sectors, 258 MB) 
# 2: 505008- 1010015 ( 505008 sectors, 258 MB) 
# 3: 0- -1 ( 0 sectors, 0 MB) 
# 4: 0- -1 ( 0 sectors, 0 MB) 
BLKPG: Device or resource busy
error adding partition 1

 

(These last 2 lines are normal in this case because partition 1 is already added in the system before partition 2 is added)

例如在添加、读取分区表信息后,再执行下面命令,就会发现分区2也报“BLKPG: Device or resource busy error adding partition 2”

 

 

 

 

检查分区节点信息。

[root@localhost ~]# ls /dev/sdb*
/dev/sdb /dev/sdb1 /dev/sdb2

另外,我在测试中,发现也可以使用下面方法里解决,例如新增的分区是/dev/sdc2/ /dev/sdb2/ /dev/sda4,那么就可以执行如下命令解决问题。

[root@localhost ~]# partx -a /dev/sdc2 /dev/sdc
[root@localhost ~]# partx -a /dev/sdb2 /dev/sdb
[root@localhost ~]# partx -a /dev/sda4 /dev/sda

  

 

 

posted on 2023-03-07 16:43  tengq  阅读(38)  评论(0编辑  收藏  举报

导航