1

So I've got an program that takes a device, partitions it and then creates the device node for the partition. The problem is, that the kernel does not pick up the device until some kind of rescan is forced. For ex.:

  • Partition device
  • Make node
  • cat node > cat: /dev/xxx: No such device or address

But this works:

  • Partition device
  • Make node
  • Run cfdisk /dev/xxx and exit instantly
  • cat node > Works fine

Why is this? Is there some kind of ioctl to re scan the SCSI bus or something?

And, this does not work:

echo "- - -" > /sys/class/scsi_host/hostX/scan
  • How are you partitioning the disk in the first place? – Stephen Harris Aug 8 '16 at 15:46
  • libparted. I figured it out. libparted has 2 calls to write info to disk. One is to commit to disk, the other is to commit to the kernel. I forgot the second one. More specifically, it is the called ped_disk_commit_to_os() – Gala Aug 8 '16 at 16:18
  • Yeah, the "commit to kernel" is the important part. Tools like fdisk will do this automatically. NOTE that if the disk is in use (eg the disk holding the root partition) then the kernel won't necessarily pick up the change. – Stephen Harris Aug 8 '16 at 16:19
  • Yup that was it. I'm partitioning external SCSI drives, so no worries. – Gala Aug 8 '16 at 16:21
1

Use partprobe /dev/xxx

partprobe is part of the parted package. From the man page:

partprobe is a program that informs the operating system kernel of partition table changes`

Another alternative if you have a partitioned block device (e.g. a disk image file) and you want to automatically create device nodes (e.g. /dev/loop*) for it AND inform the kernel, you can use kpartx. It's called automatically on hotplug events like inserting a USB or hot-swap SATA drive.

  • partprobe does nothing, except call ped_commit_to_os() for all SCSI drives. Look at the source code of partprobe. That is how I figured it out and implemented it. – Gala Aug 8 '16 at 23:00
  • in other words, it does what i said it does (and it only probes ALL drives if you don't give it any device args). If you want to know about specific programming language function calls rather than unix/linux command-line tools, you should mention that fact (as well as the language you're writing in). – cas Aug 8 '16 at 23:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.