Revert "nixos: iso-image: use syslinux bootloader for USB booting support"

This reverts commit 455db168b3.
This commit is contained in:
Luca Bruno 2014-11-08 13:09:08 +01:00
parent e3611709d6
commit 7885c2ed12
3 changed files with 77 additions and 108 deletions

View file

@ -1,4 +1,4 @@
{ stdenv, perl, pathsFromGraph, xorriso, syslinux { stdenv, perl, cdrkit, pathsFromGraph
, # The file name of the resulting ISO image. , # The file name of the resulting ISO image.
isoName ? "cd.iso" isoName ? "cd.iso"
@ -22,18 +22,12 @@
, # Whether this should be an efi-bootable El-Torito CD. , # Whether this should be an efi-bootable El-Torito CD.
efiBootable ? false efiBootable ? false
, # Wheter this should be an hybrid CD (bootable from USB as well as CD).
usbBootable ? false
, # The path (in the ISO file system) of the boot image. , # The path (in the ISO file system) of the boot image.
bootImage ? "" bootImage ? ""
, # The path (in the ISO file system) of the efi boot image. , # The path (in the ISO file system) of the efi boot image.
efiBootImage ? "" efiBootImage ? ""
, # The path (outside the ISO file system) of the isohybrid-mbr image.
isohybridMbrImage ? ""
, # Whether to compress the resulting ISO image with bzip2. , # Whether to compress the resulting ISO image with bzip2.
compressImage ? false compressImage ? false
@ -44,14 +38,13 @@
assert bootable -> bootImage != ""; assert bootable -> bootImage != "";
assert efiBootable -> efiBootImage != ""; assert efiBootable -> efiBootImage != "";
assert usbBootable -> isohybridMbrImage != "";
stdenv.mkDerivation { stdenv.mkDerivation {
name = "iso9660-image"; name = "iso9660-image";
builder = ./make-iso9660-image.sh; builder = ./make-iso9660-image.sh;
buildInputs = [perl xorriso syslinux]; buildInputs = [perl cdrkit];
inherit isoName bootable bootImage compressImage volumeID pathsFromGraph efiBootImage efiBootable isohybridMbrImage usbBootable; inherit isoName bootable bootImage compressImage volumeID pathsFromGraph efiBootImage efiBootable;
# !!! should use XML. # !!! should use XML.
sources = map (x: x.source) contents; sources = map (x: x.source) contents;

View file

@ -31,20 +31,11 @@ if test -n "$bootable"; then
fi fi
done done
isoBootFlags="-eltorito-boot ${bootImage} bootFlags="-b $bootImage -c .boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table"
-eltorito-catalog .boot.cat
-no-emul-boot -boot-load-size 4 -boot-info-table"
fi
if test -n "$usbBootable"; then
usbBootFlags="-isohybrid-mbr ${isohybridMbrImage}"
fi fi
if test -n "$efiBootable"; then if test -n "$efiBootable"; then
efiBootFlags="-eltorito-alt-boot bootFlags="$bootFlags -eltorito-alt-boot -e $efiBootImage -no-emul-boot"
-e $efiBootImage
-no-emul-boot
-isohybrid-gpt-basdat"
fi fi
touch pathlist touch pathlist
@ -83,41 +74,18 @@ for ((n = 0; n < ${#objects[*]}; n++)); do
fi fi
done done
# Escape filenames that contain '='. # !!! what does this do?
# TODO: Handle this properly. This fails for filenames
# that contain multiple '=' symbols.
cat pathlist | sed -e 's/=\(.*\)=\(.*\)=/\\=\1=\2\\=/' | tee pathlist.safer cat pathlist | sed -e 's/=\(.*\)=\(.*\)=/\\=\1=\2\\=/' | tee pathlist.safer
mkdir -p $out/iso mkdir -p $out/iso
genCommand="genisoimage -iso-level 4 -r -J $bootFlags -hide-rr-moved -graft-points -path-list pathlist.safer ${volumeID:+-V $volumeID}"
xorriso="xorriso if test -z "$compressImage"; then
-as mkisofs $genCommand -o $out/iso/$isoName
-iso-level 3 else
-volid ${volumeID} $genCommand | bzip2 > $out/iso/$isoName.bz2
-appid nixos
-publisher nixos
-graft-points
-full-iso9660-filenames
${isoBootFlags}
${usbBootFlags}
${efiBootFlags}
-r
-path-list pathlist.safer
--sort-weight 0 /
--sort-weight 1 /isolinux" # Make sure isolinux is near the beginning of the ISO
$xorriso -output $out/iso/$isoName
if test -n "$usbBootable"; then
echo "Making image hybrid..."
isohybrid --uefi $out/iso/$isoName
fi fi
if test -n "$compressImage"; then
echo "Compressing image..."
bzip2 $out/iso/$isoName
fi
mkdir -p $out/nix-support mkdir -p $out/nix-support
echo $system > $out/nix-support/system echo $system > $out/nix-support/system

View file

@ -8,37 +8,45 @@ with lib;
let let
# The configuration file for syslinux. # The Grub image.
isolinuxCfg = grubImage = pkgs.runCommand "grub_eltorito" {}
'' ''
SERIAL 0 38400 ${pkgs.grub2}/bin/grub-mkimage -p /boot/grub -O i386-pc -o tmp biosdisk iso9660 help linux linux16 chain png jpeg echo gfxmenu reboot
UI vesamenu.c32 cat ${pkgs.grub2}/lib/grub/*/cdboot.img tmp > $out
MENU TITLE NixOS ''; # */
MENU BACKGROUND /isolinux/background.png
LABEL boot
MENU LABEL Boot NixOS
LINUX /boot/bzImage init=${config.system.build.toplevel}/init ${toString config.boot.kernelParams}
INITRD /boot/initrd
LABEL chain # The configuration file for Grub.
MENU LABEL Boot existing OS grubCfg =
COM32 chain.c32 ''
APPEND hd0 0 set default=${builtins.toString config.boot.loader.grub.default}
set timeout=${builtins.toString config.boot.loader.grub.timeout}
LABEL reboot if loadfont /boot/grub/unicode.pf2; then
MENU LABEL Reboot set gfxmode=640x480
COM32 reboot.c32 insmod gfxterm
insmod vbe
terminal_output gfxterm
LABEL poweroff insmod png
MENU LABEL Power Off if background_image /boot/grub/splash.png; then
COM32 poweroff.c32 set color_normal=white/black
set color_highlight=black/white
else
set menu_color_normal=cyan/blue
set menu_color_highlight=white/blue
fi
fi
${config.boot.loader.grub.extraEntries}
''; '';
# The efi boot image # The efi boot image
efiDir = pkgs.runCommand "efi-directory" {} '' efiDir = pkgs.runCommand "efi-directory" {} ''
mkdir -p $out/EFI/boot mkdir -p $out/efi/boot
cp -v ${pkgs.gummiboot}/lib/gummiboot/gummiboot${targetArch}.efi $out/EFI/boot/boot${targetArch}.efi cp -v ${pkgs.gummiboot}/lib/gummiboot/gummiboot${targetArch}.efi $out/efi/boot/boot${targetArch}.efi
mkdir -p $out/loader/entries mkdir -p $out/loader/entries
echo "title NixOS LiveCD" > $out/loader/entries/nixos-livecd.conf echo "title NixOS LiveCD" > $out/loader/entries/nixos-livecd.conf
echo "linux /boot/bzImage" >> $out/loader/entries/nixos-livecd.conf echo "linux /boot/bzImage" >> $out/loader/entries/nixos-livecd.conf
@ -144,22 +152,6 @@ in
''; '';
}; };
isoImage.makeUsbBootable = mkOption {
default = false;
description = ''
Whether the ISO image should be bootable from CD as well as USB.
'';
};
isoImage.splashImage = mkOption {
default = pkgs.fetchurl {
url = https://raw.githubusercontent.com/NixOS/nixos-artwork/5729ab16c6a5793c10a2913b5a1b3f59b91c36ee/ideas/grub-splash/grub-nixos-1.png;
sha256 = "43fd8ad5decf6c23c87e9026170a13588c2eba249d9013cb9f888da5e2002217";
};
description = ''
The splash image to use in the bootloader.
'';
};
}; };
@ -174,7 +166,7 @@ in
# !!! Hack - attributes expected by other modules. # !!! Hack - attributes expected by other modules.
system.boot.loader.kernelFile = "bzImage"; system.boot.loader.kernelFile = "bzImage";
environment.systemPackages = [ pkgs.grub2 pkgs.syslinux ]; environment.systemPackages = [ pkgs.grub2 ];
# In stage 1 of the boot, mount the CD as the root FS by label so # In stage 1 of the boot, mount the CD as the root FS by label so
# that we don't need to know its device. We pass the label of the # that we don't need to know its device. We pass the label of the
@ -221,7 +213,7 @@ in
options = "allow_other,cow,nonempty,chroot=/mnt-root,max_files=32768,hide_meta_files,dirs=/nix/.rw-store=rw:/nix/.ro-store=ro"; options = "allow_other,cow,nonempty,chroot=/mnt-root,max_files=32768,hide_meta_files,dirs=/nix/.rw-store=rw:/nix/.ro-store=ro";
}; };
boot.initrd.availableKernelModules = [ "squashfs" "iso9660" "usb-storage" ]; boot.initrd.availableKernelModules = [ "squashfs" "iso9660" ];
boot.initrd.kernelModules = [ "loop" ]; boot.initrd.kernelModules = [ "loop" ];
@ -241,12 +233,15 @@ in
# Individual files to be included on the CD, outside of the Nix # Individual files to be included on the CD, outside of the Nix
# store on the CD. # store on the CD.
isoImage.contents = isoImage.contents =
[ { source = pkgs.substituteAll { [ { source = grubImage;
name = "isolinux.cfg"; target = "/boot/grub/grub_eltorito";
src = pkgs.writeText "isolinux.cfg-in" isolinuxCfg; }
{ source = pkgs.substituteAll {
name = "grub.cfg";
src = pkgs.writeText "grub.cfg-in" grubCfg;
bootRoot = "/boot"; bootRoot = "/boot";
}; };
target = "/isolinux/isolinux.cfg"; target = "/boot/grub/grub.cfg";
} }
{ source = config.boot.kernelPackages.kernel + "/bzImage"; { source = config.boot.kernelPackages.kernel + "/bzImage";
target = "/boot/bzImage"; target = "/boot/bzImage";
@ -254,38 +249,51 @@ in
{ source = config.system.build.initialRamdisk + "/initrd"; { source = config.system.build.initialRamdisk + "/initrd";
target = "/boot/initrd"; target = "/boot/initrd";
} }
{ source = "${pkgs.grub2}/share/grub/unicode.pf2";
target = "/boot/grub/unicode.pf2";
}
{ source = config.boot.loader.grub.splashImage;
target = "/boot/grub/splash.png";
}
{ source = config.system.build.squashfsStore; { source = config.system.build.squashfsStore;
target = "/nix-store.squashfs"; target = "/nix-store.squashfs";
} }
{ source = "${pkgs.syslinux}/share/syslinux";
target = "/isolinux";
}
{ source = config.isoImage.splashImage;
target = "/isolinux/background.png";
}
] ++ optionals config.isoImage.makeEfiBootable [ ] ++ optionals config.isoImage.makeEfiBootable [
{ source = efiImg; { source = efiImg;
target = "/boot/efi.img"; target = "/boot/efi.img";
} }
{ source = "${efiDir}/EFI"; { source = "${efiDir}/efi";
target = "/EFI"; target = "/efi";
} }
{ source = "${efiDir}/loader"; { source = "${efiDir}/loader";
target = "/loader"; target = "/loader";
} }
]; ] ++ mapAttrsToList (n: v: { source = v; target = "/boot/${n}"; }) config.boot.loader.grub.extraFiles;
# The Grub menu.
boot.loader.grub.extraEntries =
''
menuentry "NixOS ${config.system.nixosVersion} Installer" {
linux /boot/bzImage init=${config.system.build.toplevel}/init ${toString config.boot.kernelParams}
initrd /boot/initrd
}
menuentry "Boot from hard disk" {
set root=(hd0)
chainloader +1
}
'';
boot.loader.grub.timeout = 10;
# Create the ISO image. # 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 pathsFromGraph xorriso syslinux; inherit (pkgs) stdenv perl cdrkit pathsFromGraph;
inherit (config.isoImage) isoName compressImage volumeID contents; inherit (config.isoImage) isoName compressImage volumeID contents;
bootable = true; bootable = true;
bootImage = "/isolinux/isolinux.bin"; bootImage = "/boot/grub/grub_eltorito";
} // optionalAttrs config.isoImage.makeUsbBootable {
usbBootable = true;
isohybridMbrImage = "${pkgs.syslinux}/share/syslinux/isohdpfx.bin";
} // optionalAttrs config.isoImage.makeEfiBootable { } // optionalAttrs config.isoImage.makeEfiBootable {
efiBootable = true; efiBootable = true;
efiBootImage = "boot/efi.img"; efiBootImage = "boot/efi.img";