All of lore.kernel.org
 help / color / mirror / Atom feed
* please add support for os-prober to detect other OSes in update-grub
@ 2008-01-24 12:25 Fabian Greffrath
  2008-01-24 15:47 ` Bug#461442: " Otavio Salvador
  0 siblings, 1 reply; 5+ messages in thread
From: Fabian Greffrath @ 2008-01-24 12:25 UTC (permalink / raw)
  To: grub-devel; +Cc: 461442

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

Dear GRUB-developers,

I recently had a discussion with the GRUB-maintainers in Debian if it 
will be possible to add other (maybe proprietary, preinstalled) OSes to 
the GRUB boot menu when update-grub is run [1]. This happens 
automatically when Debian is installed (via the Debian-Installer) using 
a tool called 'os-prober'. This tool mounts all possible partitions and 
reports if it finds an OS on these partitions. This means it should be 
possible to run 'os-prober' and interpret it's output to generate 
further GRUB menu entries every time update-grub is started. For this 
purpose, please find my approach for an /etc/grub.d/30_os-prober script 
attached. It is only 1.5 kB, tab-indented and full of comments and 
paranoid tests. If it is considered usefull, though, I'd like to hand it 
over (including copyright!) to the GRUB-developers.

At the moment there is still one problem left: os-prober returns the 
partition on which it finds the OS as a system device name, e.g. 
/dev/hda2. At the moment, GRUB does not provide an (easy) way to 
translate these into GRUB drives, e.g. (hd0,1). This is why I allready 
requested such a feature on this list [2].
Another problem (or: missing feature) is, that at the moment my script 
can only add chainloaded OSes to grub.cfg. To add kernels like Linux or 
HURD it is necessary to mount these partitions again to find out exactly 
where the kernel and initrd images reside. This is something I want to 
avoid, because the partitions have allready been mounted by os-prober 
and I don't want to duplicate it's code for this purpose. Maybe 
os-prober could be modified to be more verbose in such cases and report 
the entire path to the images.

You may consider this a very Debian specific problem/feature, but I 
believe once os-prober finds more attention by other Linux distributions 
it will provide a very valuable means to automatically detect other OSes 
and add them to the boot menu.

Cheers,
Fabian

[1] http://bugs.debian.org/461442
[2] http://lists.gnu.org/archive/html/grub-devel/2008-01/msg00446.html
http://bugs.debian.org/462218

-- 
Dipl.-Phys. Fabian Greffrath

Ruhr-Universität Bochum
Lehrstuhl für Energieanlagen und Energieprozesstechnik (LEAT)
Universitätsstr. 150, IB 3/134
D-44780 Bochum

Telefon: +49 (0)234 / 32-26334
Fax:     +49 (0)234 / 32-14227
E-Mail:  greffrath@leat.ruhr-uni-bochum.de


[-- Attachment #2: 30_os-prober --]
[-- Type: text/plain, Size: 1582 bytes --]

#! /bin/sh -e

# update-grub helper script.
# <insert copyright and license blurb here>

if [ -x "`which os-prober 2>/dev/null`" ] ; then
	# os-prober output contains the partition and the name, a label and
	# a boot keyword, separated by colons (:) for each detected OS.
	# It may contain space characters and linebreaks,
	# e.g. "/dev/hda2:Windows XP Professional:Windows:chain".
	# Convert space characters to underscores and linebreaks to spaces.
	RESULT="`os-prober | tr ' ' '_' | tr '\n' ' '`"
fi

if [ "x${RESULT}" != "x" ] ; then
	for OS in "${RESULT}" ; do
		# e.g. "/dev/hda2:Windows_XP_Professional:Windows:chain"
		PARTITION="`echo ${OS} | cut -d ':' -f 1`"
		LONGNAME="`echo ${OS} | cut -d ':' -f 2 | tr '_' ' '`"
		LABEL="`echo ${OS} | cut -d ':' -f 3`"
		BOOT="`echo ${OS} | cut -d ':' -f 4`"

		if [ "x${LONGNAME}" = "x" ] ; then
			# is this likely to happen?
			LONGNAME="${LABEL}"
		fi

		case "${BOOT}" in
			chain)
				echo "Found ${LONGNAME} on ${PARTITION}" >&2
				if [ -x "`which grub-probe 2>/dev/null`" ] ; then
					# need to convert partition device to GRUB drive here!
					GRUB_DEVICE="`grub-probe --something ${PARTITION}`"
					cat << EOF
menuentry "${LONGNAME} (on ${PARTITION})" {
	set root=${GRUB_DEVICE}
	chainloader +1
}
EOF
				else # wtf?!
					echo "  Error: Missing grub-probe!" >&2
				fi
			;;
			macos|macosx)
				# can't macos* also be chainloaded?
			;;
			hurd|linux)
				# other Linux/HURD-Systems are not (yet) supported
				# with the given output of os-prober
			;;
			*)
				# is it possible to reach here?
			;;
		esac
	done
fi

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

* Re: Bug#461442: please add support for os-prober to detect other OSes in update-grub
  2008-01-24 12:25 please add support for os-prober to detect other OSes in update-grub Fabian Greffrath
@ 2008-01-24 15:47 ` Otavio Salvador
  2008-01-25  9:39   ` Fabian Greffrath
  0 siblings, 1 reply; 5+ messages in thread
From: Otavio Salvador @ 2008-01-24 15:47 UTC (permalink / raw)
  To: Fabian Greffrath; +Cc: grub-devel, 461442

Fabian Greffrath <greffrath@leat.rub.de> writes:

> At the moment there is still one problem left: os-prober returns the
> partition on which it finds the OS as a system device name,
> e.g. /dev/hda2. At the moment, GRUB does not provide an (easy) way to
> translate these into GRUB drives, e.g. (hd0,1). This is why I allready
> requested such a feature on this list [2].
> Another problem (or: missing feature) is, that at the moment my script
> can only add chainloaded OSes to grub.cfg. To add kernels like Linux
> or HURD it is necessary to mount these partitions again to find out
> exactly where the kernel and initrd images reside. This is something I
> want to avoid, because the partitions have allready been mounted by
> os-prober and I don't want to duplicate it's code for this
> purpose. Maybe os-prober could be modified to be more verbose in such
> cases and report the entire path to the images.

os-prober is developed inside Debian Installer team.

I think it's two different but reports and then it would be nice to
report a specific bug (maybe with a proposed patch) for os-prober to
provide what you'd need and then we can push it.

-- 
        O T A V I O    S A L V A D O R
---------------------------------------------
 E-mail: otavio@debian.org      UIN: 5906116
 GNU/Linux User: 239058     GPG ID: 49A5F855
 Home Page: http://otavio.ossystems.com.br
---------------------------------------------
"Microsoft sells you Windows ... Linux gives
 you the whole house."



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

* Re: Bug#461442: please add support for os-prober to detect other OSes in update-grub
  2008-01-24 15:47 ` Bug#461442: " Otavio Salvador
