How to use a new partition in RHEL6 without reboot?
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:
- 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. - 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.
Comments