All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Skip partitions during OS probing
@ 2011-07-09 21:43 Axel Kellermann
  2011-07-11 15:13 ` Phillip Susi
  0 siblings, 1 reply; 7+ messages in thread
From: Axel Kellermann @ 2011-07-09 21:43 UTC (permalink / raw)
  To: grub-devel

[-- Attachment #1: Type: text/plain, Size: 1294 bytes --]

Hello devels,

I attached a patch I use on my machine to skip certain predefined
partitions during OS probing by grub-mkconfig/30_os-prober. I started to
work on this as grub2 adds the Win7 system partition of my dual-booted
laptop to the boot menu, although only Win7s boot partition is actually
needed. Not a big error, but it bugged me... ;)
But apart from this special case on my machine, I think it is handy to
have a standardized way to exclude certain partitions from being
auto-probed during execution of update-grub.

The patch updates two files. grub-mkconfig.in now exports an additional
user variable called GRUB_SKIP_PARTITIONS, 30_os-prober.in adds a few
lines to check whether the currently probed partition is contained in
GRUB_SKIP_PARTITIONS, and if so, skips addition of the boot menu entry.

To skip one ore more partitions during OS probing, the user has to add
the variable GRUB_SKIP_PARTITIONS to the grub config file
(/etc/default/grub) and provide it with a space delimited list of
partition names (e.g. GRUB_SKIP_PARTITIONS="sda2 sdb3").

I created the patch with the command 'bzr patch -p1'. If that is not the
correct way, please let me know. I'm also open for suggestions on
improving the patch.


Please let me know what you think,
thanks for the good work,

Axel

[-- Attachment #2: skip_partitions.patch --]
[-- Type: text/x-diff, Size: 1039 bytes --]

=== modified file 'util/grub-mkconfig.in'
--- old/util/grub-mkconfig.in	2011-07-07 21:52:58 +0000
+++ new/util/grub-mkconfig.in	2011-07-09 21:08:25 +0000
@@ -257,7 +257,8 @@
   GRUB_INIT_TUNE \
   GRUB_SAVEDEFAULT \
   GRUB_ENABLE_CRYPTODISK \
-  GRUB_BADRAM
+  GRUB_BADRAM \
+  GRUB_SKIP_PARTITIONS
 
 if test "x${grub_cfg}" != "x"; then
   rm -f ${grub_cfg}.new

=== modified file 'util/grub.d/30_os-prober.in'
--- old/util/grub.d/30_os-prober.in	2011-07-02 19:22:19 +0000
+++ new/util/grub.d/30_os-prober.in	2011-07-09 21:06:32 +0000
@@ -94,6 +94,12 @@
   LONGNAME="`echo ${OS} | cut -d ':' -f 2 | tr '^' ' '`"
   LABEL="`echo ${OS} | cut -d ':' -f 3 | tr '^' ' '`"
   BOOT="`echo ${OS} | cut -d ':' -f 4`"
+  PARTITION="`echo ${DEVICE} | grep -o '[^\/]\+$'`"
+
+  if [ "x${GRUB_SKIP_PARTITIONS}" != "x" -a "x`echo ${GRUB_SKIP_PARTITIONS} | grep -e '\b'${PARTITION}'\b'`" != "x" ] ; then
+    echo "Skipped ${LONGNAME} on ${DEVICE} by user request." >&2
+    continue
+  fi
 
   if [ -z "${LONGNAME}" ] ; then
     LONGNAME="${LABEL}"


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] Skip partitions during OS probing
  2011-07-09 21:43 [PATCH] Skip partitions during OS probing Axel Kellermann
@ 2011-07-11 15:13 ` Phillip Susi
  2011-07-11 15:55   ` Axel Kellermann
  0 siblings, 1 reply; 7+ messages in thread
From: Phillip Susi @ 2011-07-11 15:13 UTC (permalink / raw)
  To: The development of GNU GRUB; +Cc: Axel Kellermann

On 7/9/2011 5:43 PM, Axel Kellermann wrote:
> To skip one ore more partitions during OS probing, the user has to add
> the variable GRUB_SKIP_PARTITIONS to the grub config file
> (/etc/default/grub) and provide it with a space delimited list of
> partition names (e.g. GRUB_SKIP_PARTITIONS="sda2 sdb3").

Partition numbers tend to get moved around quite frequently, so this 
would be a fragile configuration, and require manual entry.  It would be 
better to automatically notice that the partition is a Win7 system 
partition, and ignore it.  If you must explicitly exclude manually 
chosen partitions, they should be specified by UUID.



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] Skip partitions during OS probing
  2011-07-11 15:13 ` Phillip Susi
