How does partprobe work?
Partprobe calls the BLKRRPART
ioctl, which is documented in, err, include/linux/fs.h
, and beyond that the kernel source (the meat is in rescan_partitions()
):
#define BLKRRPART _IO(0x12,95) /* re-read partition table */
The easiest way to find this out is to run strace -e raw=ioctl -e open,ioctl partprobe /dev/sdb
.
I think what you tried with /sys/*/*scan
tells the kernel to check if there's been a change of drive. That doesn't help if the drive hasn't changed (or has been hotswapped in a way that the kernel doesn't detect?) but the partition structure on it has changed.
Related videos on Youtube
Matt Simmons
8+ years administering small/medium networks 12+ years of Linux experience I've been a blogger for about a year now, and have made a lot of friends and learned an amazing amount. I think that as a sysadmin, you need to learn from every opportunity, and this site is an excellent resource for that.
Updated on September 17, 2022Comments
-
Matt Simmons over 1 year
I was looking for a way to refresh the scsi bus (or any other bus, for that matter) that would allow my kernel ( 2.6.18-194-el5 on CentOS 5.5) to know about the partitions on a drive, and I couldn't find a way. partprobe did it instantly. How?
Since it's important, here's what I was doing:
I wanted to get some practice in partition-specific things like resizing, backing up the MBR and restoring it, and so on. I had created a 20GB partition on /dev/sdb, backed up the MBR:
dd if=/dev/sdb of=sdb.mbr bs=512 count=1
then I went into fdisk, deleted the partition, wrote it, and exited.
ls /dev/sdb*
showed that there was no partition, and
fdisk -l /dev/sdb'
matched, so I figured I was good.
I then reversed the dd:
dd if=sdb.mbr of=/dev/sdb bs=512 count=1
Of course, I didn't do anything at that point, so
ls /dev/sdb*
didn't list any partitions, but
fdisk -l
showed the partition, presumably because it reads the first 512 bytes on the disk and doesn't rely on the kernel. I knew that I'd have to refresh the bus, so I went into into /sys/class/scsi_host/host1, and did
echo "- - -" > scan
and doing
ls /dev/sdb
didn't show anything new, so then I went to /sys/bus/scsi/devices and for each of the listed devices, I did
echo 1 > rescan
and that didn't work.
I then did more research on the problem, and came across 'partprobe', which comes with parted. I ran it, and it worked instantly.
If I don't get a likely answer here, I'm probably going to just go get the source and look it up, but I figure there are wizards here beyond me, so I thought I'd appeal to you all.