How to use a new partition in RHEL6 without reboot?

Solution Unverified - Updated -

Environment

  • Red Hat Enterprise Linux 6

Issue

  • Added a new partition to a disk that have some existing partitions already mounted. Can the new partition be used without reboot in RHEL6?
  • New partition created with fdisk command is not visible in the OS.

Resolution

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.

So in general we would suggest:

  1. Unmount all the partitions of the disk before modifying the partition table on the disk, and then run partprobe to update the partitions in system.
  2. If this is not possible (e.g. the mounted partition is a system partition), reboot the system after modifying the partition table. The partitions information will be re-read after reboot.

If a new partition was added and none of the existing partitions were modified, consider using the partx command to update the system partition table. Do note that the partx command does not do much checking between the new and the existing partition table in the system and assumes the user knows what they are doing. So it can corrupt the data on disk if the existing partitions are modified or the partition table is not set correctly. So use at one's own risk.

For example, a partition #1 is an existing partition and a new partition #2 is already added in /dev/sdb by fdisk. Here we use partx -v -a /dev/sdb to add the new partition to the system:

# ls /dev/sdb*  
/dev/sdb  /dev/sdb1  

List the partition table of disk:

# partx -l /dev/sdb
# 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)  

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

# 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)

Check that we have device nodes for /dev/sdb itself and the partitions on it:

# ls /dev/sdb*  
/dev/sdb  /dev/sdb1  /dev/sdb2

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.

5 Comments

The question is how to use a new partition without rebooting, and the solution is to take the disk out of service (equivalent to rebooting, from a downtime perspective) or reboot? Dynamic resizing of disks is very common in SAN and VMWare environments, and this "enhancement" to RHEL 6 that disables dynamic updates to active partition tables is ill advised, in my opinion.

The solution contains non-reboot way too using partx.

Just experimented with partitions merge:
- from /dev/sda
- removed partition 9
- removed partition 8
- recreated partition 8 twice big
- issued
partx -d -nr 8-9 /dev/sda
- issued
partx -a /dev/sda
- checked /proc/partitions
- kernel now is seeing /dev/sda8 only and reports new size.

If it will work without surprises, then would think that was an enhancement actually.

Partprobe became honestly advisable and 100% safe and split out its new risky "partx" twin-brother.

^IMO

It works! so far... will need a permanent way to set this - thanks

Before
14:07:05 2014 from c292117-010001152182.cn.ca
[root@mtl-rhev02d ~]# cat /sys/class/net/165_115_118_0/bridge/multicast_querier
0
[root@mtl-rhev02d ~]# cat /sys/class/net/165_115_118_0/bridge/multicast_snooping
1
[root@mtl-rhev02d ~]# echo 0 > /sys/class/net/165_115_118_0/bridge/multicast_snooping
[root@mtl-rhev02d ~]# echo 1 > /sys/class/net/165_115_118_0/bridge/multicast_querier

I have tried partx on the active root disk where it was expanded to create new partition and partx worked without issues.

partx -v -a /dev/sda
device /dev/sda: start 0 size 106954752
gpt: 0 slices
dos: 4 slices
1: 2048- 206847 ( 204800 sectors, 104 MB)
2: 206848-104857599 (104650752 sectors, 53581 MB)
3: 104871936-106954751 ( 2082816 sectors, 1066 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

I've got the same problem within anaconda/kickstart (non-interactive install)

How can I "partprobe" in ks ?

Here is the current part of my ks.cfg :

....
# System bootloader configuration
bootloader --location=mbr
# Partition clearing information
clearpart --all
# Disk partitioning information
part /boot --fstype="ext3" --ondisk=sda --size=500
part / --fstype="ext3" --ondisk=sda --size=30000
part /tmp --fstype="ext3" --ondisk=sda --size=5000
part swap --fstype="swap" --ondisk=sda --recommended
part /scratch_l --fstype="ext3" --grow --ondisk=sda --size=1

%post
...

Thanks