10

When I want Linux to consider newly created partitions without rebooting, I have several tools available to force a refresh of the kernel "partition cache":

  • partx -va /dev/sdX
  • kpartx -va /dev/sdX
  • hdparm -z /dev/sdX
  • blockdev --rereadpt /dev/sdX
  • sfdisk -R /dev/sdX (deprecated)
  • partprobe /dev/sdX
  • ...

I'm not sure about the difference between these techniques, but I think they don't use the same ioctl, like BLKRRPART or BLKPG. So, what is the difference between those ioctl?

Totor
  • 20,040
  • Probably none at all. kpartx is derived from partx, sfdisk is another partition edit tool. hdparm is for other uses, but also has a way to read partition table into kernel. If you really need to know, then look at the source code. – ctrl-alt-delor Jul 09 '14 at 09:13

1 Answers1

9

BLKRRPART tells the kernel to reread the partition table. man 4 sd

With BLKPG you can create, add, delete partitions as you please (from the kernel, not on disk of course). You have to tell the kernel the offset and size of individual partition, which implies that you must have parsed the partition table yourself beforehand. See Linux kernel: /include/uapi/linux/blkpg.h

I personally use partprobe (part of parted), which uses the latter approach, probably to support partition tables not supported by the kernel.

John Kugelman
  • 2,057
  • 2
  • 16
  • 23
Rondom
  • 336