=熟悉《奔跑吧Linux内核(第二版)》的linux qemu虚拟开发板
目录
使用windows的wsl编译前的环境准备
使用windows的wsl的ubuntu 20.04编译代码前,除了按照指导手册说的:
首先,确保在 Linux 主机上安装了 aarch64-linux-gnu-gcc 和 QEMU 工具包。
$sudo apt-get install qemu qemu-system-arm gcc-aarch64-linux-gnu build-essential bison flex bc
然后,安装 gdb-multiarch 工具包。
$sudo apt-get install gdb-multiarch
还需要:
$sudo apt-get install libssl-dev
单板原型
编译内核
$ cd /home/rlk/rlk/runninglinuxkernel_5.0
$ ./run_rlk_arm64.sh build_kernel
生成 /home/rlk/rlk/runninglinuxkernel_5.0/arch/arm64/boot/Image
.
编译文件系统
$ cd /home/rlk/rlk/runninglinuxkernel_5.0
$ ./run_rlk_arm64.sh build_rootfs
生成 /home/rlk/rlk/runninglinuxkernel_5.0/rootfs_debian_arm64.ext4
.
编译内核模块
在vmware的虚拟机中编译ko(即交叉编译)
$ cd
/home/rlk/rlk/runninglinuxkernel_5.0/kmodules/rlk_lab/rlk_basic/chapter_5_module/lab1_simple_module
$sudo su //注意交叉编译ko需要root用户
# export ARCH=arm64
# export CROSS_COMPILE=aarch64-linux-gnu-
# export BASEINCLUDE=/home/rlk/rlk/runninglinuxkernel_5.0
# make
# cp test.ko runninglinuxkernel_5.0/kmodules
在qemu的开发板的mnt目录可以看到 test.ko,加载该内核模块:
$ insmod test.ko
在qemu的单板中自己编译ko
启动 QEMU+runninglinuxkernel。
$ ./run_rlk_arm64.sh run
Debian 系统的用户名为:root,密码为:123
进入本实验的参考代码。
# cd /mnt/rlk_lab/rlk_basic/chapter_5_module/lab1_simple_module
直接输入 make 命令来编译内核模块。
benshushu:lab1_simple_module# make
使用 insmod 命令来加载模块。
benshushu:lab1_simple_module# insmod mytest.ko
单板的启动
登录用户名root,密码123,在/home/rlk/rlk/runninglinuxkernel_5.0
下执行:
$ ./run_rlk_arm64.sh run
qemu单板和vmware之间传递文件
vmware的 /home/rlk/rlk/runninglinuxkernel_5.0/kmodules
和qemu单板的/mnt
是同步的。
单板的基本信息
benshushu:~# cat /etc/os-release
PRETTY_NAME="Debian GNU/Linux buster/sid"
NAME="Debian GNU/Linux"
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"
benshushu:~# lsmod
Module Size Used by
benshushu:~# cat /proc/cpuinfo
processor : 0
BogoMIPS : 125.00
Features : fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm jscvt fcma dcpop sha3 sm3 sm4 asimddp sha512 sve asimdfhm flagm sb paca pacg
CPU implementer : 0x00
CPU architecture: 8
CPU variant : 0x0
CPU part : 0x051
CPU revision : 0
processor : 1
BogoMIPS : 125.00
Features : fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm jscvt fcma dcpop sha3 sm3 sm4 asimddp sha512 sve asimdfhm flagm sb paca pacg
CPU implementer : 0x00
CPU architecture: 8
CPU variant : 0x0
CPU part : 0x051
CPU revision : 0
processor : 2
BogoMIPS : 125.00
Features : fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm jscvt fcma dcpop sha3 sm3 sm4 asimddp sha512 sve asimdfhm flagm sb paca pacg
CPU implementer : 0x00
CPU architecture: 8
CPU variant : 0x0
CPU part : 0x051
CPU revision : 0
processor : 3
BogoMIPS : 125.00
Features : fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm jscvt fcma dcpop sha3 sm3 sm4 asimddp sha512 sve asimdfhm flagm sb paca pacg
CPU implementer : 0x00
CPU architecture: 8
CPU variant : 0x0
CPU part : 0x051
CPU revision : 0
benshushu:~# cat /proc/meminfo
MemTotal: 736564 kB
MemFree: 562572 kB
MemAvailable: 602580 kB
Buffers: 6068 kB
Cached: 97292 kB
SwapCached: 0 kB
Active: 46724 kB
Inactive: 72496 kB
Active(anon): 16016 kB
Inactive(anon): 9300 kB
Active(file): 30708 kB
Inactive(file): 63196 kB
Unevictable: 0 kB
Mlocked: 0 kB
SwapTotal: 0 kB
SwapFree: 0 kB
Dirty: 24 kB
Writeback: 0 kB
AnonPages: 15804 kB
Mapped: 19676 kB
Shmem: 9460 kB
KReclaimable: 16108 kB
Slab: 36496 kB
SReclaimable: 16108 kB
SUnreclaim: 20388 kB
KernelStack: 2912 kB
PageTables: 764 kB
NFS_Unstable: 0 kB
Bounce: 0 kB
WritebackTmp: 0 kB
CommitLimit: 368280 kB
Committed_AS: 102636 kB
VmallocTotal: 135290159040 kB
VmallocUsed: 0 kB
VmallocChunk: 0 kB
Percpu: 912 kB
HardwareCorrupted: 0 kB
AnonHugePages: 0 kB
ShmemHugePages: 0 kB
ShmemPmdMapped: 0 kB
CmaTotal: 65536 kB
CmaFree: 65244 kB
HugePages_Total: 0
HugePages_Free: 0
HugePages_Rsvd: 0
HugePages_Surp: 0
Hugepagesize: 2048 kB
Hugetlb: 0 kB
benshushu:proc# cat mounts
/dev/root / ext4 rw,relatime 0 0
sysfs /sys sysfs rw,nosuid,nodev,noexec,relatime 0 0
proc /proc proc rw,nosuid,nodev,noexec,relatime 0 0
devtmpfs /dev devtmpfs rw,nosuid,size=333176k,nr_inodes=83294,mode=755 0 0
tmpfs /dev/shm tmpfs rw,nosuid,nodev 0 0
devpts /dev/pts devpts rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000 0 0
tmpfs /run tmpfs rw,nosuid,nodev,mode=755 0 0
tmpfs /run/lock tmpfs rw,nosuid,nodev,noexec,relatime,size=5120k 0 0
tmpfs /sys/fs/cgroup tmpfs ro,nosuid,nodev,noexec,mode=755 0 0
cgroup2 /sys/fs/cgroup/unified cgroup2 rw,nosuid,nodev,noexec,relatime,nsdelegate 0 0
cgroup /sys/fs/cgroup/systemd cgroup rw,nosuid,nodev,noexec,relatime,xattr,name=systemd 0 0
pstore /sys/fs/pstore pstore rw,nosuid,nodev,noexec,relatime 0 0
bpf /sys/fs/bpf bpf rw,nosuid,nodev,noexec,relatime,mode=700 0 0
cgroup /sys/fs/cgroup/devices cgroup rw,nosuid,nodev,noexec,relatime,devices 0 0
cgroup /sys/fs/cgroup/blkio cgroup rw,nosuid,nodev,noexec,relatime,blkio 0 0
cgroup /sys/fs/cgroup/cpu,cpuacct cgroup rw,nosuid,nodev,noexec,relatime,cpu,cpuacct 0 0
cgroup /sys/fs/cgroup/freezer cgroup rw,nosuid,nodev,noexec,relatime,freezer 0 0
cgroup /sys/fs/cgroup/cpuset cgroup rw,nosuid,nodev,noexec,relatime,cpuset 0 0
cgroup /sys/fs/cgroup/memory cgroup rw,nosuid,nodev,noexec,relatime,memory 0 0
cgroup /sys/fs/cgroup/perf_event cgroup rw,nosuid,nodev,noexec,relatime,perf_event 0 0
cgroup /sys/fs/cgroup/pids cgroup rw,nosuid,nodev,noexec,relatime,pids 0 0
systemd-1 /proc/sys/fs/binfmt_misc autofs rw,relatime,fd=28,pgrp=1,timeout=0,minproto=5,maxproto=5,direct,pipe_ino=1384 0 0
hugetlbfs /dev/hugepages hugetlbfs rw,relatime,pagesize=2M 0 0
debugfs /sys/kernel/debug debugfs rw,relatime 0 0
kmod_mount /mnt 9p rw,sync,dirsync,relatime,access=client,trans=virtio 0 0
tmpfs /run/user/0 tmpfs rw,nosuid,nodev,relatime,size=73656k,mode=700 0 0
benshushu:proc# uname -a
Linux benshushu 5.0.0+ #1 SMP Sun Mar 5 23:53:17 CST 2023 aarch64 GNU/Linux
benshushu:proc# cat cmdline
noinitrd nokaslr loglevel=8 sched_debug root=/dev/vda rootfstype=ext4 rw crashkernel=256M vfio.dyndbg=+pflmt irq_gic_v3_its.dyndbg=+pflmt iommu.dyndbg=+pflmt irqdomain.dyndbg=+pflmt
benshushu:proc# cat interrupts
CPU0 CPU1 CPU2 CPU3
3: 10149 11698 10371 10162 GICv3 27 Level arch_timer
36: 2193 0 0 0 GICv3 79 Edge virtio0
38: 0 0 0 0 GICv3 106 Edge arm-smmu-v3-evtq
41: 0 0 0 0 GICv3 109 Edge arm-smmu-v3-gerror
42: 0 0 0 0 GICv3 34 Level rtc-pl031
43: 172 0 0 0 GICv3 33 Level uart-pl011
44: 0 0 0 0 GICv3 23 Level arm-pmu
45: 16 0 0 0 GICv3 36 Level virtio1
46: 6 0 0 0 GICv3 37 Level virtio2
IPI0: 2134 1865 2002 1576 Rescheduling interrupts
IPI1: 303 264 132 251 Function call interrupts
IPI2: 0 0 0 0 CPU stop interrupts
IPI3: 0 0 0 0 CPU stop (for crash dump) interrupts
IPI4: 0 0 0 0 Timer broadcast interrupts
IPI5: 0 0 0 0 IRQ work interrupts
IPI6: 0 0 0 0 CPU wake-up interrupts
Err: 0
benshushu:proc# cat devices
Character devices:
1 mem
4 /dev/vc/0
4 tty
4 ttyS
5 /dev/tty
5 /dev/console
5 /dev/ptmx
5 ttyprintk
7 vcs
10 misc
13 input
29 fb
128 ptm
136 pts
204 ttyAMA
248 binder
249 vfio
250 bsg
251 watchdog
252 rtc
253 dax
254 gpiochip
Block devices:
7 loop
254 virtblk
259 blkext
benshushu:proc# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/root 2.0G 1.1G 788M 58% /
devtmpfs 326M 0 326M 0% /dev
tmpfs 360M 0 360M 0% /dev/shm
tmpfs 360M 9.3M 351M 3% /run
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 360M 0 360M 0% /sys/fs/cgroup
kmod_mount 982G 20G 913G 3% /mnt
tmpfs 72M 0 72M 0% /run/user/0
benshushu:proc# fdisk -l
Disk /dev/vda: 2 GiB, 2147483648 bytes, 4194304 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
benshushu:proc# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
vda 254:0 0 2G 0 disk /
benshushu:proc# cat iomem
09000000-09000fff : pl011@9000000
09000000-09000fff : pl011@9000000
09010000-09010fff : pl031@9010000
09010000-09010fff : rtc-pl031
09030000-09030fff : pl061@9030000
09030000-09030fff : pl061@9030000
09050000-0906ffff : smmuv3@9050000
0a003e00-0a003fff : a003e00.virtio_mmio
10000000-3efeffff : pcie@10000000
10000000-1003ffff : 0000:00:01.0
40000000-7fffffff : System RAM
40080000-41bfffff : Kernel code
41c00000-4208ffff : reserved
42090000-42240fff : Kernel data
48000000-480fffff : reserved
6ac00000-6fbfffff : reserved
6fd77000-6fdeefff : reserved
6fdf1000-6fdf2fff : reserved
6fdf3000-6fdf7fff : reserved
6fdf8000-6fdfffff : reserved
6fe00000-7fdfffff : Crash kernel
7fe00000-7fe00fff : reserved
7fe01000-7fe03fff : reserved
7fe04000-7fffffff : reserved
4010000000-401fffffff : PCI ECAM
8000000000-ffffffffff : pcie@10000000
8000000000-8000003fff : 0000:00:01.0
8000000000-8000003fff : virtio-pci-modern
8000004000-8000007fff : 0000:00:02.0
8000004000-8000007fff : virtio-pci-modern
benshushu:proc# ps -A
PID TTY TIME CMD
1 ? 00:00:19 systemd
2 ? 00:00:00 kthreadd
3 ? 00:00:00 rcu_gp
4 ? 00:00:00 rcu_par_gp
5 ? 00:00:00 kworker/0:0-cgroup_destroy
6 ? 00:00:00 kworker/0:0H-kblockd
7 ? 00:00:00 kworker/u8:0-events_unbound
8 ? 00:00:00 mm_percpu_wq
top - 13:01:50 up 5 min, 1 user, load average: 0.05, 0.43, 0.28
Tasks: 78 total, 1 running, 77 sleeping, 0 stopped, 0 zombie
%Cpu(s): 5.8 us, 5.8 sy, 0.0 ni, 88.5 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
MiB Mem : 719.3 total, 548.0 free, 53.3 used, 118.0 buff/cache
MiB Swap: 0.0 total, 0.0 free, 0.0 used. 588.2 avail Mem
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
747 root 20 0 7584 3040 2640 R 18.2 0.4 0:00.20 top
10 root 20 0 0 0 0 I 4.5 0.0 0:03.34 rcu_sched
1 root 20 0 165160 9392 6996 S 0.0 1.3 0:19.70 systemd
2 root 20 0 0 0 0 S 0.0 0.0 0:00.13 kthreadd
3 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 rcu_gp
4 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 rcu_par_gp
5 root 20 0 0 0 0 I 0.0 0.0 0:00.01 kworker/0+
6 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 kworker/0+
7 root 20 0 0 0 0 I 0.0 0.0 0:00.48 kworker/u+
8 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 mm_percpu+
9 root 20 0 0 0 0 S 0.0 0.0 0:00.30 ksoftirqd+
11 root rt 0 0 0 0 S 0.0 0.0 0:00.12 migration+
12 root 20 0 0 0 0 I 0.0 0.0 0:00.34 kworker/0+
13 root 20 0 0 0 0 S 0.0 0.0 0:00.01 cpuhp/0
14 root 20 0 0 0 0 S 0.0 0.0 0:00.01 cpuhp/1
15 root rt 0 0 0 0 S 0.0 0.0 0:00.11 migration+
16 root 20 0 0 0 0 S 0.0 0.0 0:00.15 ksoftirqd+
benshushu:proc# apt update
Get:1 http://mirrors.ustc.edu.cn/debian unstable InRelease [195 kB]
Err:1 http://mirrors.ustc.edu.cn/debian unstable InRelease
The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 0E98404D386FA1D9 NO_PUBKEY 6ED0E7B82643E131
Reading package lists... Done
W: GPG error: http://mirrors.ustc.edu.cn/debian unstable InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 0E98404D386FA1D9 NO_PUBKEY 6ED0E7B82643E131
E: The repository 'http://mirrors.ustc.edu.cn/debian unstable InRelease' is not signed.
N: Updating from such a repository can't be done securely, and is therefore disabled by default.
N: See apt-secure(8) manpage for repository creation and user configuration details.
benshushu:proc#
benshushu:proc# apt upgrade
Reading package lists... Done
Building dependency tree... Done
Calculating upgrade... Done
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
benshushu:proc# busybox --help
BusyBox v1.30.1 (Debian 1:1.30.1-4) multi-call binary.
BusyBox is copyrighted by many authors between 1998-2015.
Licensed under GPLv2. See source distribution for detailed
copyright notices.
Usage: busybox [function [arguments]...]
or: busybox --list[-full]
or: busybox --show SCRIPT
or: busybox --install [-s] [DIR]
or: function [arguments]...
BusyBox is a multi-call binary that combines many common Unix
utilities into a single executable. Most people will create a
link to busybox for each function they wish to use and BusyBox
will act like whatever it was invoked as.
Currently defined functions:
[, [[, acpid, adjtimex, ar, arch, arp, arping, ash, awk, basename, bc,
blkdiscard, blockdev, brctl, bunzip2, bzcat, bzip2, cal, cat, chgrp,
chmod, chown, chroot, chvt, clear, cmp, cp, cpio, cttyhack, cut, date,
dc, dd, deallocvt, depmod, devmem, df, diff, dirname, dmesg,
dnsdomainname, dos2unix, du, dumpkmap, dumpleases, echo, egrep, env,
expand, expr, factor, fallocate, false, fatattr, fgrep, find, fold,
free, freeramdisk, fsfreeze, fstrim, ftpget, ftpput, getopt, getty,
grep, groups, gunzip, gzip, halt, head, hexdump, hostid, hostname,
httpd, hwclock, i2cdetect, i2cdump, i2cget, i2cset, id, ifconfig,
ifdown, ifup, init, insmod, ionice, ip, ipcalc, ipneigh, kill, killall,
klogd, last, less, link, linux32, linux64, linuxrc, ln, loadfont,
loadkmap, logger, login, logname, logread, losetup, ls, lsmod, lsscsi,
lzcat, lzma, lzop, md5sum, mdev, microcom, mkdir, mkdosfs, mke2fs,
mkfifo, mknod, mkpasswd, mkswap, mktemp, modinfo, modprobe, more,
mount, mt, mv, nameif, nc, netstat, nl, nologin, nproc, nsenter,
nslookup, nuke, od, openvt, partprobe, paste, patch, pidof, ping,
ping6, pivot_root, poweroff, printf, ps, pwd, rdate, readlink,
realpath, reboot, renice, reset, resume, rev, rm, rmdir, rmmod, route,
rpm, rpm2cpio, run-init, run-parts, sed, seq, setkeycodes, setpriv,
setsid, sh, sha1sum, sha256sum, sha512sum, shred, shuf, sleep, sort,
ssl_client, start-stop-daemon, stat, strings, stty, svc, svok, swapoff,
swapon, switch_root, sync, sysctl, syslogd, tac, tail, tar, taskset,
tee, telnet, test, tftp, time, timeout, top, touch, tr, traceroute,
traceroute6, true, truncate, tty, ubirename, udhcpc, udhcpd, uevent,
umount, uname, uncompress, unexpand, uniq, unix2dos, unlink, unlzma,
unshare, unxz, unzip, uptime, usleep, uudecode, uuencode, vconfig, vi,
w, watch, watchdog, wc, wget, which, who, whoami, xargs, xxd, xz,
xzcat, yes, zcat
benshushu:proc# busybox i2cdetect -l
i2cdetect: can't open '/sys/class/i2c-dev': No such file or directory
benshushu:proc# find /etc/init.d/
/etc/init.d/
/etc/init.d/hwclock.sh
/etc/init.d/dhcpcd
/etc/init.d/kmod
/etc/init.d/rsyslog
/etc/init.d/networking
/etc/init.d/procps
/etc/init.d/avahi-daemon
/etc/init.d/kexec
/etc/init.d/dbus
/etc/init.d/ssh
/etc/init.d/kdump-tools
/etc/init.d/kexec-load
/etc/init.d/udev
/etc/init.d/cron
/etc/init.d/sudo
benshushu:proc# dumpsys meminfo
-bash: dumpsys: command not found