@ 2011-07-11 15:55   ` Axel Kellermann
  2011-07-11 18:25     ` Lennart Sorensen
  2011-07-11 20:21     ` Phillip Susi
  0 siblings, 2 replies; 7+ messages in thread
From: Axel Kellermann @ 2011-07-11 15:55 UTC (permalink / raw)
  To: grub-devel; +Cc: Phillip Susi

> Partition numbers tend to get moved around quite frequently, so this
> would be a fragile configuration, and require manual entry.  It would be
Good point. I guess the proposed solution works well with internal HDDs,
as they tend to always get the same device names during system
initialization (at least I never observed different behaviour on my
machine), but could be fragile for external drives.

> better to automatically notice that the partition is a Win7 system
I agree. But I guess on my machine it is not really grubs fault that the
Win7 system partition is marked as bootable. I only have one of those
Win7 licenses that come with recovery media, so I'm not able to do a
manual, clean install and it seems the recovery installation always
makes the system partition bootable. I'm probably not the only one
experiencing this kind of faulty setup...

> partition, and ignore it.  If you must explicitly exclude manually
> chosen partitions, they should be specified by UUID.
I guess we could work with UUIDs instead of partition names, but it also
turns this little patch into something a bit more complicated. I'd be
happy to look into it, but we should first decide if we really cover a
use-case here or if the whole thing isn't worth the effort.


Thanks,

Axel


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] Skip partitions during OS probing
  2011-07-11 15:55   ` Axel Kellermann
@ 2011-07-11 18:25     ` Lennart Sorensen
  2011-07-11 20:21       ` Axel Kellermann
  2011-07-11 20:21     ` Phillip Susi
  1 sibling, 1 reply; 7+ messages in thread
From: Lennart Sorensen @ 2011-07-11 18:25 UTC (permalink / raw)
  To: The development of GNU GRUB; +Cc: Phillip Susi

On Mon, Jul 11, 2011 at 05:55:53PM +0200, Axel Kellermann wrote:
> > Partition numbers tend to get moved around quite frequently, so this
> > would be a fragile configuration, and require manual entry.  It would be
> Good point. I guess the proposed solution works well with internal HDDs,
> as they tend to always get the same device names during system
> initialization (at least I never observed different behaviour on my
> machine), but could be fragile for external drives.

I have observed it on internal drives.  If you have two controllers with
different drivers and disks on both then there is no predicting which
driver will load and initiallize first in some cases.  Switching to UUIDs
made the box much more reliable to boot (it was a 50/50 chance it would
boot with the disks in the "right" order and work).

> > better to automatically notice that the partition is a Win7 system
> I agree. But I guess on my machine it is not really grubs fault that the
> Win7 system partition is marked as bootable. I only have one of those
> Win7 licenses that come with recovery media, so I'm not able to do a
> manual, clean install and it seems the recovery installation always
> makes the system partition bootable. I'm probably not the only one
> experiencing this kind of faulty setup...
> 
> > partition, and ignore it.  If you must explicitly exclude manually
> > chosen partitions, they should be specified by UUID.
> I guess we could work with UUIDs instead of partition names, but it also
> turns this little patch into something a bit more complicated. I'd be
> happy to look into it, but we should first decide if we really cover a
> use-case here or if the whole thing isn't worth the effort.

-- 
Len Sorensen


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] Skip partitions during OS probing
  2011-07-11 18:25     ` Lennart Sorensen
