backup: Configuring the kernel environment from scratch
Configuring kernel environment
Compiling kernel
Download kernel source code: https://www.kernel.org/
Install necessary dependencies
1
2sudo apt-get update
sudo apt-get install git fakeroot build-essential ncurses-dev xz-utils libssl-dev bcUnzip and enter the directory
1
make menuconfig
ps: There may be errors that require flex and bison, apt-get install can fix them
Nothing should be changed, just save
1
2
3
4
5
6enter kernel hacking
Select the following items
Kernel debugging
Compile-time checks and compiler options —> Compile the kernel with debug info和Compile the kernel with frame pointers
KGDB
Then save and exitps: Remember not to make the terminal window too small when
make menuconfig
. Otherwise you will be prompted and not allowed to complete the next steps.```bash
make bzImageSetup is 17244 bytes (padded to 17408 bytes).
System is 7666 kB
CRC 5c77cbfe
Kernel: arch/x86/boot/bzImage is ready (#1)1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
### Add a simple syscall
Helloworld again
Create a `helloworld` directory in the root of the source code
```bash
$ pwd
/home/test/test_kernel/linux-xxxxxxx/helloworld
$ tree
.
├── helloworld.c
└── Makefile
$ cat helloworld.c
#include <linux/kernel.h>
asmlinkage long sys_helloworld(void){
printk("{==kernel==} hello world\n");
return 0;
}
$ cat Makefile
obj-y=helloworld.o
Then go to the Makefile
in the root of the source code and add helloworld/
Then go to include/linux/syscalls.h
and add the function prototype
Add system call numbers to arch/x86/entry/syscalls/syscall_32.tbl
and arch/x86/entry/syscalls/syscall_64.tbl
After that, compile the kernel
1 | make bzImage |
It will be able to get bzImage
in ./arch/x86/boot/
Compile busybox
As usual, download from the official website https://busybox.net/
Unzip and enter the directory
1 | make menuconfig |
Selected Build static binary (no shared libs)
within Settings
1 | make install |
After compiling, a _install
directory will appear, then:
1 | $ cd _install |
Install qumu
Here using source code compilation
1 | wget https://download.qemu.org/qemu-4.1.0.tar.xz |
qemu boot
Get a script from veritas501
1 | $ ls |
Run Script
1 | $ ./runqemu |
Done!
Reference
As well, thanks for MiGo and Aris’ guidance OWO
Other possible problems
Freely write
pkg-config not found
sudo apt-get install pkg-config
glib-2.40 gthread-2.0 is required to compile QEMU
Use apt-cache search all | grep glib
to find glib, can find glib’s name is libglib2.0-dev
, then apt install libglib2.0-dev
ERROR: pixman >= 0.21.8 not present.
Please install the pixman devel package.
Solution:
Use apt-cache search pixman
to find, then apt install libpixman-1-dev
Virtual machines remember to enable CPU virtualization
VNC server running on 127.0.0.1:5900
sudo apt-get install libsdl1.2-dev
sudo apt-get install gcc libsdl1.2-dev zlib1g-dev libasound2-dev pkg-config libgnutls-dev pciutils-dev
sudo apt-get install libsdl2-dev
sudo apt-get install libsdl2-2.0
sudo apt install libelf-dev
backup: Configuring the kernel environment from scratch
http://aslin.site/2022/03/09/backup-Configuring-the-kernel-environment-from-scratch/