* Problems with grub-reboot/savedefault/default=saved
@ 2009-12-16 22:28 Jordan Uggla
2009-12-20 8:37 ` Jordan Uggla
` (2 more replies)
0 siblings, 3 replies; 11+ messages in thread
From: Jordan Uggla @ 2009-12-16 22:28 UTC (permalink / raw)
To: grub-devel
[-- Attachment #1: Type: text/plain, Size: 2779 bytes --]
There are multiple problems with grub-reboot/savedefault/default=saved.
1: grub-reboot doesn't restore the default after rebooting, making it
effectively equivalent to grub-set-default. This is because the
savedefault functionality currently saves the entry you boot from as the
new default even when grub-reboot is used. Because of problem #2 there is
no way ( outside manually editing the grub.cfg ) to use grub-reboot without
savedefault functionality also enabled ( and thus no configuration where grub-reboot isn't broken ). I've added a patch for this to
the bug report @ http://savannah.gnu.org/bugs/?28161 and as the first patch
attached to this email.
2: Setting GRUB_DEFAULT=saved in /etc/default/grub also enables savedefault
functionality. There are many people who would want to use grub-reboot and
grub-set-default without savedefault. The second patch adds a separate
variable, GRUB_SAVEDEFAULT, for enabling savedefault.
3: Savedefault functionality currently adds two lines ( one setting a
variable, the other saving it ) to every menu entry and with my patch for
fixing grub-reboot, an if statement as well. This clutters the menu entries
and makes it hard to write and maintain custom menu entries with
savedefault. The third patch moves this to a function "savedefault" defined
in 00_header so entries just have to have "savedefault", like in grub
legacy. And if the implementation of savedefault needs to change, custom
menu entries will still work unmodified.
4: Even with the first grub-reboot fix the default is still not restored
when grubenv is not writable ( /boot on lvm for example ). Since
grub-reboot can't work without a writable grubenv it's at least safer to
boot into the "real" default instead of the "temporary" default. The
fourth patch sets default=$prev_saved_default if save_env fails.
Grub-reboot ( the utility ) should also complain when grubenv isn't
writable by grub. What is the best way to determine that grubenv likely is
or isn't writable by grub?
5: Since grub2 uses menu entry titles for savedefault instead of numbers,
the default kernel booted won't be changed when the user installs a new
kernel. Using titles instead of numbers is good, but an unfortunate
consequence that users may not realize ( and was not true with savedefault
in grub-legacy ) is that if users set GRUB_SAVEDEFAULT=true they will never
actually boot any updated kernels unless they select them manually at the
grub menu. This could lead to not getting security updates for the kernel,
and with major upgrades could cause serious problems when the old kernel
doesn't work with newer userland components like Xorg. I can't think of a
good way to solve this problem.
--
Jordan Uggla ( Jordan_U on irc.freenode.net )
[-- Attachment #2: fix1.patch --]
[-- Type: text/x-patch, Size: 752 bytes --]
=== modified file 'util/grub-mkconfig_lib.in'
--- old/util/grub-mkconfig_lib.in 2009-12-09 21:03:26 +0000
+++ new/util/grub-mkconfig_lib.in 2009-12-16 20:12:30 +0000
@@ -97,8 +97,10 @@
save_default_entry ()
{
if [ "x${GRUB_DEFAULT}" = "xsaved" ] ; then
- echo 'saved_entry=${chosen}'
- echo 'save_env saved_entry'
+ echo 'if [ ${boot_once} != true ]; then'
+ echo ' saved_entry=${chosen}'
+ echo ' save_env saved_entry'
+ echo 'fi'
fi
}
=== modified file 'util/grub.d/00_header.in'
--- old/util/grub.d/00_header.in 2009-11-24 00:22:41 +0000
+++ new/util/grub.d/00_header.in 2009-12-16 20:12:30 +0000
@@ -46,6 +46,7 @@
save_env saved_entry
prev_saved_entry=
save_env prev_saved_entry
+ boot_once=true
fi
EOF
[-- Attachment #3: fix2.patch --]
[-- Type: text/x-patch, Size: 818 bytes --]
=== modified file 'util/grub-mkconfig.in'
--- old/util/grub-mkconfig.in 2009-12-12 00:43:32 +0000
+++ new/util/grub-mkconfig.in 2009-12-16 20:22:36 +0000
@@ -220,7 +220,8 @@
GRUB_DISABLE_LINUX_UUID \
GRUB_DISABLE_LINUX_RECOVERY \
GRUB_GFXMODE \
- GRUB_DISABLE_OS_PROBER
+ GRUB_DISABLE_OS_PROBER \
+ GRUB_SAVEDEFAULT
if test "x${grub_cfg}" != "x"; then
rm -f ${grub_cfg}.new
=== modified file 'util/grub-mkconfig_lib.in'
--- old/util/grub-mkconfig_lib.in 2009-12-16 20:12:30 +0000
+++ new/util/grub-mkconfig_lib.in 2009-12-16 20:22:36 +0000
@@ -96,7 +96,7 @@
save_default_entry ()
{
- if [ "x${GRUB_DEFAULT}" = "xsaved" ] ; then
+ if [ "x${GRUB_SAVEDEFAULT}" = "xtrue" ] ; then
echo 'if [ ${boot_once} != true ]; then'
echo ' saved_entry=${chosen}'
echo ' save_env saved_entry'
[-- Attachment #4: fix3.patch --]
[-- Type: text/x-patch, Size: 853 bytes --]
=== modified file 'util/grub-mkconfig_lib.in'
--- old/util/grub-mkconfig_lib.in 2009-12-16 20:22:36 +0000
+++ new/util/grub-mkconfig_lib.in 2009-12-16 20:25:37 +0000
@@ -97,10 +97,7 @@
save_default_entry ()
{
if [ "x${GRUB_SAVEDEFAULT}" = "xtrue" ] ; then
- echo 'if [ ${boot_once} != true ]; then'
- echo ' saved_entry=${chosen}'
- echo ' save_env saved_entry'
- echo 'fi'
+ echo 'savedefault'
fi
}
=== modified file 'util/grub.d/00_header.in'
--- old/util/grub.d/00_header.in 2009-12-16 20:12:30 +0000
+++ new/util/grub.d/00_header.in 2009-12-16 20:25:37 +0000
@@ -48,6 +48,14 @@
save_env prev_saved_entry
boot_once=true
fi
+
+function savedefault {
+ if [ \${boot_once} != true ]; then
+ saved_entry=\${chosen}
+ save_env saved_entry
+ fi
+}
+
EOF
case ${GRUB_TERMINAL_INPUT}:${GRUB_TERMINAL_OUTPUT} in
[-- Attachment #5: fix4.patch --]
[-- Type: text/x-patch, Size: 561 bytes --]
=== modified file 'util/grub.d/00_header.in'
--- old/util/grub.d/00_header.in 2009-12-16 20:25:37 +0000
+++ new/util/grub.d/00_header.in 2009-12-16 20:41:14 +0000
@@ -43,10 +43,13 @@
set default=${GRUB_DEFAULT}
if [ \${prev_saved_entry} ]; then
saved_entry=\${prev_saved_entry}
- save_env saved_entry
- prev_saved_entry=
- save_env prev_saved_entry
- boot_once=true
+ if save_env saved_entry; then
+ prev_saved_entry=
+ save_env prev_saved_entry
+ boot_once=true
+ else
+ default=\${prev_saved_entry}
+ fi
fi
function savedefault {
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Problems with grub-reboot/savedefault/default=saved
2009-12-16 22:28 Problems with grub-reboot/savedefault/default=saved Jordan Uggla
@ 2009-12-20 8:37 ` Jordan Uggla
2010-01-05 11:23 ` Colin Watson
2009-12-23 2:03 ` Problems with grub-reboot/savedefault/default=saved Colin Watson
2010-01-05 11:08 ` Colin Watson
2 siblings, 1 reply; 11+ messages in thread
From: Jordan Uggla @ 2009-12-20 8:37 UTC (permalink / raw)
To: grub-devel
[-- Attachment #1: Type: text/plain, Size: 813 bytes --]
I found another bug. For some reason grub-reboot ( the utility )
checks if prev_saved_entry ( which has just been set equal to
saved_entry ) is empty ( zero length or unset ), and if it is
unsets it. This makes grub-reboot again equivalent to
grub-set-default the first time you use it. Instead I changed it
so that if prev_saved_entry is empty it gets set to "0" because
default=0 is the same as default="" but the grub.cfg detects
that you've used grub-reboot by checking if prev_saved_entry is
not empty.
I've attached a fix for this and also updated my previous
patches so they apply cleanly and are consistent with the new
changes from the savedefault branch that were merged into
experimental ( using set var=value instead of just var=value ).
--
Jordan Uggla ( Jordan_U on irc.freenode.net )
[-- Attachment #2: fix1-rebased.patch --]
[-- Type: text/x-patch, Size: 768 bytes --]
=== modified file 'util/grub-mkconfig_lib.in'
--- old/util/grub-mkconfig_lib.in 2009-12-17 17:34:56 +0000
+++ new/util/grub-mkconfig_lib.in 2009-12-16 20:12:30 +0000
@@ -97,8 +97,10 @@
save_default_entry ()
{
if [ "x${GRUB_DEFAULT}" = "xsaved" ] ; then
- echo 'set saved_entry=${chosen}'
- echo 'save_env saved_entry'
+ echo 'if [ ${boot_once} != true ]; then'
+ echo ' set saved_entry=${chosen}'
+ echo ' save_env saved_entry'
+ echo 'fi'
fi
}
=== modified file 'util/grub.d/00_header.in'
--- old/util/grub.d/00_header.in 2009-12-17 17:34:56 +0000
+++ new/util/grub.d/00_header.in 2009-12-16 20:12:30 +0000
@@ -48,6 +48,7 @@
save_env saved_entry
set prev_saved_entry=
save_env prev_saved_entry
+ set boot_once=true
fi
EOF
[-- Attachment #3: fix2-rebased.patch --]
[-- Type: text/x-patch, Size: 822 bytes --]
=== modified file 'util/grub-mkconfig.in'
--- old/util/grub-mkconfig.in 2009-12-12 00:43:32 +0000
+++ new/util/grub-mkconfig.in 2009-12-16 20:22:36 +0000
@@ -220,7 +220,8 @@
GRUB_DISABLE_LINUX_UUID \
GRUB_DISABLE_LINUX_RECOVERY \
GRUB_GFXMODE \
- GRUB_DISABLE_OS_PROBER
+ GRUB_DISABLE_OS_PROBER \
+ GRUB_SAVEDEFAULT
if test "x${grub_cfg}" != "x"; then
rm -f ${grub_cfg}.new
=== modified file 'util/grub-mkconfig_lib.in'
--- old/util/grub-mkconfig_lib.in 2009-12-16 20:12:30 +0000
+++ new/util/grub-mkconfig_lib.in 2009-12-16 20:22:36 +0000
@@ -96,7 +96,7 @@
save_default_entry ()
{
- if [ "x${GRUB_DEFAULT}" = "xsaved" ] ; then
+ if [ "x${GRUB_SAVEDEFAULT}" = "xtrue" ] ; then
echo 'if [ ${boot_once} != true ]; then'
echo ' set saved_entry=${chosen}'
echo ' save_env saved_entry'
[-- Attachment #4: fix3-rebased.patch --]
[-- Type: text/x-patch, Size: 865 bytes --]
=== modified file 'util/grub-mkconfig_lib.in'
--- old/util/grub-mkconfig_lib.in 2009-12-16 20:22:36 +0000
+++ new/util/grub-mkconfig_lib.in 2009-12-16 20:25:37 +0000
@@ -97,10 +97,7 @@
save_default_entry ()
{
if [ "x${GRUB_SAVEDEFAULT}" = "xtrue" ] ; then
- echo 'if [ ${boot_once} != true ]; then'
- echo ' set saved_entry=${chosen}'
- echo ' save_env saved_entry'
- echo 'fi'
+ echo 'savedefault'
fi
}
=== modified file 'util/grub.d/00_header.in'
--- old/util/grub.d/00_header.in 2009-12-16 20:12:30 +0000
+++ new/util/grub.d/00_header.in 2009-12-16 20:25:37 +0000
@@ -50,6 +50,14 @@
save_env prev_saved_entry
set boot_once=true
fi
+
+function savedefault {
+ if [ \${boot_once} != true ]; then
+ set saved_entry=\${chosen}
+ save_env saved_entry
+ fi
+}
+
EOF
case ${GRUB_TERMINAL_INPUT}:${GRUB_TERMINAL_OUTPUT} in
[-- Attachment #5: fix4-rebased.patch --]
[-- Type: text/x-patch, Size: 587 bytes --]
=== modified file 'util/grub.d/00_header.in'
--- old/util/grub.d/00_header.in 2009-12-16 20:25:37 +0000
+++ new/util/grub.d/00_header.in 2009-12-20 01:45:32 +0000
@@ -45,10 +45,13 @@
set default="${GRUB_DEFAULT}"
if [ \${prev_saved_entry} ]; then
set saved_entry=\${prev_saved_entry}
- save_env saved_entry
- set prev_saved_entry=
- save_env prev_saved_entry
- set boot_once=true
+ if save_env saved_entry; then
+ set prev_saved_entry=
+ save_env prev_saved_entry
+ set boot_once=true
+ else
+ set default=\${prev_saved_entry}
+ fi
fi
function savedefault {
[-- Attachment #6: fix5.patch --]
[-- Type: text/x-patch, Size: 680 bytes --]
=== modified file 'util/grub-reboot.in'
--- old/util/grub-reboot.in 2009-12-08 01:00:26 +0000
+++ new/util/grub-reboot.in 2009-12-20 06:57:34 +0000
@@ -96,7 +96,10 @@
if [ "$prev_saved_entry" ]; then
$grub_editenv ${grubdir}/grubenv set prev_saved_entry="$prev_saved_entry"
else
- $grub_editenv ${grubdir}/grubenv unset prev_saved_entry
+ #Set prev_saved_entry to zero. Setting the default to "0" is the same as
+ #setting it to "" but because of the way grub-reboot is currently
+ #implemented prev_saved_entry can't be zero length.
+ $grub_editenv ${grubdir}/grubenv set prev_saved_entry=0
fi
$grub_editenv ${grubdir}/grubenv set saved_entry="$entry"
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Problems with grub-reboot/savedefault/default=saved
2009-12-16 22:28 Problems with grub-reboot/savedefault/default=saved Jordan Uggla
2009-12-20 8:37 ` Jordan Uggla
@ 2009-12-23 2:03 ` Colin Watson
2010-01-05 11:08 ` Colin Watson
2 siblings, 0 replies; 11+ messages in thread
From: Colin Watson @ 2009-12-23 2:03 UTC (permalink / raw)
To: The development of GNU GRUB
On Wed, Dec 16, 2009 at 02:28:03PM -0800, Jordan Uggla wrote:
> There are multiple problems with grub-reboot/savedefault/default=saved.
Hi,
I do intend to follow up on this; however, due to Christmas holidays and
the like it won't be until the new year. I'm just sending this message
to let you know that I'm not ignoring this thread. I have a slightly
modified version of this patch queued up for testing.
Thanks,
--
Colin Watson [cjwatson@ubuntu.com]
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Problems with grub-reboot/savedefault/default=saved
2009-12-16 22:28 Problems with grub-reboot/savedefault/default=saved Jordan Uggla
2009-12-20 8:37 ` Jordan Uggla
2009-12-23 2:03 ` Problems with grub-reboot/savedefault/default=saved Colin Watson
@ 2010-01-05 11:08 ` Colin Watson
2010-01-05 11:33 ` Vladimir 'φ-coder/phcoder' Serbinenko
2010-01-07 5:22 ` Jordan Uggla
2 siblings, 2 replies; 11+ messages in thread
From: Colin Watson @ 2010-01-05 11:08 UTC (permalink / raw)
To: The development of GNU GRUB
On Wed, Dec 16, 2009 at 02:28:03PM -0800, Jordan Uggla wrote:
> 1: grub-reboot doesn't restore the default after rebooting, making it
> effectively equivalent to grub-set-default. This is because the
> savedefault functionality currently saves the entry you boot from as the
> new default even when grub-reboot is used. Because of problem #2 there is
> no way ( outside manually editing the grub.cfg ) to use grub-reboot without
> savedefault functionality also enabled ( and thus no configuration where grub-reboot isn't broken ). I've added a patch for this to
> the bug report @ http://savannah.gnu.org/bugs/?28161 and as the first patch
> attached to this email.
Applied with a slight tweak, thanks.
> 2: Setting GRUB_DEFAULT=saved in /etc/default/grub also enables savedefault
> functionality. There are many people who would want to use grub-reboot and
> grub-set-default without savedefault. The second patch adds a separate
> variable, GRUB_SAVEDEFAULT, for enabling savedefault.
How would this interact with setting GRUB_DEFAULT to something other
than "saved", and doesn't 00_header.in also need to be changed to
actually use the saved entry (it won't be used unless you have
GRUB_DEFAULT=saved)?
In my mind, GRUB_DEFAULT was overloaded for this for a good reason; but
perhaps I'm simply not understanding what you mean, so would you mind
explaining further how you'd like to see the whole thing laid out?
> 3: Savedefault functionality currently adds two lines ( one setting a
> variable, the other saving it ) to every menu entry and with my patch for
> fixing grub-reboot, an if statement as well. This clutters the menu entries
> and makes it hard to write and maintain custom menu entries with
> savedefault. The third patch moves this to a function "savedefault" defined
> in 00_header so entries just have to have "savedefault", like in grub
> legacy. And if the implementation of savedefault needs to change, custom
> menu entries will still work unmodified.
Makes sense. Applied.
> 4: Even with the first grub-reboot fix the default is still not restored
> when grubenv is not writable ( /boot on lvm for example ). Since
> grub-reboot can't work without a writable grubenv it's at least safer to
> boot into the "real" default instead of the "temporary" default. The
> fourth patch sets default=$prev_saved_default if save_env fails.
> Grub-reboot ( the utility ) should also complain when grubenv isn't
> writable by grub. What is the best way to determine that grubenv likely is
> or isn't writable by grub?
I don't understand why /boot on LVM should mean that grubenv is not
writable. The point of grubenv is to be a short chunk of contiguous
reserved disk space which can be written by GRUB without needing any
special filesystem intelligence. Surely LVM doesn't split up those 1024
bytes into different physical extents?
> 5: Since grub2 uses menu entry titles for savedefault instead of numbers,
> the default kernel booted won't be changed when the user installs a new
> kernel. Using titles instead of numbers is good, but an unfortunate
> consequence that users may not realize ( and was not true with savedefault
> in grub-legacy ) is that if users set GRUB_SAVEDEFAULT=true they will never
> actually boot any updated kernels unless they select them manually at the
> grub menu. This could lead to not getting security updates for the kernel,
> and with major upgrades could cause serious problems when the old kernel
> doesn't work with newer userland components like Xorg. I can't think of a
> good way to solve this problem.
IIRC GRUB Legacy (or at least Debian's update-grub, once upon a time)
handled this by having a special "default" entry at the top of the Linux
kernel list. Would it be worth introducing this to grub-mkconfig?
--
Colin Watson [cjwatson@ubuntu.com]
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Problems with grub-reboot/savedefault/default=saved
2009-12-20 8:37 ` Jordan Uggla
@ 2010-01-05 11:23 ` Colin Watson
2010-01-05 18:30 ` Lapohos Tibor
0 siblings, 1 reply; 11+ messages in thread
From: Colin Watson @ 2010-01-05 11:23 UTC (permalink / raw)
To: The development of GNU GRUB
On Sun, Dec 20, 2009 at 12:37:17AM -0800, Jordan Uggla wrote:
> I found another bug. For some reason grub-reboot ( the utility )
> checks if prev_saved_entry ( which has just been set equal to
> saved_entry ) is empty ( zero length or unset ), and if it is
> unsets it. This makes grub-reboot again equivalent to
> grub-set-default the first time you use it. Instead I changed it
> so that if prev_saved_entry is empty it gets set to "0" because
> default=0 is the same as default="" but the grub.cfg detects
> that you've used grub-reboot by checking if prev_saved_entry is
> not empty.
>
> I've attached a fix for this
Thanks, applied, though I reworded the comment a bit. In future,
ChangeLog (or rather ChangeLog.savedefault) entries are appreciated.
Would the maintainers be OK with me merging savedefault into trunk soon?
I think it's getting pretty good now and quite a few people are
interested in it. The full current patch follows.
(What is the convention for merging Changelog.<branch> files into
ChangeLog? Do we keep everything including the dates intact, or collapse
the entries into one, or what?)
=== added file 'ChangeLog.savedefault'
--- ChangeLog.savedefault 1970-01-01 00:00:00 +0000
+++ ChangeLog.savedefault 2010-01-05 11:15:15 +0000
@@ -0,0 +1,80 @@
+2010-10-05 Jordan Uggla <jordan.uggla@gmail.com>
+2010-10-05 Colin Watson <cjwatson@ubuntu.com>
+
+ * util/grub-reboot.in: Make sure prev_saved_entry always gets a
+ non-empty value.
+
+2010-10-05 Jordan Uggla <jordan.uggla@gmail.com>
+2010-10-05 Colin Watson <cjwatson@ubuntu.com>
+
+ * util/grub.d/00_header.in: Define a "savedefault" function for use
+ in menu entries.
+ * util/grub-mkconfig_lib.in (save_default_entry): Use it.
+
+2010-10-05 Jordan Uggla <jordan.uggla@gmail.com>
+2010-10-05 Colin Watson <cjwatson@ubuntu.com>
+
+ * util/grub-mkconfig_lib.in (save_default_entry): Only set
+ saved_entry if boot_once is unset.
+ * util/grub.d/00_header.in: Set boot_once to "true" if there was a
+ previous saved entry (i.e. grub-reboot).
+
+2009-12-08 Colin Watson <cjwatson@ubuntu.com>
+
+ * util/grub.d/30_os-prober.in: Call save_default_entry for hurd.
+
+2009-12-08 Colin Watson <cjwatson@ubuntu.com>
+
+ * util/grub.d/00_header.in: Use `set var=val' rather than plain
+ `var=val'.
+ * util/grub-mkconfig_lib.in (save_default_entry): Likewise.
+
+2009-12-08 Colin Watson <cjwatson@ubuntu.com>
+
+ * util/grub-reboot.in: Fix --version output.
+ * util/grub-set-default.in: Likewise.
+
+2009-12-08 Colin Watson <cjwatson@ubuntu.com>
+
+ * util/grub.d/00_header.in: Silently ignore zero-sized environment
+ blocks.
+
+2009-12-08 Colin Watson <cjwatson@ubuntu.com>
+
+ * util/grub.d/00_header.in: Quote the value assigned to `default',
+ in case it contains spaces.
+
+2009-12-08 Colin Watson <cjwatson@ubuntu.com>
+
+ * util/grub.d/30_os-prober.in: Fix merge error that moved a
+ `save_default_entry' call from the macosx case to the linux case.
+
+2009-10-25 Vladimir Serbinenko <phcoder@gmail.com>
+2009-10-25 Colin Watson <cjwatson@ubuntu.com>
+
+ * normal/menu.c (grub_menu_execute_entry): Save selected entry title
+ in `chosen' environment variable.
+ * normal/menu_text.c (get_entry_number): Check if the variable
+ matches the title of a menu entry.
+ (run_menu): Pass menu to get_entry_number.
+
+ * util/grub-reboot.in: New file.
+ * util/grub-set-default.in: New file.
+ * conf/common.rmk (grub-reboot): New utility.
+ (grub-set-default): New utility.
+
+ * util/grub-mkconfig_lib.in (save_default_entry): New function.
+ * util/grub.d/00_header.in: If GRUB_DEFAULT is `saved', set
+ default to `${saved_entry}'. If `${prev_saved_entry}' is non-empty,
+ move it to `saved_entry' for the next boot. Load environment on
+ initialisation.
+ * util/grub.d/10_kfreebsd.in: Call save_default_entry.
+ * util/grub.d/10_hurd.in: Likewise.
+ * util/grub.d/10_linux.in (linux_entry): Likewise.
+ * util/grub.d/10_windows.in: Likewise.
+ * util/grub.d/30_os-prober.in: Likewise.
+
+ * util/grub-install.in: Create environment block.
+ * util/i386/efi/grub-install.in: Likewise.
+ * util/ieee1275/grub-install.in: Likewise.
+ * util/sparc64/ieee1275/grub-install.in: Likewise.
=== modified file 'conf/common.rmk'
--- conf/common.rmk 2009-12-25 22:06:52 +0000
+++ conf/common.rmk 2010-01-05 10:49:59 +0000
@@ -185,6 +185,20 @@ CLEANFILES += $(grub-mkconfig_SCRIPTS)
grub-mkconfig_DATA += util/grub.d/README
+# For grub-set-default.
+grub-set-default: util/grub-set-default.in config.status
+ ./config.status --file=$@:$<
+ chmod +x $@
+sbin_SCRIPTS += grub-set-default
+CLEANFILES += grub-set-default
+
+# For grub-reboot.
+grub-reboot: util/grub-reboot.in config.status
+ ./config.status --file=$@:$<
+ chmod +x $@
+sbin_SCRIPTS += grub-reboot
+CLEANFILES += grub-reboot
+
# Filing systems.
pkglib_MODULES += fshelp.mod fat.mod ufs1.mod ufs2.mod ext2.mod ntfs.mod \
ntfscomp.mod minix.mod hfs.mod jfs.mod iso9660.mod xfs.mod \
=== modified file 'normal/menu.c'
--- normal/menu.c 2009-08-24 23:55:06 +0000
+++ normal/menu.c 2009-12-08 00:47:44 +0000
@@ -137,6 +137,8 @@ grub_menu_execute_entry(grub_menu_entry_
return;
}
+ grub_env_set ("chosen", entry->title);
+
grub_parser_execute ((char *) entry->sourcecode);
if (grub_errno == GRUB_ERR_NONE && grub_loader_is_loaded ())
=== modified file 'normal/menu_text.c'
--- normal/menu_text.c 2009-12-27 21:32:52 +0000
+++ normal/menu_text.c 2010-01-05 10:49:59 +0000
@@ -365,7 +365,7 @@ grub_menu_init_page (int nested, int edi
/* Get the entry number from the variable NAME. */
static int
-get_entry_number (const char *name)
+get_entry_number (grub_menu_t menu, const char *name)
{
char *val;
int entry;
@@ -378,6 +378,28 @@ get_entry_number (const char *name)
entry = (int) grub_strtoul (val, 0, 0);
+ if (grub_errno == GRUB_ERR_BAD_NUMBER)
+ {
+ /* See if the variable matches the title of a menu entry. */
+ grub_menu_entry_t e = menu->entry_list;
+ int i;
+
+ grub_errno = GRUB_ERR_NONE;
+
+ for (i = 0; e; i++)
+ {
+ if (grub_strcmp (e->title, val) == 0)
+ {
+ entry = i;
+ break;
+ }
+ e = e->next;
+ }
+
+ if (! e)
+ entry = -1;
+ }
+
if (grub_errno != GRUB_ERR_NONE)
{
grub_errno = GRUB_ERR_NONE;
@@ -427,7 +449,7 @@ run_menu (grub_menu_t menu, int nested,
first = 0;
- default_entry = get_entry_number ("default");
+ default_entry = get_entry_number (menu, "default");
/* If DEFAULT_ENTRY is not within the menu entries, fall back to
the first entry. */
=== modified file 'util/grub-install.in'
--- util/grub-install.in 2009-12-25 22:06:52 +0000
+++ util/grub-install.in 2010-01-05 10:50:00 +0000
@@ -40,6 +40,7 @@ else
fi
grub_mkdevicemap=${sbindir}/`echo grub-mkdevicemap | sed ${transform}`
grub_probe=${sbindir}/`echo grub-probe | sed ${transform}`
+grub_editenv=${bindir}/`echo grub-editenv | sed ${transform}`
rootdir=
grub_prefix=`echo /boot/grub | sed ${transform}`
modules=
@@ -261,6 +262,10 @@ done
# Write device to a variable so we don't have to traverse /dev every time.
grub_device=`$grub_probe --target=device ${grubdir}`
+if ! test -f ${grubdir}/grubenv; then
+ $grub_editenv ${grubdir}/grubenv create
+fi
+
# Create the core image. First, auto-detect the filesystem module.
fs_module=`$grub_probe --target=fs --device ${grub_device}`
if test "x$fs_module" = x -a "x$modules" = x; then
=== modified file 'util/grub-mkconfig_lib.in'
--- util/grub-mkconfig_lib.in 2009-12-23 16:41:32 +0000
+++ util/grub-mkconfig_lib.in 2010-01-05 10:49:59 +0000
@@ -94,6 +94,15 @@ convert_system_path_to_grub_path ()
echo ${drive}${relative_path}
}
+save_default_entry ()
+{
+ if [ "x${GRUB_DEFAULT}" = "xsaved" ] ; then
+ cat << EOF
+savedefault
+EOF
+ fi
+}
+
prepare_grub_to_access_device ()
{
device=$1
=== added file 'util/grub-reboot.in'
--- util/grub-reboot.in 1970-01-01 00:00:00 +0000
+++ util/grub-reboot.in 2010-01-05 11:15:16 +0000
@@ -0,0 +1,108 @@
+#! /bin/sh
+#
+# Set a default boot entry for GRUB, for the next boot only.
+# Copyright (C) 2004,2009 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/>.
+
+# Initialize some variables.
+transform="@program_transform_name@"
+
+prefix=@prefix@
+exec_prefix=@exec_prefix@
+bindir=@bindir@
+
+grub_editenv=${bindir}/`echo grub-editenv | sed ${transform}`
+rootdir=
+
+# Usage: usage
+# Print the usage.
+usage () {
+ cat <<EOF
+Usage: $0 [OPTION] entry
+Set the default boot entry for GRUB, for the next boot only.
+
+ -h, --help print this message and exit
+ -v, --version print the version information and exit
+ --root-directory=DIR expect GRUB images under the directory DIR
+ instead of the root directory
+
+ENTRY is a number or a menu item title.
+
+Report bugs to <bug-grub@gnu.org>.
+EOF
+}
+
+# Check the arguments.
+for option in "$@"; do
+ case "$option" in
+ -h | --help)
+ usage
+ exit 0 ;;
+ -v | --version)
+ echo "grub-reboot (GNU GRUB ${PACKAGE_VERSION})"
+ exit 0 ;;
+ --root-directory=*)
+ rootdir=`echo "$option" | sed 's/--root-directory=//'` ;;
+ -*)
+ echo "Unrecognized option \`$option'" 1>&2
+ usage
+ exit 1
+ ;;
+ *)
+ if test "x$entry" != x; then
+ echo "More than one entry?" 1>&2
+ usage
+ exit 1
+ fi
+ entry="${option}" ;;
+ esac
+done
+
+if test "x$entry" = x; then
+ echo "entry not specified." 1>&2
+ usage
+ exit 1
+fi
+
+# Initialize these directories here, since ROOTDIR was initialized.
+case "$host_os" in
+netbsd* | openbsd*)
+ # Because /boot is used for the boot block in NetBSD and OpenBSD, use /grub
+ # instead of /boot/grub.
+ grub_prefix=`echo /grub | sed ${transform}`
+ bootdir=${rootdir}
+ ;;
+*)
+ # Use /boot/grub by default.
+ bootdir=${rootdir}/boot
+ ;;
+esac
+
+grubdir=${bootdir}/`echo grub | sed ${transform}`
+
+prev_saved_entry=`$grub_editenv ${grubdir}/grubenv list | sed -n 's/^saved_entry=//p'`
+if [ "$prev_saved_entry" ]; then
+ $grub_editenv ${grubdir}/grubenv set prev_saved_entry="$prev_saved_entry"
+else
+ # We need some non-empty value for prev_saved_entry so that GRUB will
+ # recognise that grub-reboot has been used and restore the previous
+ # saved entry. "0" is the same as an empty value, i.e. the first menu
+ # entry.
+ $grub_editenv ${grubdir}/grubenv set prev_saved_entry=0
+fi
+$grub_editenv ${grubdir}/grubenv set saved_entry="$entry"
+
+# Bye.
+exit 0
=== added file 'util/grub-set-default.in'
--- util/grub-set-default.in 1970-01-01 00:00:00 +0000
+++ util/grub-set-default.in 2009-12-08 01:00:23 +0000
@@ -0,0 +1,99 @@
+#! /bin/sh
+#
+# Set a default boot entry for GRUB.
+# Copyright (C) 2004,2009 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/>.
+
+# Initialize some variables.
+transform="@program_transform_name@"
+
+prefix=@prefix@
+exec_prefix=@exec_prefix@
+bindir=@bindir@
+
+grub_editenv=${bindir}/`echo grub-editenv | sed ${transform}`
+rootdir=
+
+# Usage: usage
+# Print the usage.
+usage () {
+ cat <<EOF
+Usage: $0 [OPTION] entry
+Set the default boot entry for GRUB.
+
+ -h, --help print this message and exit
+ -v, --version print the version information and exit
+ --root-directory=DIR expect GRUB images under the directory DIR
+ instead of the root directory
+
+ENTRY is a number or a menu item title.
+
+Report bugs to <bug-grub@gnu.org>.
+EOF
+}
+
+# Check the arguments.
+for option in "$@"; do
+ case "$option" in
+ -h | --help)
+ usage
+ exit 0 ;;
+ -v | --version)
+ echo "grub-set-default (GNU GRUB ${PACKAGE_VERSION})"
+ exit 0 ;;
+ --root-directory=*)
+ rootdir=`echo "$option" | sed 's/--root-directory=//'` ;;
+ -*)
+ echo "Unrecognized option \`$option'" 1>&2
+ usage
+ exit 1
+ ;;
+ *)
+ if test "x$entry" != x; then
+ echo "More than one entry?" 1>&2
+ usage
+ exit 1
+ fi
+ entry="${option}" ;;
+ esac
+done
+
+if test "x$entry" = x; then
+ echo "entry not specified." 1>&2
+ usage
+ exit 1
+fi
+
+# Initialize these directories here, since ROOTDIR was initialized.
+case "$host_os" in
+netbsd* | openbsd*)
+ # Because /boot is used for the boot block in NetBSD and OpenBSD, use /grub
+ # instead of /boot/grub.
+ grub_prefix=`echo /grub | sed ${transform}`
+ bootdir=${rootdir}
+ ;;
+*)
+ # Use /boot/grub by default.
+ bootdir=${rootdir}/boot
+ ;;
+esac
+
+grubdir=${bootdir}/`echo grub | sed ${transform}`
+
+$grub_editenv ${grubdir}/grubenv unset prev_saved_entry
+$grub_editenv ${grubdir}/grubenv set saved_entry="$entry"
+
+# Bye.
+exit 0
=== modified file 'util/grub.d/00_header.in'
--- util/grub.d/00_header.in 2009-12-23 16:41:32 +0000
+++ util/grub.d/00_header.in 2010-01-05 10:50:00 +0000
@@ -34,11 +34,29 @@ for i in ${GRUB_PRELOAD_MODULES} ; do
done
if [ "x${GRUB_DEFAULT}" = "x" ] ; then GRUB_DEFAULT=0 ; fi
+if [ "x${GRUB_DEFAULT}" = "xsaved" ] ; then GRUB_DEFAULT='${saved_entry}' ; fi
if [ "x${GRUB_TIMEOUT}" = "x" ] ; then GRUB_TIMEOUT=5 ; fi
if [ "x${GRUB_GFXMODE}" = "x" ] ; then GRUB_GFXMODE=640x480 ; fi
cat << EOF
-set default=${GRUB_DEFAULT}
+if [ -s \$prefix/grubenv ]; then
+ load_env
+fi
+set default="${GRUB_DEFAULT}"
+if [ \${prev_saved_entry} ]; then
+ set saved_entry=\${prev_saved_entry}
+ save_env saved_entry
+ set prev_saved_entry=
+ save_env prev_saved_entry
+ set boot_once=true
+fi
+
+function savedefault {
+ if [ -z \${boot_once} ]; then
+ saved_entry=\${chosen}
+ save_env saved_entry
+ fi
+}
EOF
case ${GRUB_TERMINAL_INPUT}:${GRUB_TERMINAL_OUTPUT} in
=== modified file 'util/grub.d/10_hurd.in'
--- util/grub.d/10_hurd.in 2009-11-02 19:32:12 +0000
+++ util/grub.d/10_hurd.in 2009-12-08 00:47:44 +0000
@@ -75,6 +75,7 @@ prepare_grub_to_access_device ${GRUB_DEV
cat << EOF
multiboot ${kernel} root=device:${GRUB_DEVICE#/dev/}
EOF
+save_default_entry | sed -e "s/^/\t/"
prepare_grub_to_access_device ${GRUB_DEVICE} | sed -e "s/^/\t/"
cat << EOF
module /hurd/${hurd_fs}.static ${hurd_fs} --readonly \\
=== modified file 'util/grub.d/10_kfreebsd.in'
--- util/grub.d/10_kfreebsd.in 2009-11-25 18:13:35 +0000
+++ util/grub.d/10_kfreebsd.in 2009-12-08 00:54:47 +0000
@@ -39,6 +39,7 @@ kfreebsd_entry ()
args="$4" # not used yet
title="$(gettext "%s, with kFreeBSD %s")"
printf "menuentry \"${title}\" {\n" "${os}" "${version}"
+ save_default_entry | sed -e "s/^/\t/"
if [ -z "${prepare_boot_cache}" ]; then
prepare_boot_cache="$(prepare_grub_to_access_device ${GRUB_DEVICE_BOOT} | sed -e "s/^/\t/")"
fi
=== modified file 'util/grub.d/10_linux.in'
--- util/grub.d/10_linux.in 2009-11-25 18:13:35 +0000
+++ util/grub.d/10_linux.in 2009-12-08 00:54:38 +0000
@@ -59,6 +59,7 @@ linux_entry ()
title="$(gettext "%s, with Linux %s")"
fi
printf "menuentry \"${title}\" {\n" "${os}" "${version}"
+ save_default_entry | sed -e "s/^/\t/"
if [ -z "${prepare_boot_cache}" ]; then
prepare_boot_cache="$(prepare_grub_to_access_device ${GRUB_DEVICE_BOOT} | sed -e "s/^/\t/")"
fi
=== modified file 'util/grub.d/10_windows.in'
--- util/grub.d/10_windows.in 2009-08-08 17:59:19 +0000
+++ util/grub.d/10_windows.in 2009-12-08 00:47:44 +0000
@@ -73,6 +73,7 @@ for dir in $dirlist ; do
menuentry "$OS" {
EOF
+ save_default_entry | sed -e 's,^,\t,'
prepare_grub_to_access_device "$dev" | sed 's,^,\t,'
cat << EOF
=== modified file 'util/grub.d/30_os-prober.in'
--- util/grub.d/30_os-prober.in 2009-12-22 11:02:57 +0000
+++ util/grub.d/30_os-prober.in 2010-01-05 10:51:08 +0000
@@ -41,6 +41,7 @@ osx_entry() {
cat << EOF
menuentry "${LONGNAME} (${2}-bit) (on ${DEVICE})" {
EOF
+ save_default_entry | sed -e "s/^/\t/"
prepare_grub_to_access_device ${DEVICE} | sed -e "s/^/\t/"
cat << EOF
insmod ${GRUB_VIDEO_BACKEND}
@@ -105,6 +106,7 @@ for OS in ${OSPROBED} ; do
cat << EOF
menuentry "${LONGNAME} (on ${DEVICE})" {
EOF
+ save_default_entry | sed -e "s/^/\t/"
prepare_grub_to_access_device ${DEVICE} | sed -e "s/^/\t/"
case ${LONGNAME} in
@@ -146,6 +148,7 @@ EOF
cat << EOF
menuentry "${LLABEL} (on ${DEVICE})" {
EOF
+ save_default_entry | sed -e "s/^/\t/"
if [ -z "${prepare_boot_cache}" ]; then
prepare_boot_cache="$(prepare_grub_to_access_device ${LBOOT} | sed -e "s/^/\t/")"
fi
@@ -172,6 +175,7 @@ EOF
cat << EOF
menuentry "${LONGNAME} (on ${DEVICE})" {
EOF
+ save_default_entry | sed -e "s/^/\t/"
prepare_grub_to_access_device ${DEVICE} | sed -e "s/^/\t/"
grub_device="`${grub_probe} --device ${DEVICE} --target=drive`"
mach_device="`echo "${grub_device}" | tr -d '()' | tr , s`"
=== modified file 'util/i386/efi/grub-install.in'
--- util/i386/efi/grub-install.in 2009-12-24 22:23:22 +0000
+++ util/i386/efi/grub-install.in 2010-01-05 10:49:59 +0000
@@ -35,6 +35,7 @@ pkglibdir=${libdir}/`echo ${PACKAGE_TARN
grub_mkimage=${bindir}/`echo grub-mkimage | sed ${transform}`
grub_mkdevicemap=${sbindir}/`echo grub-mkdevicemap | sed ${transform}`
grub_probe=${sbindir}/`echo grub-probe | sed ${transform}`
+grub_editenv=${bindir}/`echo grub-editenv | sed ${transform}`
rootdir=
grub_prefix=`echo /boot/grub | sed ${transform}`
modules=
@@ -179,6 +180,10 @@ for file in ${pkglibdir}/*.mod ${pkglibd
cp -f $file ${grubdir} || exit 1
done
+if ! test -f ${grubdir}/grubenv; then
+ $grub_editenv ${grubdir}/grubenv create
+fi
+
# Create the core image. First, auto-detect the filesystem module.
fs_module=`$grub_probe --target=fs --device-map=${device_map} ${grubdir}`
if test "x$fs_module" = xfat; then :; else
=== modified file 'util/ieee1275/grub-install.in'
--- util/ieee1275/grub-install.in 2008-08-14 18:59:33 +0000
+++ util/ieee1275/grub-install.in 2009-12-08 00:47:44 +0000
@@ -37,6 +37,7 @@ pkglibdir=${libdir}/`echo ${PACKAGE_TARN
grub_mkimage=${bindir}/`echo grub-mkelfimage | sed ${transform}`
grub_mkdevicemap=${sbindir}/`echo grub-mkdevicemap | sed ${transform}`
grub_probe=${sbindir}/`echo grub-probe | sed ${transform}`
+grub_editenv=${bindir}/`echo grub-editenv | sed ${transform}`
rootdir=
grub_prefix=`echo /boot/grub | sed ${transform}`
modules=
@@ -163,6 +164,10 @@ for file in ${pkglibdir}/*.mod ${pkglibd
cp -f $file ${grubdir} || exit 1
done
+if ! test -f ${grubdir}/grubenv; then
+ $grub_editenv ${grubdir}/grubenv create
+fi
+
# Create the core image. First, auto-detect the filesystem module.
fs_module=`$grub_probe --target=fs --device-map=${device_map} ${grubdir}`
if test "x$fs_module" = x -a "x$modules" = x; then
--
Colin Watson [cjwatson@ubuntu.com]
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Problems with grub-reboot/savedefault/default=saved
2010-01-05 11:08 ` Colin Watson
@ 2010-01-05 11:33 ` Vladimir 'φ-coder/phcoder' Serbinenko
2010-01-05 11:48 ` Colin Watson
2010-01-07 5:22 ` Jordan Uggla
1 sibling, 1 reply; 11+ messages in thread
From: Vladimir 'φ-coder/phcoder' Serbinenko @ 2010-01-05 11:33 UTC (permalink / raw)
To: The development of GNU GRUB
[-- Attachment #1: Type: text/plain, Size: 1653 bytes --]
Colin Watson wrote:
>> 4: Even with the first grub-reboot fix the default is still not restored
>> when grubenv is not writable ( /boot on lvm for example ). Since
>> grub-reboot can't work without a writable grubenv it's at least safer to
>> boot into the "real" default instead of the "temporary" default. The
>> fourth patch sets default=$prev_saved_default if save_env fails.
>> Grub-reboot ( the utility ) should also complain when grubenv isn't
>> writable by grub. What is the best way to determine that grubenv likely is
>> or isn't writable by grub?
>>
>
> I don't understand why /boot on LVM should mean that grubenv is not
> writable. The point of grubenv is to be a short chunk of contiguous
> reserved disk space which can be written by GRUB without needing any
> special filesystem intelligence. Surely LVM doesn't split up those 1024
> bytes into different physical extents?
>
>
Consider a RAID-1 (mirror). Currently GRUB2 uses only one disk of the
mirror. It may even be possible that second disk is inaccessible through
currently loaded drivers. But writing would need to update all copies.
And what to do if second disk isn't accessible? Same problem is present
in other RAID levels too.
ZFS and btrfs have checksums. If you update a block you have to update
its checksum too, and checksum of block containg checksum and so on. So
at the end of the day the whole is more complicated that what we wanted.
And a mistake in writing code may lead to corruption of unrelated data.
IMO for long-term we need a better place for grubenv.
--
Regards
Vladimir 'φ-coder/phcoder' Serbinenko
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 293 bytes --]
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Problems with grub-reboot/savedefault/default=saved
2010-01-05 11:33 ` Vladimir 'φ-coder/phcoder' Serbinenko
@ 2010-01-05 11:48 ` Colin Watson
0 siblings, 0 replies; 11+ messages in thread
From: Colin Watson @ 2010-01-05 11:48 UTC (permalink / raw)
To: The development of GNU GRUB
On Tue, Jan 05, 2010 at 12:33:23PM +0100, Vladimir 'φ-coder/phcoder' Serbinenko wrote:
> Colin Watson wrote:
> > I don't understand why /boot on LVM should mean that grubenv is not
> > writable. The point of grubenv is to be a short chunk of contiguous
> > reserved disk space which can be written by GRUB without needing any
> > special filesystem intelligence. Surely LVM doesn't split up those 1024
> > bytes into different physical extents?
>
> Consider a RAID-1 (mirror). Currently GRUB2 uses only one disk of the
> mirror. It may even be possible that second disk is inaccessible through
> currently loaded drivers. But writing would need to update all copies.
> And what to do if second disk isn't accessible? Same problem is present
> in other RAID levels too.
> ZFS and btrfs have checksums. If you update a block you have to update
> its checksum too, and checksum of block containg checksum and so on. So
> at the end of the day the whole is more complicated that what we wanted.
> And a mistake in writing code may lead to corruption of unrelated data.
I see. Perhaps in the short term we could have an extension to the test
command to allow grub.cfg to determine whether grubenv is sanely
writable?
> IMO for long-term we need a better place for grubenv.
I agree, although the question is where. If there were enough space in
the embedding area then we could reserve a chunk of that, but aren't we
generally pretty close to the limit there?
--
Colin Watson [cjwatson@ubuntu.com]
^ permalink raw reply [flat|nested] 11+ messages in thread
* Embedding area too small... (GRUB2 on software RAID1)
2010-01-05 11:23 ` Colin Watson
@ 2010-01-05 18:30 ` Lapohos Tibor
0 siblings, 0 replies; 11+ messages in thread
From: Lapohos Tibor @ 2010-01-05 18:30 UTC (permalink / raw)
To: grub-devel, grub-help, linux-raid
[-- Attachment #1: Type: text/plain, Size: 1887 bytes --]
Hello,
I successfully set up an Intel Matrix Raid device with a RAID1 and a RAID0 volume, each having a couple of partitions, but then I could not install GRUB2 on the RAID1 volume, which I wanted to use to boot from and mount as root. It turned out that the "IMSM" metadata is not supported in GRUB2 (v1.97.1) just yet, so I had to turn away from my original plan.
To "imitate" the setup I originally wanded, I turned both of my drives into AHCI controlled devices in the BIOS (instead of RAID), and I partitioned them to obtain /dev/sda[12] and /dev/sdb[12].
Then I used /dev/sd[ab]1 to build a RAID1 set, and /dev/sd[ab]2 to create a RAID0 set using mdadm v 3.0.3:
> mdadm -C /dev/md0 -v -e 0 -l 1 -n 2 /dev/sda1 /dev/sdb1
> mdadm -C /dev/md1 -v -e 0 -l 0 -n 2 /dev/sda2 /dev/sdb2
I set the metadata type to 0.90 because I would like to boot from it and allow the kernel to auto-detect the RAID devices while it's booting, in order to can get away from using an intitrd (I am building my own distribution based on CLFS x86_64 multilib).
I used cfdisk to partition both of the /dev/md[01] devices, and I obtained /dev/md0p[123] and /dev/md1p[12]. The plan is to use /dev/md0p1 as a RAID1 root partition, and have the system boot from /dev/md0. I formatted /dev/md0p1 as
> mk2efs -t ext4 -L OS /dev/md0p1
To this point, things went smoothly. mdadm -D... and mdadm -E... did report back working devices as intended. Then mounted /dev/md0p1 on a directory called /root/os, and I did
> grub-install --root-directory=/root/os /dev/md0
or
> grub-install --root-directory=/root/os "md0"
and I got a warning and an error message: "Embedding area is too small for core.img." and "Embedding is not possible, but this is required when the root device is on a RAID array or LVM volume."
What did I do wrong, and how do I fix it? Thanks ahead,
Tibor
[-- Attachment #2: Type: text/html, Size: 2806 bytes --]
^ permalink raw reply [flat|nested] 11+ messages in thread
* Embedding area too small... (GRUB2 on software RAID1)
@ 2010-01-05 18:30 ` Lapohos Tibor
0 siblings, 0 replies; 11+ messages in thread
From: Lapohos Tibor @ 2010-01-05 18:30 UTC (permalink / raw)
To: grub-devel, grub-help, linux-raid
[-- Attachment #1.1: Type: text/plain, Size: 1887 bytes --]
Hello,
I successfully set up an Intel Matrix Raid device with a RAID1 and a RAID0 volume, each having a couple of partitions, but then I could not install GRUB2 on the RAID1 volume, which I wanted to use to boot from and mount as root. It turned out that the "IMSM" metadata is not supported in GRUB2 (v1.97.1) just yet, so I had to turn away from my original plan.
To "imitate" the setup I originally wanded, I turned both of my drives into AHCI controlled devices in the BIOS (instead of RAID), and I partitioned them to obtain /dev/sda[12] and /dev/sdb[12].
Then I used /dev/sd[ab]1 to build a RAID1 set, and /dev/sd[ab]2 to create a RAID0 set using mdadm v 3.0.3:
> mdadm -C /dev/md0 -v -e 0 -l 1 -n 2 /dev/sda1 /dev/sdb1
> mdadm -C /dev/md1 -v -e 0 -l 0 -n 2 /dev/sda2 /dev/sdb2
I set the metadata type to 0.90 because I would like to boot from it and allow the kernel to auto-detect the RAID devices while it's booting, in order to can get away from using an intitrd (I am building my own distribution based on CLFS x86_64 multilib).
I used cfdisk to partition both of the /dev/md[01] devices, and I obtained /dev/md0p[123] and /dev/md1p[12]. The plan is to use /dev/md0p1 as a RAID1 root partition, and have the system boot from /dev/md0. I formatted /dev/md0p1 as
> mk2efs -t ext4 -L OS /dev/md0p1
To this point, things went smoothly. mdadm -D... and mdadm -E... did report back working devices as intended. Then mounted /dev/md0p1 on a directory called /root/os, and I did
> grub-install --root-directory=/root/os /dev/md0
or
> grub-install --root-directory=/root/os "md0"
and I got a warning and an error message: "Embedding area is too small for core.img." and "Embedding is not possible, but this is required when the root device is on a RAID array or LVM volume."
What did I do wrong, and how do I fix it? Thanks ahead,
Tibor
[-- Attachment #1.2: Type: text/html, Size: 2806 bytes --]
[-- Attachment #2: Type: text/plain, Size: 140 bytes --]
_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/grub-devel
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Problems with grub-reboot/savedefault/default=saved
2010-01-05 11:08 ` Colin Watson
2010-01-05 11:33 ` Vladimir 'φ-coder/phcoder' Serbinenko
@ 2010-01-07 5:22 ` Jordan Uggla
2010-02-25 13:38 ` Colin Watson
1 sibling, 1 reply; 11+ messages in thread
From: Jordan Uggla @ 2010-01-07 5:22 UTC (permalink / raw)
To: The development of GNU GRUB
On Tue, Jan 5, 2010 at 3:08 AM, Colin Watson <cjwatson@ubuntu.com> wrote:
>> 2: Setting GRUB_DEFAULT=saved in /etc/default/grub also enables savedefault
>> functionality. There are many people who would want to use grub-reboot and
>> grub-set-default without savedefault. The second patch adds a separate
>> variable, GRUB_SAVEDEFAULT, for enabling savedefault.
>
> How would this interact with setting GRUB_DEFAULT to something other
> than "saved", and doesn't 00_header.in also need to be changed to
> actually use the saved entry (it won't be used unless you have
> GRUB_DEFAULT=saved)?
That's correct. Perhaps GRUB_SAVEDEFAULT=true should imply GRUB_DEFAULT=saved?
( if [ "x${GRUB_DEFAULT}" = "xsaved" -o x${GRUB_SAVEDEFAULT} =
"xtrue" ] ; then GRUB_DEFAULT='${saved_entry}' ; )
> In my mind, GRUB_DEFAULT was overloaded for this for a good reason; but
> perhaps I'm simply not understanding what you mean, so would you mind
> explaining further how you'd like to see the whole thing laid out?
I am not set on a single layout ( I'd like input from others on
exactly how this should work ). But I do think that it should be
possible to use utilities like grub-set-default and grub-reboot
without also enabling savedefault. As an example use case:
Jane has a server with two boot options, one is a well tested, known
working, configuration and the other is a system for experimenting.
When she has physical access to the server she can select the
experimental option and if anything goes wrong she can reboot into the
stable configuration if needed. When she is administering the server
remotely though, she needs to be sure that she won't completely lose
access to the server if the experimental system fails to boot ( or
bring up the network connection / ssh properly ).
Because of this problem, Jane always wants the safe configuration to
be the default so that if anything goes wrong she can simply power
cycle the machine and fix things from the working system ( I'm not
sure why it's so common that people have the ability to remotely power
cycle but no remote access the console to be able to use the grub
menu, but every person I have talked to that uses grub-reboot is in
such a situation ). If she is in the safe configuration and wants to
remotely switch to the experimental one she uses grub-reboot to
temporarily change the default. Note that she never wants to change
the default permanently, but that's what savedefault will do if she
selects the experimental boot option from the grub menu ( rather than
grub-reboot ) and safedefault is being used.
I would guess, though I have no data to back it up, that in fact most
grub-reboot users do not want to use savedefault.
>> 5: Since grub2 uses menu entry titles for savedefault instead of numbers,
>> the default kernel booted won't be changed when the user installs a new
>> kernel. Using titles instead of numbers is good, but an unfortunate
>> consequence that users may not realize ( and was not true with savedefault
>> in grub-legacy ) is that if users set GRUB_SAVEDEFAULT=true they will never
>> actually boot any updated kernels unless they select them manually at the
>> grub menu. This could lead to not getting security updates for the kernel,
>> and with major upgrades could cause serious problems when the old kernel
>> doesn't work with newer userland components like Xorg. I can't think of a
>> good way to solve this problem.
>
> IIRC GRUB Legacy (or at least Debian's update-grub, once upon a time)
> handled this by having a special "default" entry at the top of the Linux
> kernel list. Would it be worth introducing this to grub-mkconfig?
Recently Vladimir has talked about having submenus ( one debian menu
with separate kernel versions in a submenu for instance ) which will
probably help solve this problem.
--
Jordan Uggla ( Jordan_U on irc.freenode.net )
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Problems with grub-reboot/savedefault/default=saved
2010-01-07 5:22 ` Jordan Uggla
@ 2010-02-25 13:38 ` Colin Watson
0 siblings, 0 replies; 11+ messages in thread
From: Colin Watson @ 2010-02-25 13:38 UTC (permalink / raw)
To: grub-devel
On Wed, Jan 06, 2010 at 09:22:15PM -0800, Jordan Uggla wrote:
> On Tue, Jan 5, 2010 at 3:08 AM, Colin Watson <cjwatson@ubuntu.com> wrote:
> >> 2: Setting GRUB_DEFAULT=saved in /etc/default/grub also enables savedefault
> >> functionality. There are many people who would want to use grub-reboot and
> >> grub-set-default without savedefault. The second patch adds a separate
> >> variable, GRUB_SAVEDEFAULT, for enabling savedefault.
> >
> > How would this interact with setting GRUB_DEFAULT to something other
> > than "saved", and doesn't 00_header.in also need to be changed to
> > actually use the saved entry (it won't be used unless you have
> > GRUB_DEFAULT=saved)?
>
> That's correct. Perhaps GRUB_SAVEDEFAULT=true should imply GRUB_DEFAULT=saved?
>
> ( if [ "x${GRUB_DEFAULT}" = "xsaved" -o x${GRUB_SAVEDEFAULT} =
> "xtrue" ] ; then GRUB_DEFAULT='${saved_entry}' ; )
I've left them independent for now, since I'm not sure I've thought this
through properly. (For instance you might want to change the saved
entry but not use it right away for some reason?)
> > In my mind, GRUB_DEFAULT was overloaded for this for a good reason; but
> > perhaps I'm simply not understanding what you mean, so would you mind
> > explaining further how you'd like to see the whole thing laid out?
>
> I am not set on a single layout ( I'd like input from others on
> exactly how this should work ). But I do think that it should be
> possible to use utilities like grub-set-default and grub-reboot
> without also enabling savedefault. As an example use case:
[...]
Thanks for the explanation. I agree now, and have committed your patch.
--
Colin Watson [cjwatson@ubuntu.com]
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2010-02-25 13:38 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-12-16 22:28 Problems with grub-reboot/savedefault/default=saved Jordan Uggla
2009-12-20 8:37 ` Jordan Uggla
2010-01-05 11:23 ` Colin Watson
2010-01-05 18:30 ` Embedding area too small... (GRUB2 on software RAID1) Lapohos Tibor
2010-01-05 18:30 ` Lapohos Tibor
2009-12-23 2:03 ` Problems with grub-reboot/savedefault/default=saved Colin Watson
2010-01-05 11:08 ` Colin Watson
2010-01-05 11:33 ` Vladimir 'φ-coder/phcoder' Serbinenko
2010-01-05 11:48 ` Colin Watson
2010-01-07 5:22 ` Jordan Uggla
2010-02-25 13:38 ` Colin Watson
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.