@ 2011-07-11 20:21       ` Axel Kellermann
  0 siblings, 0 replies; 7+ messages in thread
From: Axel Kellermann @ 2011-07-11 20:21 UTC (permalink / raw)
  To: The development of GNU GRUB; +Cc: Phillip Susi, Lennart Sorensen

[-- Attachment #1: Type: text/plain, Size: 1933 bytes --]

Turns out switching to UUIDs was very simple, grub already provides the
necessary utility function. :)

The new patch is attached.


Thanks,

Axel

On 07/11/2011 08:25 PM, Lennart Sorensen wrote:
> On Mon, Jul 11, 2011 at 05:55:53PM +0200, Axel Kellermann wrote:
>>> Partition numbers tend to get moved around quite frequently, so this
>>> would be a fragile configuration, and require manual entry.  It would be
>> Good point. I guess the proposed solution works well with internal HDDs,
>> as they tend to always get the same device names during system
>> initialization (at least I never observed different behaviour on my
>> machine), but could be fragile for external drives.
> 
> I have observed it on internal drives.  If you have two controllers with
> different drivers and disks on both then there is no predicting which
> driver will load and initiallize first in some cases.  Switching to UUIDs
> made the box much more reliable to boot (it was a 50/50 chance it would
> boot with the disks in the "right" order and work).
> 
>>> better to automatically notice that the partition is a Win7 system
>> I agree. But I guess on my machine it is not really grubs fault that the
>> Win7 system partition is marked as bootable. I only have one of those
>> Win7 licenses that come with recovery media, so I'm not able to do a
>> manual, clean install and it seems the recovery installation always
>> makes the system partition bootable. I'm probably not the only one
>> experiencing this kind of faulty setup...
>>
>>> partition, and ignore it.  If you must explicitly exclude manually
>>> chosen partitions, they should be specified by UUID.
>> I guess we could work with UUIDs instead of partition names, but it also
>> turns this little patch into something a bit more complicated. I'd be
>> happy to look into it, but we should first decide if we really cover a
>> use-case here or if the whole thing isn't worth the effort.

[-- Attachment #2: skip_partitions_uuid.patch --]
[-- Type: text/x-diff, Size: 1043 bytes --]

=== modified file 'util/grub-mkconfig.in'
--- old/util/grub-mkconfig.in	2011-07-07 21:52:58 +0000
+++ new/util/grub-mkconfig.in	2011-07-09 21:08:25 +0000
@@ -257,7 +257,8 @@
   GRUB_INIT_TUNE \
   GRUB_SAVEDEFAULT \
   GRUB_ENABLE_CRYPTODISK \
-  GRUB_BADRAM
+  GRUB_BADRAM \
+  GRUB_SKIP_PARTITIONS
 
 if test "x${grub_cfg}" != "x"; then
   rm -f ${grub_cfg}.new

=== modified file 'util/grub.d/30_os-prober.in'
--- old/util/grub.d/30_os-prober.in	2011-07-02 19:22:19 +0000
+++ new/util/grub.d/30_os-prober.in	2011-07-11 20:13:04 +0000
@@ -94,6 +94,12 @@
   LONGNAME="`echo ${OS} | cut -d ':' -f 2 | tr '^' ' '`"
   LABEL="`echo ${OS} | cut -d ':' -f 3 | tr '^' ' '`"
   BOOT="`echo ${OS} | cut -d ':' -f 4`"
+  UUID="`grub-probe --target=fs_uuid --device ${DEVICE}`"
+
+  if [ "x${GRUB_SKIP_PARTITIONS}" != "x" -a "x`echo ${GRUB_SKIP_PARTITIONS} | grep -i -e '\b'${UUID}'\b'`" != "x" ] ; then
+    echo "Skipped ${LONGNAME} on ${DEVICE} by user request." >&2
+    continue
+  fi
 
   if [ -z "${LONGNAME}" ] ; then
     LONGNAME="${LABEL}"


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] Skip partitions during OS probing
  2011-07-11 15:55   ` Axel Kellermann
  2011-07-11 18:25     ` Lennart Sorensen
@ 2011-07-11 20:21     ` Phillip Susi
  2011-07-18 18:06       ` Axel Kellermann
  1 sibling, 1 reply; 7+ messages in thread
From: Phillip Susi @ 2011-07-11 20:21 UTC (permalink / raw)
  To: Axel Kellermann; +Cc: grub-devel

On 7/11/2011 11:55 AM, Axel Kellermann wrote:
> Good point. I guess the proposed solution works well with internal HDDs,
> as they tend to always get the same device names during system
> initialization (at least I never observed different behaviour on my
> machine), but could be fragile for external drives.

If you only have one controller, then the disks will tend to be 
enumerated in the same order each time, but many people have multiple 
controllers these days so the order jumbles around quite a bit.  Often 
times a USB flash stick can be detected first and get sda, bumping the 
internal hard disks down.

Even if you only have one controller, sometimes a drive can take a 
little longer to spin up and one of the other drives can finish being 
detected first.

> I guess we could work with UUIDs instead of partition names, but it also
> turns this little patch into something a bit more complicated. I'd be
> happy to look into it, but we should first decide if we really cover a
> use-case here or if the whole thing isn't worth the effort.

Fixing the underlying problem of detecting and ignoring the Win7 system 
partition would render the patch moot.  If it does really still cover a 
use-case to be able to manually specify partitions to ignore, it needs 
to be done with UUIDs or something else more stable.


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] Skip partitions during OS probing
  2011-07-11 20:21     ` Phillip Susi
