Skip to contentSkip to conversation

try to reread partition table in 10_linux

PATCH In review Felix Zielcke 2 participants 3 messages Oct 28, 2009

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 try to reread partition table in 10_linux

/dev/disk/by-uuid seems to be only created when the partition table gets reread after a new filesystem has been created.
So here's a patch which does it with sfdisk.

I wasn't sure if some devices like e.g. /dev/mapper/* should be ignored. mdraid devices can have partitions so they should be tried too.

Signature · 2 lines
Felix Zielcke
Proud Debian Maintainer and GNU GRUB developer

2009-10-28 Felix Zielcke <[email protected]>

* util/grub.d/10_linux.in: Try to reread partition table with sfdisk before we check if UUIDs can be used.

grub.d/10_linux.in +7 -0
Index: util/grub.d/10_linux.in
===================================================================
@@ -35,6 +35,13 @@ case ${GRUB_DEVICE} in
   ;;
 esac
 
+# Try to reread partition table.  In case a fresh filesystem has been created
+# /dev/disk/by-uuid doestn't yet exist.
+if which sfdisk /dev/null ; then
+  GRUB_DEVICE_DISK=`echo ${GRUB_DEVICE} | sed -e "s/[0-9]*$//"`
+  sfdisk -R ${GRUB_DEVICE_DISK} 2>/dev/null
+fi
+
 if [ "x${GRUB_DEVICE_UUID}" = "x" ] || [ "x${GRUB_DISABLE_LINUX_UUID}" = "xtrue" ] \
     || ! test -e "/dev/disk/by-uuid/${GRUB_DEVICE_UUID}" ; then
   LINUX_ROOT_DEVICE=${GRUB_DEVICE}
#1 lore raw

grub.d/10_linux.in case ${GRUB_DEVICE} in · line 43

Quoted 4 lines · Felix Zielcke
grub.d/10_linux.in +4 -0
+if which sfdisk /dev/null ; then
+  GRUB_DEVICE_DISK=`echo ${GRUB_DEVICE} | sed -e "s/[0-9]*$//"`
+  sfdisk -R ${GRUB_DEVICE_DISK} 2>/dev/null
+fi

s/[0-9]*$// doesn't catch all partition path layouts. More heuristic is needed for that (we have this in util/hostdisk.c), but duplicating it doesn't sound like a good idea.

Can this be avoided altogether? E.g. by telling Linux the partition path instead, or by using another interface.

Signature · 5 lines
Robert Millan

  The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and
  how) you may access your data; but nobody's threatening your freedom: we
  still allow you to remove your data and not access it at all."
#2 lore raw

Am Donnerstag, den 29.10.2009, 00:00 +0100 schrieb Robert Millan:

Quoted 9 lines · Felix Zielcke

grub.d/10_linux.in case ${GRUB_DEVICE} in · line 43

Quoted 4 lines
grub.d/10_linux.in +4 -0
+if which sfdisk /dev/null ; then
+  GRUB_DEVICE_DISK=`echo ${GRUB_DEVICE} | sed -e "s/[0-9]*$//"`
+  sfdisk -R ${GRUB_DEVICE_DISK} 2>/dev/null
+fi

s/[0-9]*$// doesn't catch all partition path layouts. More heuristic is needed for that (we have this in util/hostdisk.c), but duplicating it doesn't sound like a good idea.

Oh right I forgot about e.g. the hardware RAID controllers.
Hm if grub-probe would accept a GRUB device, we could use 2 grub-probe calls to do that.
i.e. something like
tmp_drive=grub-probe -t drive -d ${GRUB_DEVICE} | sed -e 's/,[a-z0-9]//g' GRUB_DEVICE_DISK=grub-probe -t device ${tmp_drive}

Quoted 2 lines

Can this be avoided altogether? E.g. by telling Linux the partition path instead, or by using another interface.

I don't think we can:

$ LANG=C sudo sfdisk -R /dev/hda2
BLKRRPART: Invalid argument
I doubt the kernel provides more then one way to reread the partition
table.
Hm but maybe libparted or something else has a wrapper for this.
Signature · 2 lines
Felix Zielcke
Proud Debian Maintainer and GNU GRUB developer