Embedded system security - stepping on pits when compiling the linux kernel

How To Build Linux Kernel {Step-By-Step} | phoenixNAP KB

(Two virtual machine versions were used successively, and the installed kernel version was changed from 5.15.8 to 5.13.1, which finally achieved the purpose of the experiment)

The final implementation version is Ubuntu18.04.4 5.3.0-28-generic

Tip: The memory of the virtual machine must be large enough, otherwise there will be insufficient space when compiling the kernel

closing dependency file drivers/watchdog/.smsc37b787_wdt.od: No space on device

View disk information

sudo fdisk -l

Expand memory disk partition tool

 After expanding 30G, it can be found that the 30G is not partitioned (that is, it cannot be used)

 Partition succeeded

Dependency packages can be installed in advance

sudo apt-get install libncurses5-dev openssl libssl-dev
sudo apt-get install build-essential openssl
sudo apt-get install pkg-config
sudo apt-get install libc6-dev
sudo apt-get install bison
sudo apt-get install flex
sudo apt-get install libelf-dev
sudo apt-get install zlibc minizip
sudo apt-get install libidn11-dev libidn11

1. Check the linux kernel version

2. Download the linux kernel source code (http://www.kernel.org/)

 Simply put, both files are compressed tar files, but the compression algorithm is different. tar.gz uses the gzip compression tool, and tar.xz uses the xz tool. But for users, there is no difference between the decompression of the two.

2. Copy the source code to /usr/src and unzip it

Can also be moved manually

sudo nautilus (file manager with permissions)

3. Enter the directory file and execute make menuconfig to generate the kernel image

Insufficient permissions to run as administrator

It prompts that ncurses-devel, libncurses-dev, etc. need to be installed

Direct installation reports an error, and replaces libncurse5-dev with success

 After the installation is complete, an error is reported that there is no flex and bison

Install flex (sudo apt-get install flex)

Anso bison (sudo apt-get install bison -y)

 

 Then found that the version is not compatible

Therefore, to upgrade the gcc version of the system to 5.1.0 or above, the steps are as follows

sudo add-apt-repository ppa:ubuntu-toolchain-r/test

sudo apt-get update

sudo apt-get install gcc-5 g++-5

sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-5 60 --slave /usr/bin/g++ g++ /usr/bin/g++-5 (set the current default GCC version to gcc-5)

Re-execute sudo make config successfully (make is used to compile, it reads instructions from Makefile, and then compiles.)

Click on the load option

click ok 

show file does not exist

Clean up intermediate residual files from previously compiled kernels

 Create corresponding files

 

Compile the module and report an error without openssl 

Install openssl and other dependencies

Re-execute make modules without error (it takes a long time)

Using -j when make can effectively improve the speed

The virtual machine is stuck due to insufficient memory (change to a virtual machine with a higher version to allocate more memory) 

make install is used for installation, it also reads instructions from the Makefile and installs them to the specified location

report error

No rule to make target 'debian/certs/[email protected]', needed by 'certs/x509_certificate_list'. Stop.

Remove the value of CONFIG_SYSTEM_TRUSTED_KEYS

sudo make INSTALL_MOD_STRIP=1 modules_install

sudo make install

sudo update-initramfs -c -k 5.13.1

sudo update-grub

Verify kernel version after reboot

success!

Reference

Version 5.13.1

Guess you like

Origin blog.csdn.net/m0_67105022/article/details/123809754