@ 2011-07-18 18:06       ` Axel Kellermann
  0 siblings, 0 replies; 7+ messages in thread
From: Axel Kellermann @ 2011-07-18 18:06 UTC (permalink / raw)
  To: grub-devel; +Cc: Phillip Susi

On 07/11/2011 10:21 PM, Phillip Susi wrote:
> Fixing the underlying problem of detecting and ignoring the Win7 system
> partition would render the patch moot.  If it does really still cover a
> use-case to be able to manually specify partitions to ignore, it needs
> to be done with UUIDs or something else more stable.
Just to tie up that loose end, I had a look at the way update-grub
determines the presence of a bootable Win7 partition. Turns out it
utilizes the os-prober package, which basically uses a four step process
to check for a Win7 system:

1. check for presence of file /bootmgr
2. check for presence of directory /boot/
3. check for presence of file /boot/bcd
4. grep OS version string from file /boot/bcd

If all four steps succeed, the partition is classified as bootable and
update-grub writes a boot meny entry.

The Win7 system partition on my machine passes all the checks os-prober
does, but actually booting from that partition fails with an error
message. To solve this, os-prober would have to include some kind of
sanity check whether the bootloader configuration on the examined
partition is set up correctly and really boots the system. I'm not sure
if that is feasible and/or possible at all, and one could also argue
that it's up to the user to fix the faulty boot setup on the partition
and not blame grub/os-prober for detecting a messed up bootloader. :)

Thoughts?

BTW, I still think the patch covers a use-case and its functionality
could be handy.


Thanks,

Axel


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2011-07-18 18:06 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-07-09 21:43 [PATCH] Skip partitions during OS probing Axel Kellermann
2011-07-11 15:13 ` Phillip Susi
2011-07-11 15:55   ` Axel Kellermann
2011-07-11 18:25     ` Lennart Sorensen
2011-07-11 20:21       ` Axel Kellermann
2011-07-11 20:21     ` Phillip Susi
2011-07-18 18:06       ` Axel Kellermann

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.