Skip to content

Commit 5cb7f31

Browse files
committed
update kernel version
add kdev/rclocal and ... Signed-off-by: yifengyou <[email protected]>
1 parent 8abdb5d commit 5cb7f31

File tree

8 files changed

+376
-1
lines changed

8 files changed

+376
-1
lines changed

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
VERSION = 5
33
PATCHLEVEL = 15
44
SUBLEVEL = 60
5-
EXTRAVERSION =
5+
EXTRAVERSION = -kdev
6+
LOCALVERSION =
67
NAME = Trick or Treat
78

89
# *DOCUMENTATION*

kdev/linux-kernel-modules/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# helloworld kernel module
2+
3+
* 功能: 待录入
4+
* 创建时间: 2025-03-19 18:36:23
5+
6+
---
7+
8+
9+
10+
11+
---
12+

kdev/linux-kernel-modules/gen.sh

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
#!/bin/bash
2+
3+
if [ $# -ne 1 ]
4+
then
5+
echo "gen.sh need one parameter, please specific kernel module name."
6+
echo " begin with {a-z、A-z、_} , may contain 0-9 , make it sense."
7+
exit 1
8+
fi
9+
10+
[ ! -d src ] && mkdir src
11+
12+
if [ -f src/Makefile ]
13+
then
14+
echo "src/Makefile already exists! clean or backup it at first!"
15+
exit 1
16+
fi
17+
18+
cat > src/Makefile << EOF
19+
ENTRY := helloworld
20+
obj-m := \$(ENTRY).o
21+
KERNEL_VER = \$(shell uname -r)
22+
default: force_build
23+
24+
force_build: helloworld.c
25+
rm -f *.ko
26+
make -C /lib/modules/\$(KERNEL_VER)/build M=\$(PWD) modules
27+
ls -alh *.ko
28+
29+
notfound_build: helloworld.c
30+
[ -f *.ko ] || make -C /lib/modules/\$(KERNEL_VER)/build M=\$(PWD) modules
31+
32+
build: force_build
33+
34+
clean:
35+
make -C /lib/modules/\$(KERNEL_VER)/build M=\$(PWD) clean
36+
37+
insmod: info notfound_build
38+
dmesg --clear
39+
insmod helloworld.ko || true
40+
dmesg
41+
42+
rmmod:
43+
rmmod helloworld && dmesg
44+
45+
lsmod:
46+
lsmod |grep helloworld
47+
48+
status: lsmod
49+
50+
info: notfound_build helloworld.ko
51+
modinfo helloworld.ko
52+
md5sum helloworld.ko
53+
54+
modinfo: info
55+
56+
help:
57+
@echo " build - build module(default target)"
58+
@echo " clean - clean build dir"
59+
@echo " insmod - insmod helloworld ko module"
60+
@echo " rmmod - rmmod helloworld ko module"
61+
@echo " lsmod - find helloworld ko module whether already insmod"
62+
@echo " status - same as lsmod"
63+
@echo " info - display helloworld ko info"
64+
@echo " modinfo - same as info"
65+
@echo " help - display help info"
66+
67+
EOF
68+
69+
if [ -f "src/$1" ]
70+
then
71+
echo "src/$1 already exists! clean or backup it at first!"
72+
exit 1
73+
fi
74+
75+
cat > "src/$1.c" << EOF
76+
#include <linux/init.h>
77+
#include <linux/kernel.h>
78+
#include <linux/module.h>
79+
80+
static int __init helloworld_init(void)
81+
{
82+
printk(KERN_INFO "--------------------------------------------\n");
83+
printk(KERN_INFO "Loading helloworld Module\n");
84+
printk(KERN_INFO "file:%s func:%s line:%d\n",__FILE__,__func__,__LINE__);
85+
return 0;
86+
}
87+
88+
static void __exit helloworld_exit(void)
89+
{
90+
printk(KERN_INFO "--------------------------------------------\n");
91+
printk(KERN_INFO "Removing helloworld Module\n");
92+
printk(KERN_INFO "file:%s func:%s line:%d\n",__FILE__,__func__,__LINE__);
93+
}
94+
95+
module_init(helloworld_init);
96+
module_exit(helloworld_exit);
97+
98+
MODULE_LICENSE("GPL");
99+
MODULE_DESCRIPTION("helloworld Module");
100+
MODULE_AUTHOR("nicyou");
101+
EOF
102+
103+
104+
if [ -f README.md ]
105+
then
106+
echo "README.md already exists! clean or backup it at first!"
107+
exit 1
108+
fi
109+
110+
cat > README.md << EOF
111+
# helloworld kernel module
112+
113+
* 功能: 待录入
114+
* 创建时间: TIMESTAMP
115+
116+
---
117+
118+
119+
120+
121+
---
122+
123+
EOF
124+
125+
TIMESTAMP=`date +"%Y-%m-%d %H:%M:%S"`
126+
127+
sed -i "s/helloworld/$1/g" src/Makefile
128+
sed -i "s/helloworld/$1/g" "src/$1.c"
129+
sed -i "s/helloworld/$1/g" README.md
130+
sed -i "s/TIMESTAMP/${TIMESTAMP}/g" README.md
131+
132+
#[ -f gen.sh ] && rm -f gen.sh
133+
134+
echo "All done!"
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
ENTRY := helloworld
2+
obj-m := $(ENTRY).o
3+
KERNEL_VER = $(shell uname -r)
4+
default: force_build
5+
6+
force_build: helloworld.c
7+
rm -f *.ko
8+
make -C /lib/modules/$(KERNEL_VER)/build M=$(PWD) modules
9+
ls -alh *.ko
10+
11+
notfound_build: helloworld.c
12+
[ -f *.ko ] || make -C /lib/modules/$(KERNEL_VER)/build M=$(PWD) modules
13+
14+
build: force_build
15+
16+
clean:
17+
make -C /lib/modules/$(KERNEL_VER)/build M=$(PWD) clean
18+
19+
insmod: info notfound_build
20+
dmesg --clear
21+
insmod helloworld.ko || true
22+
dmesg
23+
24+
rmmod:
25+
rmmod helloworld && dmesg
26+
27+
lsmod:
28+
lsmod |grep helloworld
29+
30+
status: lsmod
31+
32+
info: notfound_build helloworld.ko
33+
modinfo helloworld.ko
34+
md5sum helloworld.ko
35+
36+
modinfo: info
37+
38+
help:
39+
@echo " build - build module(default target)"
40+
@echo " clean - clean build dir"
41+
@echo " insmod - insmod helloworld ko module"
42+
@echo " rmmod - rmmod helloworld ko module"
43+
@echo " lsmod - find helloworld ko module whether already insmod"
44+
@echo " status - same as lsmod"
45+
@echo " info - display helloworld ko info"
46+
@echo " modinfo - same as info"
47+
@echo " help - display help info"
48+
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#include <linux/init.h>
2+
#include <linux/kernel.h>
3+
#include <linux/module.h>
4+
5+
static int __init helloworld_init(void)
6+
{
7+
printk(KERN_INFO "--------------------------------------------\n");
8+
printk(KERN_INFO "Loading helloworld Module\n");
9+
printk(KERN_INFO "file:%s func:%s line:%d\n",__FILE__,__func__,__LINE__);
10+
return 0;
11+
}
12+
13+
static void __exit helloworld_exit(void)
14+
{
15+
printk(KERN_INFO "--------------------------------------------\n");
16+
printk(KERN_INFO "Removing helloworld Module\n");
17+
printk(KERN_INFO "file:%s func:%s line:%d\n",__FILE__,__func__,__LINE__);
18+
}
19+
20+
module_init(helloworld_init);
21+
module_exit(helloworld_exit);
22+
23+
MODULE_LICENSE("GPL");
24+
MODULE_DESCRIPTION("helloworld Module");
25+
MODULE_AUTHOR("nicyou");

kdev/linux5.kdev

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
sourcedir = /linux/linux-5.git
2+
nbd = nbd5
3+
sourcedir = /linux/linux-5.git
4+
arch = x86_64
5+
debug = True
6+
skipimagecheck = True
7+
vmname = kdev-linux5
8+
config = ubuntu22_x86_64_defconfig
9+
nodocker = False
10+
mrproper = False
11+
isoimage = False
12+
rclocal = /linux/linux-5.git-build-x86_64/rclocal
13+
qcow2_image = /linux/linux-5.git-build-x86_64/rootfs.qcow2
14+

kdev/rclocal

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
#!/bin/bash
2+
3+
if [ -f /etc/firstboot ]; then
4+
mv /etc/firstboot /etc/firstboot-bak
5+
cd /boot
6+
rm -f *.old
7+
8+
cat > /etc/default/grub << EOF
9+
# If you change this file, run 'update-grub' afterwards to update
10+
# /boot/grub/grub.cfg.
11+
# For full documentation of the options in this file, see:
12+
# info -f grub -n 'Simple configuration'
13+
14+
GRUB_DEFAULT=0
15+
# GRUB_TIMEOUT_STYLE=menu
16+
GRUB_TIMEOUT=20
17+
GRUB_DISTRIBUTOR=\`lsb_release -i -s 2> /dev/null || echo Debian\`
18+
GRUB_CMDLINE_LINUX_DEFAULT="rw console=tty0 console=ttyS0,115200n8 nokaslr earlyprintk=ttyS0 net.ifnames=0 biosdevname=0 kgdboc=ttyS0,115200 initcall_debug log_buf_len=32M serial8250.poll_timeout=10 level=10 apparmor=0 debug"
19+
GRUB_CMDLINE_LINUX=""
20+
21+
# Uncomment to enable BadRAM filtering, modify to suit your needs
22+
# This works with Linux (no patch required) and with any kernel that obtains
23+
# the memory map information from GRUB (GNU Mach, kernel of FreeBSD ...)
24+
#GRUB_BADRAM="0x01234567,0xfefefefe,0x89abcdef,0xefefefef"
25+
26+
# Uncomment to disable graphical terminal (grub-pc only)
27+
#GRUB_TERMINAL=console
28+
29+
# The resolution used on graphical terminal
30+
# note that you can use only modes which your graphic card supports via VBE
31+
# you can see them in real GRUB with the command \`vbeinfo'
32+
#GRUB_GFXMODE=640x480
33+
34+
# Uncomment if you don't want GRUB to pass "root=UUID=xxx" parameter to Linux
35+
#GRUB_DISABLE_LINUX_UUID=true
36+
37+
# Uncomment to disable generation of recovery mode menu entries
38+
#GRUB_DISABLE_RECOVERY="true"
39+
40+
# Uncomment to get a beep at grub start
41+
#GRUB_INIT_TUNE="480 440 1"
42+
GRUB_TERMINAL=serial
43+
GRUB_SERIAL_COMMAND="serial --unit=0 --speed=115200 --stop=1"
44+
EOF
45+
46+
update-initramfs -c -k 5.15.60-kdev
47+
update-grub2
48+
sync
49+
50+
if which chpasswd &> /dev/null ; then
51+
echo root:linux | chpasswd
52+
elif which passwd &> /dev/null ; then
53+
echo linux | passwd -stdin root
54+
else
55+
echo "can't reset root passwd"
56+
fi
57+
58+
sync
59+
cat > /root/.bashrc << EOF
60+
# kdev
61+
alias egrep='egrep --color=auto'
62+
alias fgrep='fgrep --color=auto'
63+
alias grep='grep --color=auto'
64+
alias l.='ls -d .* -a --color=auto'
65+
alias ll='ls -l -h -a --color=auto'
66+
alias ls='ls -a --color=auto'
67+
alias cp='cp -i'
68+
alias mv='mv -i'
69+
alias rm='rm -i'
70+
alias xzegrep='xzegrep --color=auto'
71+
alias xzfgrep='xzfgrep --color=auto'
72+
alias xzgrep='xzgrep --color=auto'
73+
alias zegrep='zegrep --color=auto'
74+
alias zfgrep='zfgrep --color=auto'
75+
alias zgrep='zgrep --color=auto'
76+
alias rpmbuild='rpmbuild --define "_topdir $(pwd)"'
77+
78+
# History setting
79+
export PROMPT_COMMAND="history -a"
80+
export HISTTIMEFORMAT="%F %T "
81+
export HISTSIZE=10000
82+
83+
# PS1
84+
PS1='\[\e[32;1m\][\[\e[31;1m\]\u\[\e[33;1m\]@\[\e[35;1m\]\h\[\e[36;1m\] \w\[\e[32;1m\]]\[\e[37;1m\]\\$\[\e[0m\] '
85+
86+
87+
EOF
88+
sync
89+
dhclient
90+
cat > /etc/apt/sources.list << EOF
91+
92+
# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
93+
# newer versions of the distribution.
94+
deb http://mirrors.aliyun.com/ubuntu jammy main restricted
95+
deb-src http://mirrors.aliyun.com/ubuntu jammy main restricted
96+
97+
## Major bug fix updates produced after the final release of the
98+
## distribution.
99+
deb http://mirrors.aliyun.com/ubuntu jammy-updates main restricted
100+
deb-src http://mirrors.aliyun.com/ubuntu jammy-updates main restricted
101+
102+
## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
103+
## team. Also, please note that software in universe WILL NOT receive any
104+
## review or updates from the Ubuntu security team.
105+
deb http://mirrors.aliyun.com/ubuntu jammy universe
106+
deb-src http://mirrors.aliyun.com/ubuntu jammy universe
107+
deb http://mirrors.aliyun.com/ubuntu jammy-updates universe
108+
deb-src http://mirrors.aliyun.com/ubuntu jammy-updates universe
109+
110+
## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
111+
## team, and may not be under a free licence. Please satisfy yourself as to
112+
## your rights to use the software. Also, please note that software in
113+
## multiverse WILL NOT receive any review or updates from the Ubuntu
114+
## security team.
115+
deb http://mirrors.aliyun.com/ubuntu jammy multiverse
116+
deb-src http://mirrors.aliyun.com/ubuntu jammy multiverse
117+
deb http://mirrors.aliyun.com/ubuntu jammy-updates multiverse
118+
deb-src http://mirrors.aliyun.com/ubuntu jammy-updates multiverse
119+
120+
## N.B. software from this repository may not have been tested as
121+
## extensively as that contained in the main release, although it includes
122+
## newer versions of some applications which may provide useful features.
123+
## Also, please note that software in backports WILL NOT receive any review
124+
## or updates from the Ubuntu security team.
125+
deb http://mirrors.aliyun.com/ubuntu jammy-backports main restricted universe multiverse
126+
deb-src http://mirrors.aliyun.com/ubuntu jammy-backports main restricted universe multiverse
127+
128+
EOF
129+
sed -i 's/security.ubuntu.com/mirrors.aliyun.com/g' /etc/apt/sources.list
130+
apt-get update && apt-get install -y vim tmux openssh-server net-tools build-essential lrzsz
131+
sed -i '/^#PermitRootLogin/c\PermitRootLogin yes' /etc/ssh/sshd_config
132+
sync
133+
# reboot -f
134+
else
135+
sync
136+
dhclient
137+
fi
138+
139+
exit 0

scripts/setlocalversion

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
#
1111
#
1212

13+
exit 0
14+
1315
usage() {
1416
echo "Usage: $0 [--save-scmversion] [srctree]" >&2
1517
exit 1

0 commit comments

Comments
 (0)