- How to Reload partition table without Reboot in Linux
- 1) Reloading partition table in Linux with partprobe command
- 2) How to reload partition table without system reboot in Linux using blockdev command
- 3) Reloading partition table in Linux using hdparm command
- 4) Reload Partition table without reboot in Linux using partx command
- Closing Notes
- Thread: write bootsector, make partition active
- write bootsector, make partition active
How to Reload partition table without Reboot in Linux
As a Linux administrator you might perform a disk partition task quite often. Most of the time the partition table will be altered successfully after the disk partition in the virtual environments (such as VMWare, Virtualbox, etc).
But things do not go as planned every time, because sometimes your system doesn’t alter the partition table with new disk information, which often happens in physical systems. If so, what is the solution to inform the OS about partition table changes?
There is a solution to this. However, we can not guarantee that it will work 100%, but it will work most of the time as per my experience and knowledge.
These commands are to: 1) force the Kernel to reload the partition table and 2)re-populate its ids in /dev.
In Linux, disk partitioning can be done using multiple commands and most users prefer to use fdisk or parted. Please choose the desired command based on your need.
Visit to the following URLs to learn more about disk partitions:
Most of the time you can get the output below in virtual environment when you are performing the disk partitions:
The partition table has been altered. Syncing disks.
At the same time when you make disk partitions, you may get the below output in the physical environment:
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 four commands on Arch Linux system and all are working fine except ‘partx’ command, because I didn’t find any information about the partition change in the ‘dmesg’ log after running the partx command.
However, the partx command works as expected on 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 the partition table changes.
In this guide, we’ll show you how to re-load partition table without reboot in Linux using the following four commands:
- 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 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.
1) Reloading partition table in Linux with partprobe command
partprobe is a program that informs the operating system kernel of partition table changes, by requesting the operating system to re-read the partition table. For instance, if you create a new partition on one of your disks using parted command, you should run partprobe afterwards to make the kernel aware of the new partition configuration.
This is standard and native command to perform this task.
In this example, we will use /dev/sdb to demonstrate this. Please make sure to input your device name instead of ours in the command below:
dmesg is used to examine or control the kernel ring buffer. So, use the following command to see the kernel changes. And indeed, i can saw the changes in my test run, 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
2) How to reload partition table without system reboot in Linux using blockdev command
The utility blockdev allows us to call block device ioctls from the command line.
We can use the blockdev command to perform this task as shown below:
$ sudo blockdev --rereadpt -v /dev/sdb
Use the following dmesg command to see the kernel changes.
And I was able to see the changes in my test run, 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
3) Reloading 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 as shown below:
$ sudo hdparm -z /dev/sdb /dev/sdb: re-reading partition table
Use the following dmesg command to see the kernel changes:
And, I could see the changes in my test run, 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
4) Reload Partition table without reboot in Linux using partx command
partx is telling the kernel about the presence as well as the numbering of on-disk partitions.
The partx command is part of the util-linux package and is available from Linux Kernel Archive.
As an alternate, we can use partx command to perform this task as shown below:
$ sudo partx -a /dev/sdb or $ sudo partx -u /dev/sdb partx: /dev/sdb: error adding partitions 1-5
You can confirm this by running the following command. If the partition table is successfully reloaded and it’s visible to the kernel, then you should be 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
And the same information can also 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)
Closing Notes
In this guide, we have shown you four commands to reload partition table without system Reboot in Linux.
If you have any questions or feedback, feel free to comment below. Happy learning!
Thread: write bootsector, make partition active
First Cup of Ubuntu
write bootsector, make partition active
Playing around with Ubuntu, I managed to mess up the partitions for my MSI Wind such that I cannot boot into Windows, or even run the recovery partition utility. I asked about my problem on a MSI-specific forum, and this was the reply.
«The recovery partition is crap.
It only operates if the second partition on the drive is NTFS and has a valid xp boot sector.
Otherwise, it will just reboot.
You will need a linux live cd most likely to fix this.
Create a primary NTFS partition as second partition. Set it active. Use whatever means you can to write a bootsector to it. Then the recovery partition will suceed in restoring your C drive partition. After doing this, you want to get the recovery disc made by BUrnRecovery onto a usb drive. At this point, you can restore not only your wind if you screw it up again, but any other of the same model.»
How do I do this is in Ubuntu? The second partition is NTFS, but I’m not sure how I would write a bootsector to the NTFS partition, or how that would interact with GRUB. I’m also not sure what it means to set a partition «active.»
I’m not experienced with Linux beyond the gui and basic command line operations, so messing with boot sectors is unfortunately out of my reach at the moment. Any help would be appreciated.