Home System Tutorial LINUX Huawei Cloud completes the compilation and installation of the Linux kernel (optional topic)

Huawei Cloud completes the compilation and installation of the Linux kernel (optional topic)

Feb 15, 2024 pm 12:12 PM
Huawei Cloud Linux operating system system version linux kernel

The experiment requires mastering the compilation and installation of the Linux kernel, mastering the basic concept design of Linux system calls and adding Linux system calls

(1) Change or return the priority (nice value and prio value) of the specified process (see textbook P328 for details) Tip: Possible reference kernel function: set_user_nice().

(2) Change the host name to a custom string (optional question)

1. Compilation and installation of the Linux kernel (use Huawei Cloud to complete the compilation and installation of the openEuler kernel)

(1) Log in to the system and check the current kernel version

[root@openEuler~]#uname-r

(2) Install tools and establish a development environment

[root@openEuler~]#yumgroupinstall-y"DevelopmentTools"

[root@openEuler~]#yuminstall-ybc

[root@openEuler~]#yuminstall-yopenssl-devel

(3) Back up the boot directory in case subsequent steps to update the kernel fail

[root@openEuler~]#tarczvfboot.origin.tgz/boot/

Save current kernel version information

[root@openEuler~]#uname–r>uname_r.log

(4) Obtain the kernel source code and decompress it

[root@openEuler~]#wget

[root@openEuler~]#unzipkernel-4.19.zip

(5)Compile kernel

[root@openEuler~]#cdkernel-kernel-4.19

[root@openEulerkernel]#makeopeneuler_defconfig

[root@openEulerkernel]#make-j4Imagemodulesdtbs

This step is to compile the image, modules and dtbs of the kernel. make-j4 means 4 thread compilation (can be adjusted according to the number of CPU cores)

(6)Install the kernel

[root@openEulerkernel]#makemodules_install

[root@openEulerkernel]#makeinstall

Note: The errors that occur during the last step "makeinstall" can be ignored here.

(7) Log in to ECS using VNC

(8) Restart the system

[root@openEulerkernel]#reboot

(9) Log in and verify

Select to boot the system with the newly compiled kernel in the VNC window

After compiling here, there is already a new kernel of version 4.19.208, select this kernel to log in

2. Master the basic concepts of Linux system calls

调用linux内核函数_linux内核调试方法总结_内核系统调用

The process of the Linux system processing system calls and the way to reduce system calls. The Linux system provides hundreds of system calls. In order to uniquely identify each system call, Linux sets a unique number for each system call, called a system call number. At the same time, each system call requires a service The interpreter completes its specific functions.

I won’t go into too much description here.

(The focus is how to add system calls!!!)

#define __NR_hello_euler 294
__SYSCALL(__NR_hello_euler, sys_hello_euler)
#undef __NR_syscalls
#define __NR_syscalls 295
Copy after login

asmlinkage long sys_hello_euler(void);
Copy after login

SYSCALL_DEFINE0(hello_euler)
{
	printk(KERN_INFO "xuehao:20273108");
	return 0;
}
Copy after login

After restart

#include 
#include 
#include 
int main()
{
ret = syscall(294);
return 0;
}
Copy after login

3. Design and add linux system calls

(1) Change or return the priority (nice value and prio value) of the specified process (see textbook P328 for details) Tip: Possible reference kernel function: set_user_nice().

#define _GNU_SOURCE
#include
#include
#include
#include
int main()
{
	pid_t pid;
	int nicevalue;
	int flag;
	int n=0;
	int p=0;
	int *prio;
	int *nice;
	prio = &p;
	nice = &n;
	printf("请输入pid: n");
	scanf("%d",&pid);
	printf("pid输入成功n请输入nice值:n");
	scanf("%d",&nicevalue);
	printf("nice输入成功n请输入flag(flag为1时修改,为0时查看):n");
	scanf("%d",&flag);
	syscall(295,pid,flag,nicevalue,prio,nice);
	printf("现在的nice为%d,prio为%dn",n,p);
	return 0;
}
Copy after login

(2) Change the host name to a custom string (optional question)

#define __NR_mysethostname 296
__SYSCALL(__NR_mysethostname,sys_mysethostname)
Copy after login

Similarly, #define__NR_syscalls296 below should be changed to #define__NR_syscalls297

4. Experiment summary

