grub2_pvgrub_image, grub: refactor, add PVH support (#374753)

Changed files
+105 -55
pkgs
by-name
gr
grub2_pvgrub_image
grub2_pvhgrub_image
tools
misc
top-level
pkgs/by-name/gr/grub2_pvgrub_image/configs/grub-bootstrap.cfg pkgs/by-name/gr/grub2_pvhgrub_image/configs/grub-bootstrap.cfg
pkgs/by-name/gr/grub2_pvgrub_image/configs/grub.cfg pkgs/by-name/gr/grub2_pvhgrub_image/configs/grub.cfg
-54
pkgs/by-name/gr/grub2_pvgrub_image/package.nix
···
-
{
-
lib,
-
stdenv,
-
grub2_xen,
-
}:
-
-
let
-
efiSystemsBuild = {
-
i686-linux.target = "i386";
-
x86_64-linux.target = "x86_64";
-
armv7l-linux.target = "arm";
-
aarch64-linux.target = "aarch64";
-
riscv32-linux.target = "riscv32";
-
riscv64-linux.target = "riscv64";
-
};
-
-
in
-
(
-
-
stdenv.mkDerivation rec {
-
name = "pvgrub-image";
-
-
configs = ./configs;
-
-
buildInputs = [ grub2_xen ];
-
-
buildCommand = ''
-
cp "${configs}"/* .
-
tar -cf memdisk.tar grub.cfg
-
# We include all modules except all_video.mod as otherwise grub will fail printing "no symbol table"
-
# if we include it.
-
grub-mkimage -O "${
-
efiSystemsBuild.${stdenv.hostPlatform.system}.target
-
}-xen" -c grub-bootstrap.cfg \
-
-m memdisk.tar -o "grub-${efiSystemsBuild.${stdenv.hostPlatform.system}.target}-xen.bin" \
-
$(ls "${grub2_xen}/lib/grub/${
-
efiSystemsBuild.${stdenv.hostPlatform.system}.target
-
}-xen/" |grep 'mod''$'|grep -v '^all_video\.mod''$')
-
mkdir -p "$out/lib/grub-xen"
-
cp "grub-${efiSystemsBuild.${stdenv.hostPlatform.system}.target}-xen.bin" $out/lib/grub-xen/
-
'';
-
-
meta = with lib; {
-
description = "PvGrub image for use for booting PV Xen guests";
-
-
longDescription = ''
-
This package provides a PvGrub image for booting Para-Virtualized (PV)
-
Xen guests
-
'';
-
-
platforms = platforms.gnu ++ platforms.linux;
-
};
-
}
-
)
+83
pkgs/by-name/gr/grub2_pvhgrub_image/package.nix
···
+
{
+
lib,
+
stdenv,
+
grub2_xen,
+
grub2_xen_pvh,
+
grubPlatform ? "xen_pvh",
+
}:
+
+
assert lib.assertOneOf "grubPlatform" grubPlatform [
+
"xen"
+
"xen_pvh"
+
];
+
let
+
targets = {
+
i686-linux.target = "i386";
+
x86_64-linux.target = if grubPlatform == "xen_pvh" then "i386" else "x86_64";
+
};
+
in
+
stdenv.mkDerivation {
+
name = "grub2_${grubPlatform}_image";
+
+
env = {
+
GRUB_CONFIGS = "${./configs}";
+
GRUB_FORMAT = "${targets.${stdenv.buildPlatform.system}.target}-${grubPlatform}";
+
};
+
+
buildInputs =
+
lib.optional (grubPlatform == "xen") grub2_xen
+
++ lib.optional (grubPlatform == "xen_pvh") grub2_xen_pvh;
+
+
dontUnpack = true;
+
+
buildPhase = ''
+
cp "$GRUB_CONFIGS"/* .
+
tar -cf memdisk.tar grub.cfg
+
grub-mkimage \
+
-O "$GRUB_FORMAT" \
+
-c grub-bootstrap.cfg \
+
-m memdisk.tar \
+
-o grub-"$GRUB_FORMAT".bin \
+
${if grubPlatform == "xen_pvh" then grub2_xen_pvh else grub2_xen}/lib/grub/"$GRUB_FORMAT"/*.mod
+
'';
+
+
installPhase = ''
+
mkdir -p "$out/lib/grub-${grubPlatform}"
+
cp grub-"$GRUB_FORMAT".bin $out/lib/grub-${grubPlatform}/
+
'';
+
+
dontFixup = true;
+
+
meta = {
+
description = "PvGrub2 image for booting ${
+
if grubPlatform == "xen_pvh" then "PVH" else "PV"
+
} Xen guests";
+
+
longDescription =
+
if (grubPlatform == "xen_pvh") then
+
''
+
This package provides a prebuilt PvGrub2 image for booting PVH Xen
+
guests (also commonly referred to as PvhGrub2), which searches for
+
`grub.cfg` on the guest disk and interprets it to load the kernel,
+
eliminating the need to copy the guest kernel to the Dom0.
+
+
You will need `pkgs.grub2_xen_pvh` to build a customized PvhGrub2
+
image. See [PvGrub2](https://wiki.xenproject.org/wiki/PvGrub2) for
+
more explanations.
+
''
+
else
+
''
+
This package provides a prebuilt PvGrub2 image for booting PV Xen
+
guests, which searches for `grub.cfg` on the guest disk and interprets
+
it to load the kernel, eliminating the need to copy the guest kernel
+
to the Dom0.
+
+
You will need `pkgs.grub2_xen` to build a customized PvGrub2 image.
+
See [PvGrub2](https://wiki.xenproject.org/wiki/PvGrub2) for more
+
explanations.
+
'';
+
+
teams = [ lib.teams.xen ];
+
platforms = lib.attrNames targets;
+
};
+
}
+14 -1
pkgs/tools/misc/grub/default.nix
···
efiSupport ? false,
zfsSupport ? false,
xenSupport ? false,
+
xenPvhSupport ? false,
kbdcompSupport ? false,
ckbcomp,
}:
···
x86_64-linux.target = "x86_64";
};
+
xenPvhSystemsBuild = {
+
i686-linux.target = "i386";
+
x86_64-linux.target = "i386"; # Xen PVH is only i386 on x86.
+
};
+
inPCSystems = lib.any (system: stdenv.hostPlatform.system == system) (lib.attrNames pcSystems);
gnulib = fetchgit {
···
in
assert zfsSupport -> zfs != null;
-
assert !(efiSupport && xenSupport);
+
assert !(efiSupport && (xenSupport || xenPvhSupport));
+
assert !(xenSupport && xenPvhSupport);
stdenv.mkDerivation rec {
pname = "grub";
···
++ lib.optionals xenSupport [
"--with-platform=xen"
"--target=${xenSystemsBuild.${stdenv.hostPlatform.system}.target}"
+
]
+
++ lib.optionals xenPvhSupport [
+
"--with-platform=xen_pvh"
+
"--target=${xenPvhSystemsBuild.${stdenv.hostPlatform.system}.target}"
];
# save target that grub is compiled for
···
lib.attrNames efiSystemsBuild
else if xenSupport then
lib.attrNames xenSystemsBuild
+
else if xenPvhSupport then
+
lib.attrNames xenPvhSystemsBuild
else
platforms.gnu ++ platforms.linux;
+8
pkgs/top-level/all-packages.nix
···
xenSupport = true;
};
+
grub2_xen_pvh = grub2.override {
+
xenPvhSupport = true;
+
};
+
+
grub2_pvgrub_image = grub2_pvhgrub_image.override {
+
grubPlatform = "xen";
+
};
+
grub4dos = callPackage ../tools/misc/grub4dos {
stdenv = stdenv_32bit;
};