How To Reload Partition Table In Linux Without System Reboot?

As a Linux administrator you might perform a disk partition task multiple times in a day.

Most of the times the partition table has been altered successfully after the disk partition in the virtual environments (such as VMWare, Virtualbox, etc).

But it doesn’t happens on physical servers then what is the solution to inform the OS about partition table changes?

Yes, there will be solution for this. However, we can’t give you a guarantee that will work 100% but it will work in most of the times.

I can say in other words. It will work 99% as per my experience and knowledge.

These methods are force the Kernel to reload the partition table and re-populate its ids in /dev.

If you are looking for the disk partition utilities then you can try one of these. Disk partition utilities are fdisk and parted.

If you would like to read the related articles about disk partitions then you can navigate to the following articles.

You might get the output similar to below in most of the time in the virtual environment, when you are perform the disk partitions.

The partition table has been altered.
Syncing disks.

You might get the below same output in most of the time in the physical environment, when you perform the disk partitions.

The partition table has been altered.
Calling ioctl() to re-read partition table.
Re-reading the partition table failed.: 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).

I have tested the below commands on Arch Linux system and it was working fine except partx command. Because i don’t see any logs in the dmesg log after ran the partx command.

However it was working fine as expected in the RHEL 7 systems.

I would suggest you to run any of the below commands after adding a partition in Linux system to inform the OS about partition table changes.

It can be done using the following four methods.

  • partprobe: partprobe is a program that informs the operating system kernel of partition table changes, by requesting that the operating system re-read the partition table.
  • blockdev: The utility blockdev allows one to call block device ioctls from the command line.
  • hdparm: hdparm provides a command line interface to various kernel interfaces supported by the Linux SATA/PATA/SAS “libata” subsystem and the older IDE driver subsystem.
  • partx: partx is telling the kernel about presence and numbering of on-disk partitions.

How To Reload partition table in Linux Using partprobe Command

partprobe is a program that informs the operating system kernel of partition table changes, by requesting that the operating system re-read the partition table.

This is standard and native command to perform this task.

In this example I’m going to use /dev/sdb and make sure you have to input your device name instead of us.

$ sudo partprobe /dev/sdb

dmesg is used to examine or control the kernel ring buffer. So, use the following command to see the kernel changes. Yes, i can see the changes because there is a new log for sdb device in the dmesg.

$ dmesg | grep sdb
[    3.143163] sd 3:0:0:0: [sdb] 20971520 512-byte logical blocks: (10.7 GB/10.0 GiB)
[    3.143186] sd 3:0:0:0: [sdb] Write Protect is off
[    3.143192] sd 3:0:0:0: [sdb] Mode Sense: 00 3a 00 00
[    3.143276] sd 3:0:0:0: [sdb] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA
[    3.145620] sd 3:0:0:0: [sdb] Attached SCSI disk
[  188.810583]  sdb: sdb1 sdb2 sdb3 sdb4 < sdb5 >
[  219.112109]  sdb: sdb1 sdb2 sdb3 sdb4 < sdb5 >

How To Reload partition table in Linux Using blockdev Command

The utility blockdev allows one to call block device ioctls from the command line.

We can use the blockdev command to perform this task.

$ sudo blockdev --rereadpt -v /dev/sdb

Use the following dmesg command to see the kernel changes. Yes, i can see the changes because there is a new log again for sdb device in the dmesg.

$ dmesg | grep sdb
[    3.143163] sd 3:0:0:0: [sdb] 20971520 512-byte logical blocks: (10.7 GB/10.0 GiB)
[    3.143186] sd 3:0:0:0: [sdb] Write Protect is off
[    3.143192] sd 3:0:0:0: [sdb] Mode Sense: 00 3a 00 00
[    3.143276] sd 3:0:0:0: [sdb] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA
[    3.145620] sd 3:0:0:0: [sdb] Attached SCSI disk
[  188.810583]  sdb: sdb1 sdb2 sdb3 sdb4 < sdb5 >
[  219.112109]  sdb: sdb1 sdb2 sdb3 sdb4 < sdb5 >
[  422.506376]  sdb: sdb1 sdb2 sdb3 sdb4 < sdb5 >

How To Reload partition table in Linux Using hdparm Command

hdparm provides a command line interface to various kernel interfaces supported by the Linux SATA/PATA/SAS “libata” subsystem and the older IDE driver subsystem.

Alternatively, we can use hdparm command to perform this task.

$ sudo hdparm -z /dev/sdb

/dev/sdb:
 re-reading partition table

Use the following dmesg command to see the kernel changes. Yes, i can see the changes because there is a new log again for sdb device in the dmesg.

$ dmesg | grep sdb
[    3.143163] sd 3:0:0:0: [sdb] 20971520 512-byte logical blocks: (10.7 GB/10.0 GiB)
[    3.143186] sd 3:0:0:0: [sdb] Write Protect is off
[    3.143192] sd 3:0:0:0: [sdb] Mode Sense: 00 3a 00 00
[    3.143276] sd 3:0:0:0: [sdb] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA
[    3.145620] sd 3:0:0:0: [sdb] Attached SCSI disk
[  188.810583]  sdb: sdb1 sdb2 sdb3 sdb4 < sdb5 >
[  219.112109]  sdb: sdb1 sdb2 sdb3 sdb4 < sdb5 >
[  422.506376]  sdb: sdb1 sdb2 sdb3 sdb4 < sdb5 >
[  504.328312]  sdb: sdb1 sdb2 sdb3 sdb4 < sdb5 >

How To Reload partition table in Linux Using partx Command

partx is telling the kernel about presence and numbering of on-disk partitions.

The partx command is part of the util-linux package and is available from Linux Kernel Archive.

Alternatively, we can use partx command to perform this task.

$ sudo partx -a /dev/sdb
or
$ sudo partx -u /dev/sdb
partx: /dev/sdb: error adding partitions 1-5

You can double confirm this by running the following command. If the partition table is successfully reloaded and it’s visible to the kernel then you can able to see those new partitions in this location.

$ cat /proc/partitions
major minor  #blocks  name

   8        0   31457280 sda
   8        1   31455232 sda1
   8       16   10485760 sdb
   8       17    1048576 sdb1
   8       18     512000 sdb2
   8       19     512000 sdb3
   8       20          1 sdb4
   8       21    1048576 sdb5
   8       32   10485760 sdc

The same information can be found using the following ls command.

$ ls -l /dev/sdb*
brw-rw---- 1 root disk 8, 16 Mar  8 07:23 /dev/sdb
brw-rw---- 1 root disk 8, 17 Mar  8 07:23 /dev/sdb1
brw-rw---- 1 root disk 8, 18 Mar  8 07:23 /dev/sdb2
brw-rw---- 1 root disk 8, 19 Mar  8 07:23 /dev/sdb3
brw-rw---- 1 root disk 8, 20 Mar  8 07:23 /dev/sdb4
brw-rw---- 1 root disk 8, 21 Mar  8 07:23 /dev/sdb5

The same information can be found using the following partx command.

$ sudo partx -l /dev/sdb
# 1:      2048-  2099199 (  2097152 sectors,   1073 MB)
# 2:   2099200-  3123199 (  1024000 sectors,    524 MB)
# 3:   3123200-  4147199 (  1024000 sectors,    524 MB)
# 4:   4147200- 20971519 ( 16824320 sectors,   8614 MB)
# 5:   4149248-  6246399 (  2097152 sectors,   1073 MB)

Magesh Maruthamuthu

Love to play with all Linux distribution

You may also like...

Shares
Close
Please support the site
By clicking any of these buttons you help our site to get better