From 8efda48496d1be5d47518f7903b5ada110738beb Mon Sep 17 00:00:00 2001 From: Shea Levy Date: Fri, 16 Mar 2012 05:37:24 +0000 Subject: [PATCH] Enable building an efi-bootable ISO svn path=/nixos/trunk/; revision=33140 --- lib/make-iso9660-image.nix | 9 ++++- lib/make-iso9660-image.sh | 3 ++ .../cd-dvd/installation-cd-new-kernel.nix | 16 ++++++++- modules/installer/cd-dvd/iso-image.nix | 36 +++++++++++++++++-- .../installer/efi-boot-stub/efi-boot-stub.nix | 2 +- 5 files changed, 61 insertions(+), 5 deletions(-) diff --git a/lib/make-iso9660-image.nix b/lib/make-iso9660-image.nix index 9dfde3e4a7c1..5ad546e9534d 100644 --- a/lib/make-iso9660-image.nix +++ b/lib/make-iso9660-image.nix @@ -19,9 +19,15 @@ , # Whether this should be an El-Torito bootable CD. bootable ? false +, # Whether this should be an efi-bootable El-Torito CD. + efiBootable ? false + , # The path (in the ISO file system) of the boot image. bootImage ? "" +, # The path (in the ISO file system) of the efi boot image. + efiBootImage ? "" + , # Whether to compress the resulting ISO image with bzip2. compressImage ? false @@ -31,13 +37,14 @@ }: assert bootable -> bootImage != ""; +assert efiBootable -> efiBootImage != ""; stdenv.mkDerivation { name = "iso9660-image"; builder = ./make-iso9660-image.sh; buildInputs = [perl cdrkit]; - inherit isoName bootable bootImage compressImage volumeID pathsFromGraph; + inherit isoName bootable bootImage compressImage volumeID pathsFromGraph efiBootImage efiBootable; # !!! should use XML. sources = map (x: x.source) contents; diff --git a/lib/make-iso9660-image.sh b/lib/make-iso9660-image.sh index c6996e8db9a5..89b681ed2cd5 100644 --- a/lib/make-iso9660-image.sh +++ b/lib/make-iso9660-image.sh @@ -34,6 +34,9 @@ if test -n "$bootable"; then bootFlags="-b $bootImage -c .boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table" fi +if test -n "$efiBootable"; then + bootFlags="$bootFlags -eltorito-alt-boot -e $efiBootImage -no-emul-boot" +fi touch pathlist diff --git a/modules/installer/cd-dvd/installation-cd-new-kernel.nix b/modules/installer/cd-dvd/installation-cd-new-kernel.nix index c7ea5ddfb01b..1d7af6401efc 100644 --- a/modules/installer/cd-dvd/installation-cd-new-kernel.nix +++ b/modules/installer/cd-dvd/installation-cd-new-kernel.nix @@ -3,6 +3,20 @@ { require = [ ./installation-cd-graphical.nix ]; - boot.kernelPackages = pkgs.linuxPackages_3_2; + boot.kernelPackages = pkgs.linuxPackages_3_3; boot.vesa = false; + + # What follows should probably move into base once the base kernel has the + # efi boot stub + + # Get a console as soon as the initrd loads fbcon on EFI boot + boot.initrd.kernelModules = [ "fbcon" ]; + + # Enable reading EFI variables via sysfs + boot.kernelModules = [ "efivars" ]; + + # efi-related tools + environment.systemPackages = [ pkgs.efibootmgr ]; + + isoImage.makeEfiBootable = true; } diff --git a/modules/installer/cd-dvd/iso-image.nix b/modules/installer/cd-dvd/iso-image.nix index 7cc08315d012..82acac9a3e58 100644 --- a/modules/installer/cd-dvd/iso-image.nix +++ b/modules/installer/cd-dvd/iso-image.nix @@ -73,6 +73,14 @@ let ''; }; + isoImage.makeEfiBootable = mkOption { + default = false; + description = '' + Whether the ISO image should be an efi-bootable volume + ''; + }; + + }; @@ -110,6 +118,20 @@ let ${config.boot.loader.grub.extraEntries} ''; + + # The boot params for the efi boot stub + bootParams = pkgs.runCommand "boot-params_eltorito" {} + '' + echo "\\boot\\bzImage initrd=\\boot\\initrd init=${config.system.build.toplevel}/init ${toString config.boot.kernelParams}" | iconv -f utf-8 -t UCS-2 > $out + ''; + + targetArch = if pkgs.stdenv.isi686 then + "IA32" + else if pkgs.stdenv.isx86_64 then + "x64" + else + throw "Unsupported architecture"; + in { @@ -220,6 +242,13 @@ in source = pkgs.runCommand "empty" {} "ensureDir $out"; target = "/nix/store"; } + ] ++ pkgs.stdenv.lib.optionals config.isoImage.makeEfiBootable [ + { source = bootParams; + target = "/efi/nixos/boot-params"; + } + { source = "${pkgs.NixosBootPkg}/*/NixosBoot.efi"; + target = "/efi/boot/boot${targetArch}.efi"; + } ]; # The Grub menu. @@ -239,14 +268,17 @@ in boot.loader.grub.timeout = 10; # Create the ISO image. - system.build.isoImage = import ../../../lib/make-iso9660-image.nix { + system.build.isoImage = import ../../../lib/make-iso9660-image.nix ({ inherit (pkgs) stdenv perl cdrkit pathsFromGraph; inherit (config.isoImage) isoName compressImage volumeID contents; bootable = true; bootImage = "/boot/grub/grub_eltorito"; - }; + } // pkgs.stdenv.lib.optionalAttrs config.isoImage.makeEfiBootable { + efiBootable = true; + efiBootImage = "efi/boot/boot${targetArch}.efi"; + }); boot.postBootCommands = '' diff --git a/modules/installer/efi-boot-stub/efi-boot-stub.nix b/modules/installer/efi-boot-stub/efi-boot-stub.nix index 55c4055ca1ec..7b28faa9ab21 100644 --- a/modules/installer/efi-boot-stub/efi-boot-stub.nix +++ b/modules/installer/efi-boot-stub/efi-boot-stub.nix @@ -88,7 +88,7 @@ let inherit (config.boot.loader.efiBootStub) efiSysMountPoint runEfibootmgr installStartupNsh efiDisk efiPartition installRemovableMediaImage; kernelFile = platform.kernelTarget; } // pkgs.stdenv.lib.optionalAttrs config.boot.loader.efiBootStub.installRemovableMediaImage { - removableMediaImage = "${pkgs.NixosBootPkg}/X64/NixosBoot.efi"; + removableMediaImage = "${pkgs.NixosBootPkg}/*/NixosBoot.efi"; targetArch = if pkgs.stdenv.isi686 then "IA32" else if pkgs.stdenv.isx86_64 then