@ 2008-01-25  9:39   ` Fabian Greffrath
  2008-01-25 13:21     ` Robert Millan
  0 siblings, 1 reply; 5+ messages in thread
From: Fabian Greffrath @ 2008-01-25  9:39 UTC (permalink / raw)
  To: Otavio Salvador; +Cc: grub-devel, Robert Millan, 461442

Otavio Salvador schrieb:
> os-prober is developed inside Debian Installer team.
>
> I think it's two different but reports and then it would be nice to
> report a specific bug (maybe with a proposed patch) for os-prober to
> provide what you'd need and then we can push it.

I believe the issue is even easier to solve. I simply need to run 
'linux-boot-prober' (in the same package as os-prober, it seems I am 
blinded) on the partition for which the 'linux' boot keyword is reported 
and interpret it's output. Expect more work on this next week. I am 
sorry I cannot test my script drafts, because I have no other *nix 
besides Debian on my machine (the first of The Ten Commandments). ;)

Cheers,

-- 
Dipl.-Phys. Fabian Greffrath

Ruhr-Universität Bochum
Lehrstuhl für Energieanlagen und Energieprozesstechnik (LEAT)
Universitätsstr. 150, IB 3/134
D-44780 Bochum

Telefon: +49 (0)234 / 32-26334
Fax:     +49 (0)234 / 32-14227
E-Mail:  greffrath@leat.ruhr-uni-bochum.de




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

* Re: Bug#461442: please add support for os-prober to detect other OSes in update-grub
  2008-01-25  9:39   ` Fabian Greffrath
@ 2008-01-25 13:21     ` Robert Millan
  2008-01-30 10:48       ` Fabian Greffrath
  0 siblings, 1 reply; 5+ messages in thread
From: Robert Millan @ 2008-01-25 13:21 UTC (permalink / raw)
  To: Fabian Greffrath; +Cc: grub-devel, Otavio Salvador, 461442

On Fri, Jan 25, 2008 at 10:39:14AM +0100, Fabian Greffrath wrote:
> Otavio Salvador schrieb:
> >os-prober is developed inside Debian Installer team.
> >
> >I think it's two different but reports and then it would be nice to
> >report a specific bug (maybe with a proposed patch) for os-prober to
> >provide what you'd need and then we can push it.
> 
> I believe the issue is even easier to solve. I simply need to run 
> 'linux-boot-prober' (in the same package as os-prober, it seems I am 
> blinded) on the partition for which the 'linux' boot keyword is reported 
> and interpret it's output. Expect more work on this next week. I am 
> sorry I cannot test my script drafts, because I have no other *nix 
> besides Debian on my machine (the first of The Ten Commandments). ;)

You could try with qemu.

-- 
Robert Millan

<GPLv2> I know my rights; I want my phone call!
<DRM> What use is a phone call… if you are unable to speak?
(as seen on /.)



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

* Re: Bug#461442: please add support for os-prober to detect other OSes in update-grub
  2008-01-25 13:21     ` Robert Millan
