* [PATCH] system: grub: Add 'libreboot?' install flag.
@ 2016-02-02 21:24 Jookia
2016-02-04 21:35 ` Ludovic Courtès
0 siblings, 1 reply; 4+ messages in thread
From: Jookia @ 2016-02-02 21:24 UTC (permalink / raw)
To: guix-devel
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 9747 bytes --]
Libreboot doesn't read GRUB from the disk, it chainloads configuration files. As
such, grub-install is known to fail and require fragile workarounds. To solve
this issue, there's now a 'libreboot?' boolean flag that will instead use
'/boot/grub/libreboot_grub.cfg' for the GRUB menu and not run 'grub-install'.
* gnu/system/grub.scm (<grub-configuration>): Add and export 'libreboot?' flag.
* doc/guix.texi (GRUB Configuration): Explain the 'libreboot?' flag.
* guix/scripts/system.scm: Read and use 'libreboot?' flag when installing GRUB.
(process-action): Read GRUB's 'libreboot?' flag and pass it to perform-action.
(perform-action): Pass the 'libreboot?' flag to 'install-grub*' and 'install'.
(install): Pass the 'libreboot?' flag to install-grub*.
(install-grub*): Pass the 'libreboot?' flag to install-grub.
* gnu/build/install.scm (install-grub): Read 'libreboot?' flag and based on this
decide where to put the grub.cfg file and whether to run grub-install.
---
doc/guix.texi | 6 ++++++
gnu/build/install.scm | 21 +++++++++++++--------
gnu/system/grub.scm | 4 ++++
guix/scripts/system.scm | 23 ++++++++++++++---------
4 files changed, 37 insertions(+), 17 deletions(-)
diff --git a/doc/guix.texi b/doc/guix.texi
index 11664f4..704809f 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -17,6 +17,7 @@ Copyright @copyright{} 2015 Mathieu Lirzin@*
Copyright @copyright{} 2014 Pierre-Antoine Rault@*
Copyright @copyright{} 2015 Taylan Ulrich Bayırlı/Kammer@*
Copyright @copyright{} 2015, 2016 Leo Famulari
+Copyright @copyright{} 2016 Jookia
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
@@ -9132,6 +9133,11 @@ understood by the @command{grub-install} command, such as
@code{/dev/sda} or @code{(hd0)} (@pxref{Invoking grub-install,,, grub,
GNU GRUB Manual}).
+@item @code{libreboot?} (default: @code{#f})
+Setting this boolean to true will tweak GRUB for systems running Libreboot with
+the GRUB payload. Instead of installing GRUB to disk, a configuration will be
+put in @code{/boot/grub/libreboot_grub.cfg} for Libreboot to load.
+
@item @code{menu-entries} (default: @code{()})
A possibly empty list of @code{menu-entry} objects (see below), denoting
entries to appear in the GRUB boot menu, in addition to the current
diff --git a/gnu/build/install.scm b/gnu/build/install.scm
index 9785b6d..471ff58 100644
--- a/gnu/build/install.scm
+++ b/gnu/build/install.scm
@@ -1,5 +1,6 @@
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2013, 2014, 2015 Ludovic Courtès <ludo@gnu.org>
+;;; Copyright © 2016 Jookia <166291@gmail.com>
;;;
;;; This file is part of GNU Guix.
;;;
@@ -36,15 +37,17 @@
;;;
;;; Code:
-(define* (install-grub grub.cfg device mount-point)
+(define* (install-grub grub.cfg device mount-point libreboot?)
"Install GRUB with GRUB.CFG on DEVICE, which is assumed to be mounted on
MOUNT-POINT.
Note that the caller must make sure that GRUB.CFG is registered as a GC root
so that the fonts, background images, etc. referred to by GRUB.CFG are not
GC'd."
- (let* ((target (string-append mount-point "/boot/grub/grub.cfg"))
- (pivot (string-append target ".new")))
+ (let* ((base (string-append mount-point "/boot/grub/"))
+ (target (string-append base "grub.cfg"))
+ (pivot (string-append target ".new"))
+ (librebooter (string-append base "libreboot_grub.cfg")))
(mkdir-p (dirname target))
;; Copy GRUB.CFG instead of just symlinking it, because symlinks won't
@@ -52,11 +55,13 @@ GC'd."
(copy-file grub.cfg pivot)
(rename-file pivot target)
- (unless (zero? (system* "grub-install" "--no-floppy"
- "--boot-directory"
- (string-append mount-point "/boot")
- device))
- (error "failed to install GRUB"))))
+ (if libreboot?
+ (rename-file target librebooter)
+ (unless (zero? (system* "grub-install" "--no-floppy"
+ "--boot-directory"
+ (string-append mount-point "/boot")
+ device))
+ (error "failed to install GRUB")))))
(define (evaluate-populate-directive directive target)
"Evaluate DIRECTIVE, an sexp describing a file or directory to create under
diff --git a/gnu/system/grub.scm b/gnu/system/grub.scm
index 45b46ca..d5a2df0 100644
--- a/gnu/system/grub.scm
+++ b/gnu/system/grub.scm
@@ -1,5 +1,6 @@
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2013, 2014, 2015, 2016 Ludovic Courtès <ludo@gnu.org>
+;;; Copyright © 2016 Jookia <166291@gmail.com>
;;;
;;; This file is part of GNU Guix.
;;;
@@ -50,6 +51,7 @@
grub-configuration
grub-configuration?
grub-configuration-device
+ grub-configuration-libreboot
menu-entry
menu-entry?
@@ -98,6 +100,8 @@
(grub grub-configuration-grub ; package
(default (@ (gnu packages grub) grub)))
(device grub-configuration-device) ; string
+ (libreboot? grub-configuration-libreboot ; bool
+ (default #f))
(menu-entries grub-configuration-menu-entries ; list
(default '()))
(default-entry grub-configuration-default-entry ; integer
diff --git a/guix/scripts/system.scm b/guix/scripts/system.scm
index e31eec6..d0e7e77 100644
--- a/guix/scripts/system.scm
+++ b/guix/scripts/system.scm
@@ -1,6 +1,7 @@
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2014, 2015 Ludovic Courtès <ludo@gnu.org>
;;; Copyright © 2016 Alex Kost <alezost@gmail.com>
+;;; Copyright © 2016 Jookia <166291@gmail.com>
;;;
;;; This file is part of GNU Guix.
;;;
@@ -122,7 +123,7 @@ TARGET, and register them."
(map (cut copy-item <> target #:log-port log-port)
to-copy))))
-(define (install-grub* grub.cfg device target)
+(define (install-grub* grub.cfg device target libreboot?)
"This is a variant of 'install-grub' with error handling, lifted in
%STORE-MONAD"
(let* ((gc-root (string-append %gc-roots-directory "/grub.cfg"))
@@ -135,7 +136,7 @@ TARGET, and register them."
;; 'install-grub' completes (being a bit paranoid.)
(make-symlink temp-gc-root grub.cfg)
- (munless (false-if-exception (install-grub grub.cfg device target))
+ (munless (false-if-exception (install-grub grub.cfg device target libreboot?))
(delete-file temp-gc-root)
(leave (_ "failed to install GRUB on device '~a'~%") device))
@@ -145,7 +146,7 @@ TARGET, and register them."
(define* (install os-drv target
#:key (log-port (current-output-port))
- grub? grub.cfg device)
+ grub? grub.cfg device libreboot?)
"Copy the closure of GRUB.CFG, which includes the output of OS-DRV, to
directory TARGET. TARGET must be an absolute directory name since that's what
'guix-register' expects.
@@ -188,7 +189,7 @@ the ownership of '~a' may be incorrect!~%")
(populate os-dir target)
(mwhen grub?
- (install-grub* grub.cfg device target)))))
+ (install-grub* grub.cfg device target libreboot?)))))
\f
;;;
@@ -391,7 +392,7 @@ PATTERN, a string. When PATTERN is #f, display all the system generations."
(define* (perform-action action os
#:key grub? dry-run? derivations-only?
- use-substitutes? device target
+ use-substitutes? device libreboot? target
image-size full-boot?
(mappings '()))
"Perform ACTION for OS. GRUB? specifies whether to install GRUB; DEVICE is
@@ -451,7 +452,7 @@ building anything."
(switch-to-system os)
(mwhen grub?
(install-grub* (derivation->output-path grub.cfg)
- device "/"))))
+ device "/" libreboot?))))
((init)
(newline)
(format #t (_ "initializing operating system under '~a'...~%")
@@ -459,7 +460,8 @@ building anything."
(install sys (canonicalize-path target)
#:grub? grub?
#:grub.cfg (derivation->output-path grub.cfg)
- #:device device))
+ #:device device
+ #:libreboot? libreboot?))
(else
;; All we had to do was to build SYS.
(return (derivation->output-path sys))))))))
@@ -626,7 +628,9 @@ resulting from command-line parsing."
(_ #f)))
(device (and grub?
(grub-configuration-device
- (operating-system-bootloader os)))))
+ (operating-system-bootloader os))))
+ (libreboot? (grub-configuration-libreboot
+ (operating-system-bootloader os))))
(with-store store
(set-build-options-from-command-line store opts)
@@ -653,7 +657,8 @@ resulting from command-line parsing."
(_ #f))
opts)
#:grub? grub?
- #:target target #:device device))))
+ #:target target #:device device
+ #:libreboot? libreboot?))))
#:system system))))
(define (process-command command args opts)
--
2.7.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] system: grub: Add 'libreboot?' install flag.
2016-02-02 21:24 [PATCH] system: grub: Add 'libreboot?' install flag Jookia
@ 2016-02-04 21:35 ` Ludovic Courtès
2016-03-09 21:37 ` Danny Milosavljevic
0 siblings, 1 reply; 4+ messages in thread
From: Ludovic Courtès @ 2016-02-04 21:35 UTC (permalink / raw)
To: Jookia; +Cc: guix-devel
Jookia <166291@gmail.com> skribis:
> Libreboot doesn't read GRUB from the disk, it chainloads configuration files. As
> such, grub-install is known to fail and require fragile workarounds. To solve
> this issue, there's now a 'libreboot?' boolean flag that will instead use
> '/boot/grub/libreboot_grub.cfg' for the GRUB menu and not run 'grub-install'.
Glad you’re streamlining it! Unfortunately I don’t (yet!) have access
to Libreboot-capable hardware, so I’ll let Mark comment on the method.
Some “superficial” comments follow.
> * gnu/system/grub.scm (<grub-configuration>): Add and export 'libreboot?' flag.
> * doc/guix.texi (GRUB Configuration): Explain the 'libreboot?' flag.
> * guix/scripts/system.scm: Read and use 'libreboot?' flag when installing GRUB.
> (process-action): Read GRUB's 'libreboot?' flag and pass it to perform-action.
> (perform-action): Pass the 'libreboot?' flag to 'install-grub*' and 'install'.
> (install): Pass the 'libreboot?' flag to install-grub*.
> (install-grub*): Pass the 'libreboot?' flag to install-grub.
> * gnu/build/install.scm (install-grub): Read 'libreboot?' flag and based on this
[...]
> Copyright @copyright{} 2015 Taylan Ulrich Bayırlı/Kammer@*
> Copyright @copyright{} 2015, 2016 Leo Famulari
> +Copyright @copyright{} 2016 Jookia
Add “@*” at the end of the previous line so that a newline gets
inserted.
> +@item @code{libreboot?} (default: @code{#f})
> +Setting this boolean to true will tweak GRUB for systems running Libreboot with
s/boolean/Boolean/
> +the GRUB payload. Instead of installing GRUB to disk, a configuration will be
> +put in @code{/boot/grub/libreboot_grub.cfg} for Libreboot to load.
s/a configuration will be put in @code/configuration is written to @file/
It would be nice to link to the relevant Libreboot documentation, if
possible.
> + (if libreboot?
> + (rename-file target librebooter)
> + (unless (zero? (system* "grub-install" "--no-floppy"
Please align below the ‘l’ of ‘libreboot?’.
> + (libreboot? grub-configuration-libreboot ; bool
> + (default #f))
s/bool/Boolean/ :-)
It’s a bit annoying that we have to pass the ‘libreboot?’ parameter
across functions.
Thanks for working on it!
Ludo’.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] system: grub: Add 'libreboot?' install flag.
2016-02-04 21:35 ` Ludovic Courtès
@ 2016-03-09 21:37 ` Danny Milosavljevic
2016-03-09 22:49 ` Jookia
0 siblings, 1 reply; 4+ messages in thread
From: Danny Milosavljevic @ 2016-03-09 21:37 UTC (permalink / raw)
To: Ludovic Courtès; +Cc: guix-devel
Hi,
just adding a few bits of information:
It's true that libreboot can (and does) source other grub config files. GRUB should also be able to chainload other bootloaders, however I tried that several times now and it just doesn't work. Is this a known limitation?
insmod ahci
insmod ext2
insmod part_msdos
insmod chain
set default=0
set timeout=1
submenu "Load Config" 0 {
root=(ahci0,msdos1)
source /boot/grub/grub.cfg <--- works
unset superusers
}
menuentry "Chainload GuixSD" {
chainloader (ahci0)+1 <-- doesn't work, "unknown payload"
}
But I can confirm that having /boot/grub/libreboot_grub.cfg makes libreboot use that by default (after a 1 second or so delay where you can choose something else for it to do).
Personally, I just use
$ ln -s grub.cfg /boot/grub/libreboot_grub.cfg
without any other patches instead. Works fine. Also auto-updates.
The default libreboot grub config (in flash) is:
set prefix=(memdisk)/boot/grub
insmod nativedisk
insmod ehci
insmod ohci
insmod uhci
insmod usb
insmod usbserial_pl2303
insmod usbserial_ftdi
insmod usbserial_usbdebug
# Serial and keyboard configuration, very important.
serial --speed=115200 --unit=0 --word=8 --parity=no --stop=1
terminal_input --append serial
terminal_output --append serial
terminal_input --append at_keyboard
gfxpayload=keep
terminal_output --append gfxterm
# Default to first option, automatically boot after 1 second
set default="0"
set timeout=1
# This is useful when using 'cat' on long files on GRUB terminal
set pager=1
# # Play a beep on startup
# play 480 440 1
insmod jpeg
background_image (cbfsdisk)/background.jpg
loadfont (memdisk)/dejavusansmono.pf2
keymap ukqwerty
menuentry 'Load Operating System' {
insmod ahci
insmod part_msdos
insmod part_gpt
for x in (ahci0,1) (ahci0,2) (ahci0,3) (ahci0,4); do
if [ -f "$x/grub/libreboot_grub.cfg" ] ; then
set root=$x
configfile /grub/libreboot_grub.cfg
fi
if [ -f "$x/boot/grub/libreboot_grub.cfg" ] ; then
set root=$x
configfile /boot/grub/libreboot_grub.cfg
fi
done
set root='ahci0,1'
linux /vmlinuz root=/dev/sda1 rw
if [ -f "/initrd.img" ] ; then
initrd /initrd.img
fi
}
menuentry 'Parse ISOLINUX menu (ahci0)' {
insmod ahci
insmod part_msdos
insmod part_gpt
for x in (ahci0,1) (ahci0,2) (ahci0,3) (ahci0,4); do
set root=$x
if [ -f "/isolinux/isolinux.cfg" ] ; then
syslinux_configfile -i /isolinux/isolinux.cfg
elif [ -f "/syslinux/syslinux.cfg" ] ; then
syslinux_configfile -i /syslinux/syslinux.cfg
elif [ -f "/boot/isolinux/isolinux.cfg" ] ; then
syslinux_configfile -i /boot/isolinux/isolinux.cfg
elif [ -f "/boot/syslinux/syslinux.cfg" ] ; then
syslinux_configfile -i /boot/syslinux/syslinux.cfg
fi
done
}
menuentry 'Parse ISOLINUX menu (USB)' {
insmod usbms
insmod part_msdos
insmod part_gpt
for x in (usb0) (usb0,1) (usb0,2) (usb0,3) (usb0,4); do
set root=$x
if [ -f "/isolinux/isolinux.cfg" ] ; then
syslinux_configfile -i /isolinux/isolinux.cfg
elif [ -f "/syslinux/syslinux.cfg" ] ; then
syslinux_configfile -i /syslinux/syslinux.cfg
elif [ -f "/boot/isolinux/isolinux.cfg" ] ; then
syslinux_configfile -i /boot/isolinux/isolinux.cfg
elif [ -f "/boot/syslinux/syslinux.cfg" ] ; then
syslinux_configfile -i /boot/syslinux/syslinux.cfg
fi
done
}
menuentry 'Parse ISOLINUX menu (CD/DVD)' {
insmod ahci
insmod ata
insmod iso9660
for x in (ata0) (ahci1); do
set root=$x
if [ -f "/isolinux/isolinux.cfg" ] ; then
syslinux_configfile -i /isolinux/isolinux.cfg
elif [ -f "/syslinux/syslinux.cfg" ] ; then
syslinux_configfile -i /syslinux/syslinux.cfg
elif [ -f "/boot/isolinux/isolinux.cfg" ] ; then
syslinux_configfile -i /boot/isolinux/isolinux.cfg
elif [ -f "/boot/syslinux/syslinux.cfg" ] ; then
syslinux_configfile -i /boot/syslinux/syslinux.cfg
fi
done
}
menuentry 'Switch to grubtest.cfg' {
set root='cbfsdisk'
configfile (cbfsdisk)/grubtest.cfg
}
menuentry 'Search for GRUB configuration (grub.cfg) outside of CBFS' {
insmod ahci
insmod usbms
insmod part_msdos
insmod part_gpt
for x in (ahci0,1) (ahci0,2) (ahci0,3) (ahci0,4) (usb0) (usb0,1) (usb0,2) (usb0,3) (usb0,4); do
if [ -f "$x/grub/grub.cfg" ] ; then
submenu "Load Config from $x" $x {
root=$2
source /grub/grub.cfg
unset superusers
}
fi
if [ -f "$x/boot/grub/grub.cfg" ] ; then
submenu "Load Config from $x" $x {
root=$2
source /boot/grub/grub.cfg
unset superusers
}
fi
if [ -f "$x/grub2/grub.cfg" ] ; then
submenu "Load Config from $x" $x {
root=$2
source /grub2/grub.cfg
unset superusers
}
fi
if [ -f "$x/boot/grub2/grub.cfg" ] ; then
submenu "Load Config from $x" $x {
root=$2
source /boot/grub2/grub.cfg
unset superusers
}
fi
done
}
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] system: grub: Add 'libreboot?' install flag.
2016-03-09 21:37 ` Danny Milosavljevic
@ 2016-03-09 22:49 ` Jookia
0 siblings, 0 replies; 4+ messages in thread
From: Jookia @ 2016-03-09 22:49 UTC (permalink / raw)
To: Danny Milosavljevic; +Cc: guix-devel
On Wed, Mar 09, 2016 at 10:37:43PM +0100, Danny Milosavljevic wrote:
> Hi,
Hi there, this is an old patch set so if you intend on using it you should use
my newer RFC posted earlier this month. :)
> just adding a few bits of information:
>
> It's true that libreboot can (and does) source other grub config files. GRUB should also be able to chainload other bootloaders, however I tried that several times now and it just doesn't work. Is this a known limitation?
>
> insmod ahci
> insmod ext2
> insmod part_msdos
> insmod chain
>
> set default=0
> set timeout=1
>
> submenu "Load Config" 0 {
> root=(ahci0,msdos1)
> source /boot/grub/grub.cfg <--- works
> unset superusers
> }
>
> menuentry "Chainload GuixSD" {
> chainloader (ahci0)+1 <-- doesn't work, "unknown payload"
> }
I'm unsure if it can chainload from another drive's MBR like this.
> But I can confirm that having /boot/grub/libreboot_grub.cfg makes libreboot use that by default (after a 1 second or so delay where you can choose something else for it to do).
>
> Personally, I just use
>
> $ ln -s grub.cfg /boot/grub/libreboot_grub.cfg
>
> without any other patches instead. Works fine. Also auto-updates.
Unfortunately this doesn't work for encrypted disks.
Jookia.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2016-03-09 22:51 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-02-02 21:24 [PATCH] system: grub: Add 'libreboot?' install flag Jookia
2016-02-04 21:35 ` Ludovic Courtès
2016-03-09 21:37 ` Danny Milosavljevic
2016-03-09 22:49 ` Jookia
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/guix.git
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.