11---
22title : " Enable LUKS2 and Argon2 Support for Packages"
33weight : 332
4- vars :
5- memregion_patch : " 4500-grub-2.06-runtime-memregion-alloc.patch"
6- argon2_patch_206 : " 5000-grub-2.06-luks2-argon2-v4.patch"
7- argon2_patch_212 : " grub-2.12-luks2-argon2-v4.patch"
8- aur_patch : " 9500-grub-AUR-improved-luks2.patch"
9- lastmod : 2023-12-24
104---
115
126Because the LUKS partition uses LUKS2 and Argon2id, support for these LUKS
@@ -36,131 +30,16 @@ USE flag must be disabled so `cryptsetup` can be built into the initramfs by
3630dracut, or else the LUKS partition could not be unlocked during boot.
3731{.notice--success}
3832
39- ## Add Patches for GRUB
40-
41- Neither GRUB 2.12 nor GRUB 2.06 supports the Argon2id PBKDF; GRUB 2.06 even has
42- more limitations on LUKS2 support. Therefore, both GRUB 2.12 and GRUB 2.06
43- need some patches for LUKS2 with Argon2id support.
44-
45- ### GRUB 2.12
46-
47- GRUB 2.12 only needs one patch [ ` {{< param vars.argon2_patch_212 >}} ` ] (
48- {{< patchesBaseURL.inline >}}
49- {{- partial "static-path.html" (dict
50- "page" (index .Page.Ancestors.Reverse 2) "type" "res") -}}
51- {{< /patchesBaseURL.inline >}}/{{< param vars.argon2_patch_212 >}}) to get
52- support for LUKS2 with Argon2. This patch was originally [ submitted to the
53- grub-devel mailing list] [ grub-devel-argon2-v4 ] and targeted GRUB 2.06; I ported
54- it to GRUB 2.12, and it still works.
55-
56- This patch has not been merged into GRUB, nor is it likely to be merged in the
57- future. The patch's author [ commented] [ grub-2.12-argon2 ] that, after the patch
58- had been created, one dependency of GRUB gained Argon2 support, so the best way
59- to add Argon2 support to GRUB became upgrading that dependency in GRUB's source
60- tree. What the patch does instead is adding the Argon2 reference
61- implementation to GRUB, which has become redundant after the said dependency's
62- new version would also add Argon2 support.
63-
64- To apply this patch to Gentoo's GRUB package -- ` sys-boot/grub ` , add it as a
65- [ Portage user patch] [ gentoo-wiki-etc-portage-patches ] to
66- ` /etc/portage/patches/sys-boot/grub-2.12 ` . Patches at this location are
67- applied to all Gentoo revisions of GRUB 2.12 (` -r1 ` , ` -r2 ` , etc.). The
68- following commands may be used to do this:
69-
70- {{< commands.inline "2.12" "argon2_patch_212" >}}
71- {{- $grubVer := .Get 0 }}
72- {{- $patches := split (.Get 1) " " }}
73- {{- $patches = apply $patches "printf" "vars.%s" "." }}
74- {{- $patches = apply $patches "page.Param" "." }}
75-
76- {{ $content := print
77- "# mkdir -p /etc/portage/patches/sys-boot/grub-" $grubVer | println }}
78- {{ $content := print $content
79- "# cd /etc/portage/patches/sys-boot/grub-" $grubVer | println }}
80- {{- $baseURL := partial "static-path.html" (dict
81- "page" (index .Page.Ancestors.Reverse 2) "type" "res" "abs" true) }}
82- {{- range $patches }}
83- {{- $content = print $content "# curl -O " $baseURL "/" . | println }}
84- {{- end }}
85- {{- highlight $content "console" }}
86- {{< /commands.inline >}}
87-
88- Readers who are interested in learning more about Portage's user patch feature
89- are welcome to read [ another article on this website] [ portage-user-patches ]
90- that discusses it in depth.
91- {.notice--success}
92-
93- Because this patch modifies the file ` grub-core/Makefile.core.def ` , according
94- to the [ ` sys-boot/grub ` ebuild] [ ebuild-sys-boot:grub ] , the ` GRUB_AUTOGEN ` and
95- ` GRUB_AUTORECONF ` environment variables must be set. ** Otherwise, any builds
96- of the package with the patch applied would fail.** The environment variable
97- can be set exclusively for all Gentoo revisions of ` sys-boot/grub-2.12 ` in file
98- ` /etc/portage/env/sys-boot/grub-2.12 ` :
99-
100- ``` console
101- # mkdir -p /etc/portage/env/sys-boot
102- # echo -e ' GRUB_AUTOGEN=1\nGRUB_AUTORECONF=1' >> /etc/portage/env/sys-boot/grub-2.12
103- ```
104-
105- [ grub-devel-argon2-v4 ] : https://lists.gnu.org/archive/html/grub-devel/2021-08/msg00027.html
106- [ grub-2.12-argon2 ] : https://lists.gnu.org/archive/html/grub-devel/2022-11/msg00094.html
107- [ gentoo-wiki-etc-portage-patches ] : https://wiki.gentoo.org/wiki//etc/portage/patches
108- [ portage-user-patches] : {{< relref "2021-03-01-portage-user-patches" >}}
109- [ ebuild-sys-boot:grub ] : https://gitweb.gentoo.org/repo/gentoo.git/tree/sys-boot/grub/grub-2.12.ebuild?id=76418694270557b6feb75381912a39569ee28d45#n6
110-
111- ### GRUB 2.06
112-
113- GRUB 2.06's support for LUKS2 is [ more limited] [ arch-wiki-grub-luks2 ] .
114- Although code implementing partial LUKS2 support exists in this version, the
115- bootloader files installed using the default procedure do not support LUKS2.
116-
117- Luckily, after applying the following patches to GRUB 2.06, LUKS2 support can
118- be added to the installed bootloader files automatically, and Argon2id is
119- supported too.
33+ ## GRUB 2.12 and Lower Only: Add Patches for GRUB
12034
121- - [ ` {{< param vars.memregion_patch >}} ` ] ({{< patchesBaseURL.inline />}}/{{<
122- param vars.memregion_patch >}}): A patch set that allows GRUB to allocate new
123- consecutive and large memory chunks, which is a prerequisite for Argon2
124- support in GRUB. Argon2 enhances the security of LUKS by increasing the size
125- of memory required for unlocking computations, so GRUB must be able to
126- allocate more memory when needed. This patch set was cherry-picked from
127- [ GRUB 2.12] [ grub-git-memregion-patch ] .
128-
129- - [ ` {{< param vars.argon2_patch_206 >}} ` ] ({{< patchesBaseURL.inline />}}/{{<
130- param vars.argon2_patch_206 >}}): The patch set that adds Argon2 support
131- itself to GRUB. This patch is equivalent to the only patch needed for GRUB
132- 2.12 mentioned above.
133-
134- - [ ` {{< param vars.aur_patch >}} ` ] ({{< patchesBaseURL.inline />}}/{{< param
135- vars.aur_patch >}}): A patch [ included] [ aur-git-grub-install-luks2-patch ] in
136- the [ ` grub-improved-luks2-git ` ] [ aur-grub-improved-luks2-git ] package on the
137- AUR, which is what the Arch Wiki's GRUB article recommends for users seeking
138- great LUKS2 support in GRUB. This patch allows GRUB 2.06's ` grub-install `
139- command to automatically install bootloader files with LUKS2 support.
140-
141- The numbers in front of the patches' file names are there only to control the
142- order in which they are applied (patches with a smaller ordinal are applied
143- first). As long as the order is maintained, these numbers' values are
144- arbitrary.
145- {.notice--info}
146-
147- Similar to the case of GRUB 2.12, add these patches as Portage user patches to
148- ` /etc/portage/patches/sys-boot/grub-2.06 ` :
149-
150- {{< commands.inline "2.06" "memregion_patch argon2_patch_206 aur_patch" />}}
151-
152- Then, add the required environment variables to
153- ` /etc/portage/env/sys-boot/grub-2.06 ` :
154-
155- ``` console
156- # mkdir -p /etc/portage/env/sys-boot
157- # echo -e ' GRUB_AUTOGEN=1\nGRUB_AUTORECONF=1' >> /etc/portage/env/sys-boot/grub-2.06
158- ```
35+ GRUB has gained built-in support for LUKS2 and Argon2id support since 2.14, so
36+ users of GRUB 2.14 do not need to manually patch its source code to manually
37+ add LUKS2 and Argon2id support. These users can skip this step and move on to
38+ the next one.
15939
160- [ arch-wiki-grub-luks2 ] : https://wiki.archlinux.org/title/GRUB#LUKS2
161- [ grub-git-memregion-patch ] : https://git.savannah.gnu.org/cgit/grub.git/log/?qt=range&q=8afa5ef45..1df293482
162- [ aur-grub-improved-luks2-git ] : https://aur.archlinux.org/packages/grub-improved-luks2-git
163- [ aur-git-grub-install-luks2-patch ] : https://aur.archlinux.org/cgit/aur.git/tree/grub-install_luks2.patch?h=grub-improved-luks2-git&id=27612416769e544d2c08d29932fff69129cb143a
40+ Users who need to use an older GRUB release for any reason, including 2.12 and
41+ 2.06, need to patch its source code to add LUKS2 and Argon2id support. See
42+ [ the appendix] ({{% relref "../../patch-grub" %}}) for instructions.
16443
16544## New Installation Only: Initialize Portage
16645
@@ -174,8 +53,8 @@ chapter:
17453
17554## Rebuild Packages
17655
177- First, build ` sys-boot/grub ` with the patches applied. Before starting the
178- build, please make sure that in the output of ` emerge ` ,
56+ First, build ` sys-boot/grub ` ( with any patches applied, if needed). Before
57+ starting the build, please make sure that in the output of ` emerge ` ,
17958` GRUB_PLATFORMS="efi-64" ` is enabled for ` sys-boot/grub ` . In other words,
18059please check that ` efi-64 ` is listed * without* a minus sign (` - ` ) in front of
18160it under ` GRUB_PLATFORMS ` . If this is not true, the Handbook has [ related
0 commit comments