@ 2008-01-30 10:48       ` Fabian Greffrath
  0 siblings, 0 replies; 5+ messages in thread
From: Fabian Greffrath @ 2008-01-30 10:48 UTC (permalink / raw)
  To: Robert Millan; +Cc: grub-devel, Otavio Salvador, 461442

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

Robert Millan schrieb:
> You could try with qemu.
Update:
I tried with Knoppix on a computer that has Debian sid and Windows XP 
installed. The attached script did it's job well - of course except for 
the part when it has to convert Linux device names to GRUB drives (see 
#462218). Support for HURD is still outstanding, though.

Cheers,
Fabian

-- 
Dipl.-Phys. Fabian Greffrath

Ruhr-Universität Bochum
Lehrstuhl für Energieanlagen und Energieprozesstechnik (LEAT)
Universitätsstr. 150, IB 3/134
D-44780 Bochum

Telefon: +49 (0)234 / 32-26334
Fax:     +49 (0)234 / 32-14227
E-Mail:  greffrath@leat.ruhr-uni-bochum.de


[-- Attachment #2: 30_os-prober --]
[-- Type: text/plain, Size: 2014 bytes --]

#! /bin/sh -e

# update-grub helper script.
# <insert copyright and license blurb here>

convert_device_to_grub_drive () {
  # you know what's missing here...
  echo $1
}

if [ -x "`which os-prober 2>/dev/null`" ] ; then
  OSPROBED="`os-prober | tr ' ' '|' | paste -s -d ' '`"
fi

if [ -n "${OSPROBED}" ] ; then
  for OS in ${OSPROBED} ; do
    DEVICE="`echo ${OS} | cut -d ':' -f 1`"
    LONGNAME="`echo ${OS} | cut -d ':' -f 2 | tr '|' ' '`"
    LABEL="`echo ${OS} | cut -d ':' -f 3 | tr '|' ' '`"
    BOOT="`echo ${OS} | cut -d ':' -f 4`"

    if [ -z "${LONGNAME}" ] ; then
      LONGNAME="${LABEL}"
    fi

    echo "Found ${LONGNAME} on ${DEVICE}" >&2

    case "${BOOT}" in
      chain)
        CHAINROOT="`convert_device_to_grub_drive ${DEVICE}`"

        cat << EOF
menuentry "${LONGNAME} (on ${DEVICE})" {
	set root=${CHAINROOT}
	chainloader +1
}
EOF
      ;;
      linux)
        if [ -x "`which linux-boot-prober 2>/dev/null`" ] ; then
          LINUXPROBED="`linux-boot-prober ${DEVICE} | tr ' ' '|' | paste -s -d ' '`"
        fi

        if [ -n "${LINUXPROBED}" ] ; then
          for LINUX in ${LINUXPROBED} ; do
            LROOT="`echo ${LINUX} | cut -d ':' -f 1`"
            LBOOT="`echo ${LINUX} | cut -d ':' -f 2`"
            LLABEL="`echo ${LINUX} | cut -d ':' -f 3 | tr '|' ' '`"
            LKERNEL="`echo ${LINUX} | cut -d ':' -f 4`"
            LINITRD="`echo ${LINUX} | cut -d ':' -f 5`"
            LPARAMS="`echo ${LINUX} | cut -d ':' -f 6 | tr '|' ' '`"

            LINUXROOT="`convert_device_to_grub_drive ${LBOOT}`"

            if [ -z "${LLABEL}" ] ; then
              LLABEL="${LONGNAME}"
            fi

            cat << EOF
menuentry "${LLABEL} (on ${DEVICE})" {
	set root=${LINUXROOT}
	linux ${LKERNEL} ${LPARAMS}
EOF
            if [ -n "${LINITRD}" ] ; then
              cat << EOF
	initrd ${LINITRD}
EOF
            fi
            cat << EOF
}
EOF
          done
        fi
      ;;
      hurd)
        # not yet...
      ;;
      *)
      ;;
    esac
  done
fi

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

end of thread, other threads:[~2008-01-30 10:48 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-01-24 12:25 please add support for os-prober to detect other OSes in update-grub Fabian Greffrath
2008-01-24 15:47 ` Bug#461442: " Otavio Salvador
2008-01-25  9:39   ` Fabian Greffrath
2008-01-25 13:21     ` Robert Millan
2008-01-30 10:48       ` Fabian Greffrath

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.