From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1KQ60g-0007Ag-J1 for mharc-grub-devel@gnu.org; Mon, 04 Aug 2008 15:46:26 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KQ60f-0007Ab-SQ for grub-devel@gnu.org; Mon, 04 Aug 2008 15:46:25 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KQ60e-0007AP-Db for grub-devel@gnu.org; Mon, 04 Aug 2008 15:46:24 -0400 Received: from [199.232.76.173] (port=45328 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KQ60e-0007AM-8y for grub-devel@gnu.org; Mon, 04 Aug 2008 15:46:24 -0400 Received: from mailout07.t-online.de ([194.25.134.83]:53860) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1KQ60d-0002ic-HV for grub-devel@gnu.org; Mon, 04 Aug 2008 15:46:24 -0400 Received: from fwd24.aul.t-online.de by mailout07.sul.t-online.de with smtp id 1KQ60a-0004An-02; Mon, 04 Aug 2008 21:46:20 +0200 Received: from [10.3.2.2] (GQhlzsZdrheFrMp-9xJ33lrd73bXrn+UV8XGjr6EnskfdiDESQfRvN7eVGd6VCvZTs@[217.235.244.166]) by fwd24.aul.t-online.de with esmtp id 1KQ60J-1FPog40; Mon, 4 Aug 2008 21:46:03 +0200 Message-ID: <48975C7B.7060803@t-online.de> Date: Mon, 04 Aug 2008 21:46:03 +0200 From: Christian Franke User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.16) Gecko/20080702 SeaMonkey/1.1.11 MIME-Version: 1.0 To: The development of GRUB 2 References: <4888E3C5.9090707@t-online.de> <4888E868.10404@t-online.de> <20080725204222.GE18149@thorin> <48922F66.4050803@t-online.de> In-Reply-To: <48922F66.4050803@t-online.de> Content-Type: multipart/mixed; boundary="------------060303000400070207000307" X-ID: GQhlzsZdrheFrMp-9xJ33lrd73bXrn+UV8XGjr6EnskfdiDESQfRvN7eVGd6VCvZTs X-TOI-MSGID: 45829ddc-5690-4f83-832b-502ae937e7eb X-detected-kernel: by monty-python.gnu.org: Linux 2.6 (newer, 3) Subject: Re: [PATCH] update-grub for Cygwin X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: The development of GRUB 2 List-Id: The development of GRUB 2 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 04 Aug 2008 19:46:26 -0000 This is a multi-part message in MIME format. --------------060303000400070207000307 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Christian Franke wrote: > Robert Millan wrote: >> On Thu, Jul 24, 2008 at 10:39:04PM +0200, Christian Franke wrote: >> >>> + >>> +d="`${grub_probe} -t drive "$p" 2>/dev/null`" || exit 0 >>> >> >> Please avoid reliing on '-t drive'. It's based on device.map which just >> contains guesswork. >> >> prepare_grub_to_access_device() is a much better option. >> >> > > Yes. Thanks for the info. New version below. > > Christian > > ... > Here a more generic version which allows to specifiy windows system dirs by /etc/default/grub:GRUB_WINDOWS_DIRS. Defaults to current SYSTEMDRIVE on Cygwin, and nothing on other OS. Christian 2008-08-04 Christian Franke * conf/common.rmk: Add `10_windows' to `update-grub_SCRIPTS'. * util/grub.d/10_windows.in: New file. * util/update-grub.in: Add export of GRUB_WINDOWS_DIRS. --------------060303000400070207000307 Content-Type: text/x-diff; name="grub2-10_windows.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="grub2-10_windows.patch" diff --git a/conf/common.rmk b/conf/common.rmk index 3d3cd8a..3d674a6 100644 --- a/conf/common.rmk +++ b/conf/common.rmk @@ -120,7 +120,7 @@ CLEANFILES += update-grub_lib %: util/grub.d/%.in config.status ./config.status --file=$@:$< chmod +x $@ -update-grub_SCRIPTS = 00_header 10_linux 10_hurd 30_os-prober 40_custom +update-grub_SCRIPTS = 00_header 10_linux 10_hurd 10_windows 30_os-prober 40_custom CLEANFILES += $(update-grub_SCRIPTS) update-grub_DATA += util/grub.d/README diff --git a/util/grub.d/10_windows.in b/util/grub.d/10_windows.in new file mode 100644 index 0000000..0b0bce2 --- /dev/null +++ b/util/grub.d/10_windows.in @@ -0,0 +1,104 @@ +#! /bin/sh -e + +# update-grub helper script. +# Copyright (C) 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 . + +prefix=@prefix@ +exec_prefix=@exec_prefix@ +libdir=@libdir@ +. ${libdir}/grub/update-grub_lib + +# List of directories to search for Windows can be specified +# in @sysconfdir@/default/grub by GRUB_WINDOWS_DIRS, e.g: +# GRUB_WINDOWS_DIRS="/boot /mnt/win*" + +dirlist="$GRUB_WINDOWS_DIRS" + +if [ -z "$dirlist" ] ; then + case "`uname 2>/dev/null`" in + CYGWIN*) + # Cygwin: try current system partition. + dirlist="$SYSTEMDRIVE" ;; + *) + # Other: do nothing to avoid collision with os-prober. + exit 0 ;; + esac +fi + +# Test for a file, case-insensitive. +test_nocase () +{ + local p="" + if [ "$1" = "-p" ] ; then + p=t ; shift + fi + local f=`ls -1 "$1" 2>/dev/null | grep -i '^'"$2"'$' | sed 1q` + test -n "$f" || return 1 + test -z "$p" || echo "$1/$f" +} + +# Get OS name from boot.ini. +get_os_name_from_boot_ini () +{ + local ini=`test_nocase -p "$1" boot.ini` || return 1 + + # Fail if no or more than one partition. + test "`sed -n 's,^\(\(multi\|scsi\)[^=]*\)=.*$,\1,p' "$ini" 2>/dev/null | \ + sort | uniq | wc -l`" = 1 || return 1 + + # Search 'default=PARTITION' + local part=`sed -n 's,^default=,,p' "$ini" | sed 's,\\\\,/,g;s,[ \t\r]*$,,;1q'` + test -n "$part" || return 1 + + # Search 'PARTITION="NAME" ...' + local name=`sed -n 's,\\\\,/,g;s,^'"$part"'="\([^"]*\)".*$,\1,p' "$ini" | sed 1q` + test -n "$name" || return 1 + + echo "$name" +} + + +for dir in $dirlist ; do + + # Check for Vista Bootmgr. + if test_nocase "$dir" bootmgr && bootdir=`test_nocase -p "$dir" boot` && + test_nocase "$bootdir" bcd ; then + OS="Windows Vista bootmgr" + + # Check for NTLDR. + elif test_nocase "$dir" ntldr && test_nocase "$dir" ntdetect.com ; then + OS=`get_os_name_from_boot_ini "$dir"` || OS="Windows NT/2000/XP loader" + + else + continue + fi + + # Get boot /dev/ice. + dev=`${grub_probe} -t device "$dir" 2>/dev/null` || continue + + echo "Found $OS on $dir ($dev)" >&2 + cat << EOF +menuentry "$OS" { +EOF + + prepare_grub_to_access_device "$dev" | sed 's,^,\t,' + + cat << EOF + chainloader +1 +} +EOF +done + diff --git a/util/update-grub.in b/util/update-grub.in index 8c60c41..eafaa91 100644 --- a/util/update-grub.in +++ b/util/update-grub.in @@ -163,7 +163,7 @@ esac export GRUB_DEVICE GRUB_DEVICE_UUID GRUB_DEVICE_BOOT GRUB_DEVICE_BOOT_UUID GRUB_FS GRUB_FONT_PATH GRUB_PRELOAD_MODULES # These are optional, user-defined variables. -export GRUB_DEFAULT GRUB_TIMEOUT GRUB_DISTRIBUTOR GRUB_CMDLINE_LINUX GRUB_CMDLINE_LINUX_DEFAULT GRUB_TERMINAL GRUB_SERIAL_COMMAND GRUB_DISABLE_LINUX_UUID +export GRUB_DEFAULT GRUB_TIMEOUT GRUB_DISTRIBUTOR GRUB_CMDLINE_LINUX GRUB_CMDLINE_LINUX_DEFAULT GRUB_TERMINAL GRUB_SERIAL_COMMAND GRUB_DISABLE_LINUX_UUID GRUB_WINDOWS_DIRS rm -f ${grub_cfg}.new exec > ${grub_cfg}.new --------------060303000400070207000307--