(1) Before you do the experiment, you must clearly identify whether it is x86 or arm architecture after reading the tutorial! ! ! This is where I stumbled and rebuilt Huawei Cloud three or four times

(2) If the following error occurs when logging in with VNC, congratulations, it is probably because your kernel has crashed~ My teacher said that as long as you are fast enough, you can use VNC to restart the virtual machine immediately. It is possible to log in, and I did not succeed. I could only rebuild the cloud host n times.

(3) Although the experiment report given by the teacher requires VNC login to call the Linux kernel function , I personally recommend using cloudshell to execute the command.

(4) During the initial test, the teacher suddenly asked me about the meaning and usage of the functions in the system call, and I was immediately stumbled. I will post the meaning and usage of some internal functions below.

1.find_get_pid(pid)

find_get_pid has different namespaces in the kernel. The pid value of the same process in their respective namespaces may be different. Find_get_pid is to find the real pid of the process in the kernel mode

2.set_user_nice(task,nicevalue)

Used to set the nice value of the process

3.copy_to_user()

Complete the copy from kernel space to user space, To target address linux operating system version linux system, this address is the address of user space; From source address, this address is the address of kernel space; N bytes of the data to be copied number.

If the data copy is successful, return zero; otherwise, return the number of data bytes that were not copied successfully.

4.copy_from_user()

copy_from_user copies the string pointed to by name from user space to kernel space. If it fails, it returns the number of bytes that have not been copied. If it succeeds, it returns 0.

5.down_write()

The function down_write() is called when the writer uses it to get the read semaphore sem. If the semaphore is held by the reader or writer Call the linux kernel function , then the function's The call will cause the caller to sleep and can only be used in the process context to obtain the write lock in the Linux kernel read semaphore.

6.memcpy(str1,str2,n)

Copy n bytes from storage area str2 to storage area str1.

The above is the detailed content of Huawei Cloud completes the compilation and installation of the Linux kernel (optional topic). For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

3d rendering, computer configuration? What kind of computer is needed to design 3D rendering? 3d rendering, computer configuration? What kind of computer is needed to design 3D rendering? May 06, 2024 pm 06:25 PM

3d rendering, computer configuration? 1 Computer configuration is very important for 3D rendering, and sufficient hardware performance is required to ensure rendering effect and speed. 23D rendering requires a lot of calculations and image processing, so it requires high-performance CPU, graphics card and memory. 3 It is recommended to configure at least one computer with at least 6 cores and 12 threads CPU, more than 16GB of memory and a high-performance graphics card to meet the higher 3D rendering needs. At the same time, you also need to pay attention to the computer's heat dissipation and power supply configuration to ensure the stable operation of the computer. What kind of computer is needed to design 3D rendering? I am also a designer, so I will give you a set of configurations (I will use it again) CPU: amd960t with 6 cores (or 1090t directly overclocked) Memory: 1333

What you need to know when reinstalling the system from a USB flash drive: How to set up the BIOS correctly What you need to know when reinstalling the system from a USB flash drive: How to set up the BIOS correctly May 06, 2024 pm 03:00 PM

Reinstalling the system is a problem that many computer users often encounter. Whether it is due to system crash, poisoning or wanting to upgrade the system, reinstalling the system is a good choice. However, many people encounter various problems when reinstalling the system, such as not knowing how to set up the BIOS, not knowing how to choose a suitable installation disk, etc. Today, we will talk about some things you must know when reinstalling the system from a USB flash drive, and teach you how to set up the BIOS correctly and successfully complete the system reinstallation. Tool materials: System version: Windows1020H2 Brand model: Lenovo Xiaoxin Air14 Software version: Pocket machine One-click reinstallation of system software v1.0 1. Preparation 1. Prepare a U disk with a capacity of no less than 8GB, preferably USB3. 0, so the speed will be faster

How to assemble an acer desktop computer? How to assemble an acer desktop computer? May 08, 2024 pm 08:25 PM

How to assemble an acer desktop computer? The assembly method of Acer desktop computer is as follows: open the case, install the power supply into the case, and tighten the screws. Install the CPU onto the motherboard, making sure the pins on the CPU are aligned with the slots on the motherboard, and tighten the screws on the CPU heat sink. Install the memory module onto the motherboard, making sure that the bumps on the memory module are aligned with the slots on the motherboard. Press down hard until you hear a "pop" sound to complete the installation. Install graphics cards, sound cards, network cards and other boards onto the motherboard, making sure the screws on the boards are tightened. Install storage devices such as hard drives and optical drives into the chassis, making sure the screws are tightened. Connect the motherboard to the chassis, including power cables, hard drive cables, optical drive cables, etc. Finally, close the chassis cover and tighten the screws to complete the assembly. exist

