-
Notifications
You must be signed in to change notification settings - Fork 35
build cenos 7 aarch64 2009 4k
ppggff edited this page Sep 19, 2022
·
4 revisions
- Build a kernel with 4K page size to be compatible with apple m1 (CentOS 7 also need a small patch, it's based on kernel commits "Revert "arm64: Remove unnecessary ISBs from set_{pte, pmd, pud}")
- Install this "new" kernel to the official cloud image
- Turn the altered image to a vagrant box
Sorry I didn't remember so many details, there are some notes, hope it will help you.
- Build kernel:
-
I build it on a x86 machine, with qemu-static + binfmt-misc (do you want more info about this?) this could be simplified by doing it on a arm vm, or apple m1 vm without 'accel=hvf'
-
Compile the kernel
- follows:
- config
- "Kernel Features" -> "Page size (64KB)" -> "4KB"
-
Build the vagrant box
- https://www.vagrantup.com/docs/boxes/base
- use the 'create_box.sh' from vagrant-libvirt
- you could hack packer to simplify this step, I tried:
- post-processor "shell-local" to prepare
metadata.json
andbox.img
- use post-processor "vagrant" and 'provider_override = "lxc"' to build the box
- post-processor "shell-local" to prepare
At last is the recored script about compile the kernel, it may not complete, use it as a hint.
# prepare
yum groupinstall "Development Tools"
yum install ncurses-devel
yum install hmaccalc zlib-devel binutils-devel elfutils-libelf-devel
yum install asciidoc audit-libs-devel bash bc binutils binutils-devel bison diffutils elfutils
yum install elfutils-devel elfutils-libelf-devel findutils flex gawk gcc gettext gzip hmaccalc hostname java-devel
yum install m4 make module-init-tools ncurses-devel net-tools newt-devel numactl-devel openssl
yum install patch pciutils-devel perl perl-ExtUtils-Embed pesign python-devel python-docutils redhat-rpm-config
yum install rpm-build sh-utils tar xmlto xz zlib-devel
yum install libcap-devel python3-devel devtoolset-8-build devtoolset-8-binutils devtoolset-8-gcc devtoolset-8-make python3-rpm-macros dwarves libbpf-devel libbabeltrace-devel libcap-ng-devel llvm-toolset-7.0 openssl-devel
yum install centos-release-scl
yum install devtoolset-8
yum install llvm-toolset-7.0
yum install wget
yum install libarchive
yum install popt-devel
yum install vim
yum install linux-firmware
# prepare
su - test
scl enable devtoolset-8 bash
scl enable llvm-toolset-7.0 bash
export PATH=$PATH:/sbin/
curl -O https://ftp.gnu.org/gnu/bash/bash-5.0.tar.gz
./configure
make
make install # with root
wget https://cbs.centos.org/kojifiles/packages/rpm/4.13.0.2/1.el7.c8/aarch64/python2-rpm-4.13.0.2-1.el7.c8.aarch64.rpm
wget https://cbs.centos.org/kojifiles/packages/rpm/4.13.0.2/1.el7.c8/aarch64/rpm-build-4.13.0.2-1.el7.c8.aarch64.rpm
wget https://cbs.centos.org/kojifiles/packages/rpm/4.13.0.2/1.el7.c8/aarch64/rpm-devel-4.13.0.2-1.el7.c8.aarch64.rpm
wget https://cbs.centos.org/kojifiles/packages/rpm/4.13.0.2/1.el7.c8/aarch64/rpm-build-libs-4.13.0.2-1.el7.c8.aarch64.rpm
wget https://cbs.centos.org/kojifiles/packages/rpm/4.13.0.2/1.el7.c8/aarch64/rpm-libs-4.13.0.2-1.el7.c8.aarch64.rpm
wget https://cbs.centos.org/kojifiles/packages/rpm/4.13.0.2/1.el7.c8/aarch64/rpm-plugin-ima-4.13.0.2-1.el7.c8.aarch64.rpm
wget https://cbs.centos.org/kojifiles/packages/rpm/4.13.0.2/1.el7.c8/aarch64/rpm-plugin-selinux-4.13.0.2-1.el7.c8.aarch64.rpm
wget https://cbs.centos.org/kojifiles/packages/rpm/4.13.0.2/1.el7.c8/aarch64/rpm-plugin-syslog-4.13.0.2-1.el7.c8.aarch64.rpm
wget https://cbs.centos.org/kojifiles/packages/rpm/4.13.0.2/1.el7.c8/aarch64/rpm-plugin-systemd-inhibit-4.13.0.2-1.el7.c8.aarch64.rpm
wget https://cbs.centos.org/kojifiles/packages/rpm/4.13.0.2/1.el7.c8/aarch64/rpm-sign-4.13.0.2-1.el7.c8.aarch64.rpm
wget https://cbs.centos.org/kojifiles/packages/rpm/4.13.0.2/1.el7.c8/aarch64/rpm-debuginfo-4.13.0.2-1.el7.c8.aarch64.rpm
rpm -Uvh *.rpm # with root
# prepare source code
mkdir -p ~/rpmbuild/{BUILD,BUILDROOT,RPMS,SOURCES,SPECS,SRPMS}
echo '%_topdir %(echo $HOME)/rpmbuild' > ~/.rpmmacros
rpm -i kernel-4.18.0-305.10.2.el7.src.rpm 2>&1 | grep -v 'exist'
cd ~/rpmbuild/SPECS
rpmbuild -bp --target=$(uname -m) kernel.spec
# configure the kernel
cd ~/rpmbuild/BUILD/kernel-*/linux-*/
cp configs/kernel-4.18.0-aarch64.config .config
make oldconfig
make menuconfig # "Kernel Features" -> "Page size (64KB)" -> "4KB"
# add to the top of `.config`: # arm64
cp .config configs/kernel-4.18.0-aarch64.config
cp configs/* ~/rpmbuild/SOURCES/
# complie
cd ~/rpmbuild/SPECS/
cp kernel.spec kernel.spec.distro
vi kernel.spec
# fix a minor problem in the spec file
42c42
< # define buildid .local
---
> %define buildid .gzq4K
1216,1218c1216,1218
< cp $RPM_SOURCE_DIR/kernel-*.config .
< cp %{SOURCE41} .
< VERSION=%{version} NAME=%{name} ./generate_all_configs.sh
---
> cp $RPM_SOURCE_DIR/kernel-%{version}-*.config .
> #cp %{SOURCE41} .
> #VERSION=%{version} NAME=%{name} ./generate_all_configs.sh
rpmbuild --with baseonly --without debug --without debuginfo --without kabichk -bb --target=`uname -m` kernel.spec 2> build-err.log | tee build-out.log
# install the kernel
cd /home/test/rpmbuild/RPMS/aarch64/
yum localinstall kernel-*.rpm # with root
# check
grub2-editenv list
CentOS 7 also need a small patch, it's based on kernel commits "Revert "arm64: Remove unnecessary ISBs from set_{pte, pmd, pud}"
--- a/arch/arm64/include/asm/pgtable.h
+++ b/arch/arm64/include/asm/pgtable.h
@@ -229,8 +229,10 @@
* Only if the new pte is valid and kernel, otherwise TLB maintenance
* or update_mmu_cache() have the necessary barriers.
*/
- if (pte_valid_not_user(pte))
+ if (pte_valid_not_user(pte)) {
dsb(ishst);
+ isb();
+ }
}
extern void __sync_icache_dcache(pte_t pteval);
@@ -470,6 +472,7 @@
WRITE_ONCE(*pmdp, pmd);
dsb(ishst);
+ isb();
}
static inline void pmd_clear(pmd_t *pmdp)
@@ -526,6 +529,7 @@
WRITE_ONCE(*pudp, pud);
dsb(ishst);
+ isb();
}
static inline void pud_clear(pud_t *pudp)