


Huawei Cloud completes the compilation and installation of the Linux kernel (optional topic)
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
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
asmlinkage long sys_hello_euler(void);
SYSCALL_DEFINE0(hello_euler) { printk(KERN_INFO "xuehao:20273108"); return 0; }
After restart
#include #include #include int main() { ret = syscall(294); return 0; }
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; }
(2) Change the host name to a custom string (optional question)
#define __NR_mysethostname 296 __SYSCALL(__NR_mysethostname,sys_mysethostname)
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!

The main tasks of Linux system administrators include system monitoring and performance tuning, user management, software package management, security management and backup, troubleshooting and resolution, performance optimization and best practices. 1. Use top, htop and other tools to monitor system performance and tune it. 2. Manage user accounts and permissions through useradd commands and other commands. 3. Use apt and yum to manage software packages to ensure system updates and security. 4. Configure a firewall, monitor logs, and perform data backup to ensure system security. 5. Troubleshoot and resolve through log analysis and tool use. 6. Optimize kernel parameters and application configuration, and follow best practices to improve system performance and stability.

Learning Linux is not difficult. 1.Linux is an open source operating system based on Unix and is widely used in servers, embedded systems and personal computers. 2. Understanding file system and permission management is the key. The file system is hierarchical, and permissions include reading, writing and execution. 3. Package management systems such as apt and dnf make software management convenient. 4. Process management is implemented through ps and top commands. 5. Start learning from basic commands such as mkdir, cd, touch and nano, and then try advanced usage such as shell scripts and text processing. 6. Common errors such as permission problems can be solved through sudo and chmod. 7. Performance optimization suggestions include using htop to monitor resources, cleaning unnecessary files, and using sy

The average annual salary of Linux administrators is $75,000 to $95,000 in the United States and €40,000 to €60,000 in Europe. To increase salary, you can: 1. Continuously learn new technologies, such as cloud computing and container technology; 2. Accumulate project experience and establish Portfolio; 3. Establish a professional network and expand your network.

The main uses of Linux include: 1. Server operating system, 2. Embedded system, 3. Desktop operating system, 4. Development and testing environment. Linux excels in these areas, providing stability, security and efficient development tools.

The Internet does not rely on a single operating system, but Linux plays an important role in it. Linux is widely used in servers and network devices and is popular for its stability, security and scalability.

The core of the Linux operating system is its command line interface, which can perform various operations through the command line. 1. File and directory operations use ls, cd, mkdir, rm and other commands to manage files and directories. 2. User and permission management ensures system security and resource allocation through useradd, passwd, chmod and other commands. 3. Process management uses ps, kill and other commands to monitor and control system processes. 4. Network operations include ping, ifconfig, ssh and other commands to configure and manage network connections. 5. System monitoring and maintenance use commands such as top, df, du to understand the system's operating status and resource usage.

Introduction Linux is a powerful operating system favored by developers, system administrators, and power users due to its flexibility and efficiency. However, frequently using long and complex commands can be tedious and er

Linux is suitable for servers, development environments, and embedded systems. 1. As a server operating system, Linux is stable and efficient, and is often used to deploy high-concurrency applications. 2. As a development environment, Linux provides efficient command line tools and package management systems to improve development efficiency. 3. In embedded systems, Linux is lightweight and customizable, suitable for environments with limited resources.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Atom editor mac version download
The most popular open source editor

SublimeText3 Linux new version
SublimeText3 Linux latest version

SublimeText3 Mac version
God-level code editing software (SublimeText3)

SublimeText3 English version
Recommended: Win version, supports code prompts!

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.