All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Use os-prober to detect other OSes during update-grub
@ 2008-02-11  8:53 Fabian Greffrath
  0 siblings, 0 replies; 2+ messages in thread
From: Fabian Greffrath @ 2008-02-11  8:53 UTC (permalink / raw)
  To: The development of GRUB 2

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

The following is a script that should be installed into `/etc/grub.d/os-prober'.
It uses Debian's `os-prober' package (if installed) to detect other operating
systems which are installed on the computer and add them to the boot menu. It's
up to you to decide if this is too Debian-specific or if you'd like to have it
included in the upstream distribution of GRUB.

This script is improved over the one from my previous posting and has some minor
issues fixed. Please use this version instead. It is all my work.

@Robert: Refering to your question from Mon, 4 Feb 2008: I do not believe it is
possible to simplify the code with "echo something | read a b c d" because it
has to be '-f 6-' in the last step. Kernel parameters may of course contain
colons. I do not know if it is possible to implement this via "echo ... | read ...".




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

#! /bin/sh -e

# update-grub helper script.
# Copyright (C) 2006,2007,2008  Free Software Foundation, Inc.
#
# GRUB is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# GRUB is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GRUB.  If not, see <http://www.gnu.org/licenses/>.

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
    
    TESTDEVICE="`grub-probe --target=device $0`"
    if [ -n "`grub-probe --target=drive --device ${TESTDEVICE} 2>/dev/null`" ] ; then
      case "${BOOT}" in
        chain)
          CHAINROOT="`grub-probe --target=drive --device ${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="`grub-probe --target=drive --device ${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
    fi
  done
fi



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

* Re: [PATCH] Use os-prober to detect other OSes during update-grub
@ 2008-02-11  9:34 Fabian Greffrath
  0 siblings, 0 replies; 2+ messages in thread
From: Fabian Greffrath @ 2008-02-11  9:34 UTC (permalink / raw)
  To: The development of GRUB 2

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

I should not forget to say that this script *depends* on the patch I sent in for 
grub-probe in my previous mail.

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

#! /bin/sh -e

# update-grub helper script.
# Copyright (C) 2006,2007,2008  Free Software Foundation, Inc.
#
# GRUB is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# GRUB is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GRUB.  If not, see <http://www.gnu.org/licenses/>.

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
    
    TESTDEVICE="`grub-probe --target=device $0`"
    if [ -n "`grub-probe --target=drive --device ${TESTDEVICE} 2>/dev/null`" ] ; then
      case "${BOOT}" in
        chain)
          CHAINROOT="`grub-probe --target=drive --device ${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="`grub-probe --target=drive --device ${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
    fi
  done
fi




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

end of thread, other threads:[~2008-02-11  9:34 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-02-11  9:34 [PATCH] Use os-prober to detect other OSes during update-grub Fabian Greffrath
  -- strict thread matches above, loose matches on Subject: below --
2008-02-11  8:53 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.