Introduction to solutions to Xiaomi Leica camera crashes Introduction to solutions to Xiaomi Leica camera crashes May 08, 2024 pm 03:20 PM

Xiaomi’s new photography software Leica Camera is very popular, but this software will crash when taking pictures. Many users don’t know what’s going on and how to solve it. Let’s take a look at the Xiaomi Leica Camera crash solution. Method. What to do if the Xiaomi Leica camera crashes? Solution 1: 1. First turn off the phone, and then restart the phone after 30 seconds. 2. Then download a camera software of the same type and try to see if it can operate normally. 3. Open the phone settings-camera program-clear cache data. 4. If the problem is still not solved, try backing up the phone data and restoring factory settings. 5. If none of the above points are true, it may be a hardware problem with the camera component, and the phone needs to be returned to the factory for repair and testing. Solution two: 1. Back up important data and open the security center

Microsoft's latest Win11 Chinese official version system official original ISO image download Microsoft's latest Win11 Chinese official version system official original ISO image download May 06, 2024 am 11:13 AM

Microsoft's latest Windows 11 operating system has attracted much attention. Its new interface design, powerful performance and rich functional features have brought users a new experience. This article will give you a detailed introduction to the official original ISO image download method of the Windows 11 Chinese official version system, and provide some practical installation suggestions, hoping to help everyone successfully upgrade to this new operating system. Tool materials: System version: Windows 11 Chinese official version Brand model: Supports multiple brands and models of computers, such as Lenovo, Dell, Asus, etc. Software version: Microsoft official original ISO image 1. Download Windows 11 official original ISO image 1. Visit Microsoft official Website (https:/

Does the memory become smaller after reinstalling the system from USB flash drive? These reasons cannot be ignored! Does the memory become smaller after reinstalling the system from USB flash drive? These reasons cannot be ignored! May 06, 2024 pm 03:10 PM

Reinstalling the system is a common computer maintenance operation, but sometimes you encounter some unexpected situations, such as the memory becoming smaller after reinstalling the system on a USB flash drive. HH? Below we will analyze the reasons and provide some practical suggestions. Tool materials: System version: Windows 1021H2 Brand model: Lenovo ThinkPad After reinstalling the system, some users will install a large number of unnecessary drivers and software, which takes up memory space. 2. The system disk partition scheme is unreasonable. If the system disk space is not properly allocated when reinstalling the system, it may cause memory outage.

What to do if Win11 black screen teaches you how to solve Windows_11 black screen problem What to do if Win11 black screen teaches you how to solve Windows_11 black screen problem May 08, 2024 pm 03:10 PM

Windows 11 is the latest operating system launched by Microsoft, which brings a new interface design and more practical functions. However, some users encountered a black screen problem during the upgrade or use process, resulting in the inability to work properly. This article will introduce in detail several methods to effectively solve the black screen problem in Win11 and help you quickly restore the normal operation of the computer. Tool materials: System version: Windows11 (21H2) Brand model: Lenovo Xiaoxin Pro162022, Dell XPS13Plus, Asus ZenBookS13OLED Software version: NVIDIA GeForceExperience3.26.0.160, Intel Driver & SupportAssist

How to achieve wireless screen projection between computer and TV (simple steps allow you to easily enjoy the big-screen viewing experience) How to achieve wireless screen projection between computer and TV (simple steps allow you to easily enjoy the big-screen viewing experience) May 07, 2024 pm 02:43 PM

Computers and televisions have become indispensable entertainment tools in people's lives. In the digital era. Imagine being able to wirelessly cast content from your computer to a TV to play games and conduct presentations. Imagine that we would be able to enjoy movies on a larger screen. Let you enjoy a more shocking audio-visual experience. This article will show you how to achieve wireless screen mirroring between your computer and TV in simple steps. 1. Prepare a TV that supports wireless projection. Make sure you have a TV that supports wireless projection. If your TV doesn't have one, you can buy an external wireless screen projection device. Most smart TVs on the market now have this built-in function, such as Chromecast or AppleTV. 2. Choose the appropriate screencasting protocol. Next, choose the appropriate

See all articles