获取源码包 src.rpm包
## 附也可以用 公版的 grub-2.02~beta2.tar.xz (实测也能成功)
http://alpha.gnu.org/gnu/grub/
# https://github.com/rhboot/grub2 # 这个没尝试过过
## 附、grub2 相关软件包的命令作用
http://doc.yonyoucloud.com/doc/LFS-BOOK-7.7-systemd/chapter06/grub.html
## 将下列补丁包上传到目录 /root/rpmbuild/SOURCES/
0001-Cryptomount-support-LUKS-detached-header.patch
0002-Cryptomount-support-key-files.patch
0003-Cryptomount-luks-allow-multiple-passphrase-attempts.patch
0004-Cryptomount-support-plain-dm-crypt.patch
0005-Cryptomount-support-for-hyphens-in-UUID.patch
0006-Retain-constness-of-parameters.patch
0007-Add-support-for-using-a-whole-device-as-a-keyfile.patch
## 编辑编译时引用的补丁列表文件,增加如下内容(实测 0003 及以后的无法编译成功,就注释了)
vi /root/rpmbuild/SOURCES/grub.patches
Patch0500: 0001-Cryptomount-support-LUKS-detached-header.patch
Patch0501: 0002-Cryptomount-support-key-files.patch
#Patch0502: 0003-Cryptomount-luks-allow-multiple-passphrase-attempts.patch
#Patch0503: 0004-Cryptomount-support-plain-dm-crypt.patch
#Patch0504: 0005-Cryptomount-support-for-hyphens-in-UUID.patch
#Patch0505: 0006-Retain-constness-of-parameters.patch
#Patch0506: 0007-Add-support-for-using-a-whole-device-as-a-keyfile.patch
# 执行编译
rpmbuild -ba rpmbuild/SPECS/grub2.spec
# 如何查看a目录下 所有文件是否包含 aaa这个字符
grep -rl "aaa" a/
grep -rl "Attempting to decrypt master key..." ./
## 修改文件
vi ./grub-core/disk/geli.c
vi ./grub-core/disk/luks.c
## 打包成品
cd /root/rpmbuild/
tar zcvf my-grub2.tar.gz RPMS
## gcc升级到9版本(貌似不需要)
## 解包(会自动在/root/ 目录下生成rpmbuild 相关目录 )
rpm -ivh grub2-2.02-0.87.0.2.el7.centos.14.src.rpm
## 补丁
https://grub.johnlane.ie/
## 加载补丁
# 下载补丁
wget -O /root/rpmbuild/SOURCES/0002-Cryptomount-support-key-files.patch https://grub.johnlane.ie/assets/0002-Cryptomount-support-key-files.patch
# 上传补丁并核查到 目录 /root/rpmbuild/SOURCES
ls /root/rpmbuild/SOURCES/ | grep 0002-Cryptomount-support-key-files.patch
# 把补丁放在 /root/rpmbuild/SOURCES/ 目录下,名称格式 0499-safemath-add-grub_cast-for-gcc-5.1.patch
# 在下面最末行按照格式添加
# vi /root/rpmbuild/SOURCES/grub.patches
# 快捷方式
echo "Patch0500: 0002-Cryptomount-support-key-files.patch" >> /root/rpmbuild/SOURCES/grub.patches
# 把补丁应用到源码(Tips: -p1 是只应用补丁的路径层级,有-p0 表示不去除 路径层级、-p1 去掉路径的第 1 层目录、-p2 去掉路径的前 2 层目录)
# 如何查看补丁的层级 head -n 20 0002-Cryptomount-support-key-files.patch 有如下输出类型的 用 -p1
# diff --git a/grub-core/disk/cryptodisk.c b/grub-core/disk/cryptodisk.c #这个 a/xxx b/xxx 格式的
cd /root/rpmbuild/BUILD/grub-2.02~beta2/grub-2.02~beta2
# 把补丁上传到 /root/rpmbuild/SOURCES/
# 然后将 grub的源码压缩包 复制一份 然后解压
cp /root/rpmbuild/SOURCES/grub-2.02~beta2.tar.xz /mnt/
cd /mnt
tar xf grub-2.02~beta2.tar.xz
cd /mnt/grub-2.02~beta2
# 导入补丁
patch -p1 < /root/rpmbuild/SOURCES/0001-Cryptomount-support-LUKS-detached-header.patch
patch -p1 < /root/rpmbuild/SOURCES/0002-Cryptomount-support-key-files.patch
# 把带有额外补丁的源码,重新压缩为xz格式,并复制到原本的路径
cd /mnt
tar -cJf grub-2.02~beta2.tar.xz grub-2.02~beta2
\cp -af grub-2.02~beta2.tar.xz /root/rpmbuild/SOURCES/
# 执行编译
rpmbuild -ba rpmbuild/SPECS/grub2.spec
会得到
Wrote: /root/rpmbuild/SRPMS/grub2-2.02-0.87.0.2.el7.14.src.rpm
Wrote: /root/rpmbuild/RPMS/x86_64/grub2-2.02-0.87.0.2.el7.14.x86_64.rpm
Wrote: /root/rpmbuild/RPMS/noarch/grub2-common-2.02-0.87.0.2.el7.14.noarch.rpm
Wrote: /root/rpmbuild/RPMS/x86_64/grub2-tools-2.02-0.87.0.2.el7.14.x86_64.rpm
Wrote: /root/rpmbuild/RPMS/x86_64/grub2-tools-minimal-2.02-0.87.0.2.el7.14.x86_64.rpm
Wrote: /root/rpmbuild/RPMS/x86_64/grub2-tools-extra-2.02-0.87.0.2.el7.14.x86_64.rpm
Wrote: /root/rpmbuild/RPMS/x86_64/grub2-efi-x64-2.02-0.87.0.2.el7.14.x86_64.rpm
Wrote: /root/rpmbuild/RPMS/noarch/grub2-efi-x64-modules-2.02-0.87.0.2.el7.14.noarch.rpm
Wrote: /root/rpmbuild/RPMS/x86_64/grub2-efi-x64-cdboot-2.02-0.87.0.2.el7.14.x86_64.rpm
Wrote: /root/rpmbuild/RPMS/x86_64/grub2-efi-ia32-2.02-0.87.0.2.el7.14.x86_64.rpm
Wrote: /root/rpmbuild/RPMS/noarch/grub2-efi-ia32-modules-2.02-0.87.0.2.el7.14.noarch.rpm
Wrote: /root/rpmbuild/RPMS/x86_64/grub2-efi-ia32-cdboot-2.02-0.87.0.2.el7.14.x86_64.rpm
Wrote: /root/rpmbuild/RPMS/x86_64/grub2-pc-2.02-0.87.0.2.el7.14.x86_64.rpm
Wrote: /root/rpmbuild/RPMS/noarch/grub2-pc-modules-2.02-0.87.0.2.el7.14.noarch.rpm
Wrote: /root/rpmbuild/RPMS/x86_64/grub2-debuginfo-2.02-0.87.0.2.el7.14.x86_64.rpm
+++++++++++++++下载后改名,改前面的序号
0001-Cryptomount-support-LUKS-detached-header.patch
0002-Cryptomount-support-key-files.patch
0003-Cryptomount-luks-allow-multiple-passphrase-attempts.patch
0004-Cryptomount-support-plain-dm-crypt.patch
0005-Cryptomount-support-for-hyphens-in-UUID.patch
0006-Retain-constness-of-parameters.patch
0007-Add-support-for-using-a-whole-device-as-a-keyfile.patch
+++++++++++++++
0500-Cryptomount-support-LUKS-detached-header.patch
0501-Cryptomount-support-key-files.patch
0502-Cryptomount-luks-allow-multiple-passphrase-attempts.patch
0503-Cryptomount-support-plain-dm-crypt.patch
0504-Cryptomount-support-for-hyphens-in-UUID.patch
0505-Retain-constness-of-parameters.patch
0506-Add-support-for-using-a-whole-device-as-a-keyfile.patch
=======
Patch0500: 0500-Cryptomount-support-LUKS-detached-header.patch
Patch0501: 0501-Cryptomount-support-key-files.patch
Patch0502: 0502-Cryptomount-luks-allow-multiple-passphrase-attempts.patch
Patch0503: 0503-Cryptomount-support-plain-dm-crypt.patch
Patch0504: 0504-Cryptomount-support-for-hyphens-in-UUID.patch
Patch0505: 0505-Retain-constness-of-parameters.patch
Patch0506: 0506-Add-support-for-using-a-whole-device-as-a-keyfile.patch
+++++++++导入是有顺序的
patch -p1 < /root/rpmbuild/SOURCES/0001-Cryptomount-support-LUKS-detached-header.patch
patch -p1 < /root/rpmbuild/SOURCES/0002-Cryptomount-support-key-files.patch
patch -p1 < /root/rpmbuild/SOURCES/0003-Cryptomount-luks-allow-multiple-passphrase-attempts.patch
#导入这行会报错,继续导入到时不会报,建议以下都不导入
patch -p1 < /root/rpmbuild/SOURCES/0004-Cryptomount-support-plain-dm-crypt.patch
# 继续导入下面的,不会报错
patch -p1 < /root/rpmbuild/SOURCES/0005-Cryptomount-support-for-hyphens-in-UUID.patch
patch -p1 < /root/rpmbuild/SOURCES/0006-Retain-constness-of-parameters.patch
patch -p1 < /root/rpmbuild/SOURCES/0007-Add-support-for-using-a-whole-device-as-a-keyfile.patch
=======验证cryptomount 是否支持 -k
++++
git am --resolved
git am --skip
git am --abort
bios方式安装(8个包)
rpm -ivh --force noarch/grub2-common-2.02-0.87.0.2.el7.14.noarch.rpm
rpm -ivh --force noarch/grub2-pc-modules-2.02-0.87.0.2.el7.14.noarch.rpm
rpm -ivh --force x86_64/grub2-2.02-0.87.0.2.el7.14.x86_64.rpm
rpm -ivh --force x86_64/grub2-debuginfo-2.02-0.87.0.2.el7.14.x86_64.rpm
rpm -ivh --force x86_64/grub2-pc-2.02-0.87.0.2.el7.14.x86_64.rpm
rpm -ivh --force x86_64/grub2-tools-2.02-0.87.0.2.el7.14.x86_64.rpm
rpm -ivh --force x86_64/grub2-tools-extra-2.02-0.87.0.2.el7.14.x86_64.rpm
rpm -ivh --force x86_64/grub2-tools-minimal-2.02-0.87.0.2.el7.14.x86_64.rpm
grub2-install /dev/sda # 执行完这一步后,重启时 cyrptomount 才支持 -k 参数
grub2-mkconfig -o /boot/grub2/grub.cfg
# grub2-mkconfig -o /boot/efi/EFI/centos/grub.cfg
uefi方式安装(9个包)
rpm -ivh --force noarch/grub2-common-2.02-0.87.0.2.el7.14.noarch.rpm
rpm -ivh --force noarch/grub2-pc-modules-2.02-0.87.0.2.el7.14.noarch.rpm
rpm -ivh --force noarch/grub2-efi-x64-modules-2.02-0.87.0.2.el7.14.noarch.rpm
rpm -ivh --force x86_64/grub2-2.02-0.87.0.2.el7.14.x86_64.rpm
rpm -ivh --force x86_64/grub2-pc-2.02-0.87.0.2.el7.14.x86_64.rpm
rpm -ivh --force x86_64/grub2-tools-extra-2.02-0.87.0.2.el7.14.x86_64.rpm
rpm -ivh --force x86_64/grub2-tools-minimal-2.02-0.87.0.2.el7.14.x86_64.rpm
rpm -ivh --force x86_64/grub2-efi-x64-2.02-0.87.0.2.el7.14.x86_64.rpm
rpm -ivh --force x86_64/grub2-tools-2.02-0.87.0.2.el7.14.x86_64.rpm
# 注意uefi模式下,引导不是安装到磁盘设备的
grub2-mkconfig -o /boot/efi/EFI/centos/grub.cfg
grub2-install --target=x86_64-efi --efi-directory=/boot/efi
# 正确方法
rpm -ivh --force grub2-*
cp noarch/grub2-common-2.02-0.87.0.2.el7.14.noarch.rpm bios/
cp noarch/grub2-pc-modules-2.02-0.87.0.2.el7.14.noarch.rpm bios/
cp x86_64/grub2-2.02-0.87.0.2.el7.14.x86_64.rpm bios/
cp x86_64/grub2-debuginfo-2.02-0.87.0.2.el7.14.x86_64.rpm bios/
cp x86_64/grub2-pc-2.02-0.87.0.2.el7.14.x86_64.rpm bios/
cp x86_64/grub2-tools-2.02-0.87.0.2.el7.14.x86_64.rpm bios/
cp x86_64/grub2-tools-extra-2.02-0.87.0.2.el7.14.x86_64.rpm bios/
cp x86_64/grub2-tools-minimal-2.02-0.87.0.2.el7.14.x86_64.rpm bios/
如果文章对你有帮助,欢迎点击上方按钮打赏作者
暂无评论