[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] update-grub for Cygwin
From: |
Christian Franke |
Subject: |
Re: [PATCH] update-grub for Cygwin |
Date: |
Tue, 05 Aug 2008 14:13:43 +0200 |
User-agent: |
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.16) Gecko/20080702 SeaMonkey/1.1.11 |
Robert Millan wrote:
On Mon, Aug 04, 2008 at 10:40:02PM +0200, Christian Franke wrote:
Robert Millan wrote:
On Mon, Aug 04, 2008 at 09:46:03PM +0200, Christian Franke wrote:
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 <address@hidden>
* 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.
Why is this needed? Can't we do something like 'grub-probe -t device
c:/ntldr'
or so?
It is not needed for standard installations with ntldr on SYSTEMDRIVE (C:).
The ability to specify GRUB_WINDOWS_DIRS is added to support
non-standard installations.
It also allows to use 10_windows on other OS if os-prober is not available.
Why not have the user write a custom entry then? I think it clutters the
user interface to add options for everything. If a corner case (boot a non
native disk, can't use os-prober) can be supported by creating a new config
file, why not do that? It was the whole reason for designing update-grub to
be easily extensible.
Even with the new configuration parameter, user can still decide to
leave the parameter unset and write a custom entry. Or the user can set
the parameter and so "opt-in" to let the script do the work (or
"opt-out" to disable the default work on Cygwin).
But in case the extra 'export' in 'update-grub' is a problem, here a
simplified version.
Scans C: and SYSTEMDRIVE on Cygwin, does nothing elsewhere. Cannot be
configured.
Christian
2008-08-05 Christian Franke <address@hidden>
* conf/common.rmk: Add `10_windows' to `update-grub_SCRIPTS'.
* util/grub.d/10_windows.in: New file.
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..e8f3c3e
--- /dev/null
+++ b/util/grub.d/10_windows.in
@@ -0,0 +1,83 @@
+#! /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 <http://www.gnu.org/licenses/>.
+
address@hidden@
address@hidden@
address@hidden@
+. ${libdir}/grub/update-grub_lib
+
+case "`uname 2>/dev/null`" in
+ CYGWIN*) ;;
+ *) exit 0 ;;
+esac
+
+# Try C: even if current system is on other partition.
+case "$SYSTEMDRIVE" in
+ [Cc]:) dirlist="C:" ;;
+ [D-Zd-z]:) dirlist="C: $SYSTEMDRIVE" ;;
+ *) exit 0 ;;
+esac
+
+get_os_name_from_boot_ini ()
+{
+ # Fail if no or more than one partition.
+ test "`sed -n 's,^\(\(multi\|scsi\)[^=]*\)=.*$,\1,p' "$1" 2>/dev/null | \
+ sort | uniq | wc -l`" = 1 || return 1
+
+ # Search 'default=PARTITION'
+ local part=`sed -n 's,^default=,,p' "$1" | 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' "$1" | sed
1q`
+ test -n "$name" || return 1
+
+ echo "$name"
+}
+
+
+for dir in $dirlist ; do
+
+ # Check for Vista bootmgr.
+ if [ -f "$dir"/bootmgr -a -f "$dir"/boot/bcd ] ; then
+ OS="Windows Vista bootmgr"
+
+ # Check for NTLDR.
+ elif [ -f "$dir"/ntldr -a -f "$dir"/ntdetect.com -a -f "$dir"/boot.ini ] ;
then
+ OS=`get_os_name_from_boot_ini "$dir"/boot.ini` || 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
+