Re: [PATCH] system: grub: Add 'libreboot?' install flag.

2016-03-09 Thread Jookia
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.



Re: [PATCH] system: grub: Add 'libreboot?' install flag.

2016-03-09 Thread Danny Milosavljevic
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 

Re: [PATCH] system: grub: Add 'libreboot?' install flag.

2016-02-04 Thread Ludovic Courtès
Jookia <166...@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 (): 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’.



[PATCH] system: grub: Add 'libreboot?' install flag.

2016-02-04 Thread Jookia
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 (): 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 
+;;; Copyright © 2016 Jookia <166...@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 
+;;; Copyright © 2016 Jookia <166...@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?
@@