主机软件版本信息
- 主机系统:
wxer@wxer:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 20.04.1 LTS
Release: 20.04
Codename: focal
- 模拟器版本(Qemu版本):
wxer@wxer:~$ qemu-system-x86_64 --version
QEMU emulator version 4.2.0
Copyright (c) 2003-2019 Fabrice Bellard and the QEMU Project developer
- 主机内核版本
wxer@wxer:~$ uname -a
Linux wxer 5.4.0-42-generic #46-Ubuntu SMP Fri Jul 10 00:24:02 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
- 编译器版本:
wxer@wxer:~$ gcc --version
gcc (Ubuntu 9.3.0-10ubuntu2) 9.3.0
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
软件安装
- 安装Ubuntu系统
- 编译器GCC系统自带
- Qemu模拟器安装
Linux内核编译
下载内核源码
从https://www.kernel.org下载最新的Linux内核源码,目前(2020.09.05)最新的内核源码是:linux-5.8.6.tar.xz
解压内核
wxer@wxer:~/os_dev/qemu_x86_64_linux$ xz -d linux-5.8.6.tar.xz
wxer@wxer:~/os_dev/qemu_x86_64_linux$ tar xvf linux-5.8.6.tar
配置编译项
cd linux-5.8.6/
make O=build x86_64_defconfig
make O=build menuconfig
由于选择用ramdisk启动的方式,因此需要在配置项中选择支持RAM block device,RAM disk大小配置为64M(65535字节)。如下图所示
编译
make O=build bzImage -j8
制作根文件系统
从https://busybox.net/downloads/网站下载最新的busybox源码,截至当前时间(2020/09/05)的最新版本是:busybox-1.32.0.tar.bz2
按如下步骤编译busybox
mkdir build
make O=build menuconfig
cd build
make -j4
make install
制作initramfs文件
使用如下脚本制作ramdisk文件
wxer@wxer:~/os_dev/qemu_x86_64_linux$ mkdir -pv initramfs/x86_64_busybox
mkdir: 已创建目录 'initramfs'
mkdir: 已创建目录 'initramfs/x86_64_busybox'
wxer@wxer:~/os_dev/qemu_x86_64_linux$ ls
busybox-1.32.0 busybox-1.32.0.tar.bz2 initramfs linux-5.8.6 linux-5.8.6.tar mk_ramdisk ramdisk.gz run.sh
wxer@wxer:~/os_dev/qemu_x86_64_linux$ cd initramfs/x86_64_busybox/
wxer@wxer:~/os_dev/qemu_x86_64_linux/initramfs/x86_64_busybox$ mkdir -pv {bin,sbin,etc,proc,sys,usr/{bin,sbin}}
mkdir: 已创建目录 'bin'
mkdir: 已创建目录 'sbin'
mkdir: 已创建目录 'etc'
mkdir: 已创建目录 'proc'
mkdir: 已创建目录 'sys'
mkdir: 已创建目录 'usr'
mkdir: 已创建目录 'usr/bin'
mkdir: 已创建目录 'usr/sbin'
wxer@wxer:~/os_dev/qemu_x86_64_linux/initramfs/x86_64_busybox$ cp -av ../../busybox-1.32.0/build/_install/* .
initramfs需要一个init程序,可以写一个简单的shell脚本作为init,内容如下
#!/bin/sh
mount -t proc none /proc
mount -t sysfs none /sys
echo -e "\nBoot took $(cut -d' ' -f1 /proc/uptime) seconds\n"
exec /bin/sh
修改init的执行权限
chmod u+x init
同时编写一个hello.c程序,放到bin目录下作为测试可执行文件的执行效果
hello.c文件如下
#include <stdio.h>
int main()
{
printf("Boot init app...\n");
printf("Hello, World\n");
fflush(stdout);
return 0;
}
编译为可执行文件的命令为
gcc -static -o hello hello.c
修改hello的权限为可执行
chmod a+x hello
然后把编译生成的hello可执行文件拷贝到x86_64_busybox/bin目录下
cp hello x86_64_busybox/bin/.
将x86_64_busybox目录下的内容打包归档为cpio文件,供linux内核在做initramfs启动时执行,打包为cpio文件的命令为
find . -print0 | cpio --null -ov --format=newc | gzip -9 > …/initramfs-busybox-x86_64.cpio.gz
Qemu启动linux内核
命令如下
qemu-system-x86_64
-smp 2
-m 1024M
-kernel ./linux-5.8.6/build/arch/x86_64/boot/bzImage
-nographic
-append “root=/dev/ram0 rw rootfstype=ext4 console=ttyS0 init=/linuxrc”
-initrd ./initramfs/initramfs-busybox-x86_64.cpio.gz \
运行效果如下图
启动的Log如下
[ 0.000000] Linux version 5.8.6 (wxer@wxer) (gcc (Ubuntu 9.3.0-10ubuntu2) 9.0
[ 0.000000] Command line: root=/dev/ram0 rw rootfstype=ext4 console=ttyS0 inc
[ 0.000000] x86/fpu: x87 FPU will use FXSAVE
[ 0.000000] BIOS-provided physical RAM map:
[ 0.000000] BIOS-e820: [mem 0x0000000000000000-0x000000000009fbff] usable
[ 0.000000] BIOS-e820: [mem 0x000000000009fc00-0x000000000009ffff] reserved
[ 0.000000] BIOS-e820: [mem 0x00000000000f0000-0x00000000000fffff] reserved
[ 0.000000] BIOS-e820: [mem 0x0000000000100000-0x000000003ffdffff] usable
[ 0.000000] BIOS-e820: [mem 0x000000003ffe0000-0x000000003fffffff] reserved
[ 0.000000] BIOS-e820: [mem 0x00000000fffc0000-0x00000000ffffffff] reserved
[ 0.000000] NX (Execute Disable) protection: active
[ 0.000000] SMBIOS 2.8 present.
[ 0.000000] DMI: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.12.0-59-4
[ 0.000000] last_pfn = 0x3ffe0 max_arch_pfn = 0x400000000
[ 0.000000] x86/PAT: Configuration [0-7]: WB WC UC- UC WB WP UC- WT
[ 0.000000] found SMP MP-table at [mem 0x000f5a90-0x000f5a9f]
[ 0.000000] check: Scanning 1 areas for low memory corruption
[ 0.000000] RAMDISK: [mem 0x3fe2d000-0x3ffdffff]
[ 0.000000] ACPI: Early table checksum verification disabled
[ 0.000000] ACPI: RSDP 0x00000000000F5870 000014 (v00 BOCHS )
[ 0.000000] ACPI: RSDT 0x000000003FFE15C9 000030 (v01 BOCHS BXPCRSDT 000000)
[ 0.000000] ACPI: FACP 0x000000003FFE149D 000074 (v01 BOCHS BXPCFACP 000000)
[ 0.000000] ACPI: DSDT 0x000000003FFE0040 00145D (v01 BOCHS BXPCDSDT 000000)
[ 0.000000] ACPI: FACS 0x000000003FFE0000 000040
[ 0.000000] ACPI: APIC 0x000000003FFE1511 000080 (v01 BOCHS BXPCAPIC 000000)
[ 0.000000] ACPI: HPET 0x000000003FFE1591 000038 (v01 BOCHS BXPCHPET 000000)
[ 0.000000] No NUMA configuration found
[ 0.000000] Faking a node at [mem 0x0000000000000000-0x000000003ffdffff]
[ 0.000000] NODE_DATA(0) allocated [mem 0x3fe29000-0x3fe2cfff]
[ 0.000000] Zone ranges:
[ 0.000000] DMA [mem 0x0000000000001000-0x0000000000ffffff]
[ 0.000000] DMA32 [mem 0x0000000001000000-0x000000003ffdffff]
[ 0.000000] Normal empty
[ 0.000000] Movable zone start for each node
[ 0.000000] Early memory node ranges
[ 0.000000] node 0: [mem 0x0000000000001000-0x000000000009efff]
[ 0.000000] node 0: [mem 0x0000000000100000-0x000000003ffdffff]
[ 0.000000] Zeroed struct page in unavailable ranges: 130 pages
[ 0.000000] Initmem setup node 0 [mem 0x0000000000001000-0x000000003ffdffff]
[ 0.000000] ACPI: PM-Timer IO Port: 0x608
[ 0.000000] ACPI: LAPIC_NMI (acpi_id[0xff] dfl dfl lint[0x1])
[ 0.000000] IOAPIC[0]: apic_id 0, version 32, address 0xfec00000, GSI 0-23
[ 0.000000] ACPI: INT_SRC_OVR (bus 0 bus_irq 0 global_irq 2 dfl dfl)
[ 0.000000] ACPI: INT_SRC_OVR (bus 0 bus_irq 5 global_irq 5 high level)
[ 0.000000] ACPI: INT_SRC_OVR (bus 0 bus_irq 9 global_irq 9 high level)
[ 0.000000] ACPI: INT_SRC_OVR (bus 0 bus_irq 10 global_irq 10 high level)
[ 0.000000] ACPI: INT_SRC_OVR (bus 0 bus_irq 11 global_irq 11 high level)
[ 0.000000] Using ACPI (MADT) for SMP configuration information
[ 0.000000] ACPI: HPET id: 0x8086a201 base: 0xfed00000
[ 0.000000] smpboot: Allowing 2 CPUs, 0 hotplug CPUs
[ 0.000000] PM: hibernation: Registered nosave memory: [mem 0x00000000-0x000]
[ 0.000000] PM: hibernation: Registered nosave memory: [mem 0x0009f000-0x000]
[ 0.000000] PM: hibernation: Registered nosave memory: [mem 0x000a0000-0x000]
[ 0.000000] PM: hibernation: Registered nosave memory: [mem 0x000f0000-0x000]
[ 0.000000] [mem 0x40000000-0xfffbffff] available for PCI devices
[ 0.000000] clocksource: refined-jiffies: mask: 0xffffffff max_cycles: 0xfffs
[ 0.000000] setup_percpu: NR_CPUS:64 nr_cpumask_bits:64 nr_cpu_ids:2 nr_node1
[ 0.000000] percpu: Embedded 52 pages/cpu s172632 r8192 d32168 u1048576
[ 0.000000] Built 1 zonelists, mobility grouping on. Total pages: 257897
[ 0.000000] Policy zone: DMA32
[ 0.000000] Kernel command line: root=/dev/ram0 rw rootfstype=ext4 console=tc
[ 0.000000] Dentry cache hash table entries: 131072 (order: 8, 1048576 bytes)
[ 0.000000] Inode-cache hash table entries: 65536 (order: 7, 524288 bytes, l)
[ 0.000000] mem auto-init: stack:off, heap alloc:off, heap free:off
[ 0.000000] Memory: 999108K/1048056K available (14340K kernel code, 1542K rw)
[ 0.000000] SLUB: HWalign=64, Order=0-3, MinObjects=0, CPUs=2, Nodes=1
[ 0.000000] rcu: Hierarchical RCU implementation.
[ 0.000000] rcu: RCU event tracing is enabled.
[ 0.000000] rcu: RCU restricting CPUs from NR_CPUS=64 to nr_cpu_ids=2.
[ 0.000000] rcu: RCU calculated value of scheduler-enlistment delay is 100 j.
[ 0.000000] rcu: Adjusting geometry for rcu_fanout_leaf=16, nr_cpu_ids=2
[ 0.000000] NR_IRQS: 4352, nr_irqs: 440, preallocated irqs: 16
[ 0.000000] random: get_random_bytes called from start_kernel+0x357/0x522 wi0
[ 0.000000] Console: colour VGA+ 80x25
[ 0.000000] printk: console [ttyS0] enabled
[ 0.000000] ACPI: Core revision 20200528
[ 0.000000] clocksource: hpet: mask: 0xffffffff max_cycles: 0xffffffff, max_s
[ 0.006000] APIC: Switch to symmetric I/O mode setup
[ 0.021000] ..TIMER: vector=0x30 apic1=0 pin1=2 apic2=-1 pin2=-1
[ 0.030000] tsc: Unable to calibrate against PIT
[ 0.030000] tsc: using HPET reference calibration
[ 0.031000] tsc: Detected 2993.134 MHz processor
[ 0.003216] tsc: Marking TSC unstable due to TSCs unsynchronized
[ 0.004899] Calibrating delay loop (skipped), value calculated using timer f)
[ 0.007390] pid_max: default: 32768 minimum: 301
[ 0.010623] LSM: Security Framework initializing
[ 0.015221] SELinux: Initializing.
[ 0.018925] Mount-cache hash table entries: 2048 (order: 2, 16384 bytes, lin)
[ 0.019211] Mountpoint-cache hash table entries: 2048 (order: 2, 16384 bytes)
[ 0.106929] Last level iTLB entries: 4KB 0, 2MB 0, 4MB 0
[ 0.107160] Last level dTLB entries: 4KB 0, 2MB 0, 4MB 0, 1GB 0
[ 0.108786] Spectre V1 : Mitigation: usercopy/swapgs barriers and __user poin
[ 0.109631] Spectre V2 : Mitigation: Full AMD retpoline
[ 0.110143] Spectre V2 : Spectre v2 / SpectreRSB mitigation: Filling RSB on h
[ 0.111131] Speculative Store Bypass: Vulnerable
[ 0.125567] Freeing SMP alternatives memory: 40K
[ 0.225503] random: fast init done
[ 0.273323] smpboot: CPU0: AMD QEMU Virtual CPU version 2.5+ (family: 0x6, m)
[ 0.299101] Performance Events: PMU not available due to virtualization, usi.
[ 0.306028] rcu: Hierarchical SRCU implementation.
[ 0.329113] smp: Bringing up secondary CPUs ...
[ 0.337478] x86: Booting SMP configuration:
[ 0.338150] .... node #0, CPUs: #1
[ 0.000000] smpboot: CPU 1 Converting physical 0 to logical die 1
[ 0.455411] smp: Brought up 1 node, 2 CPUs
[ 0.455893] smpboot: Max logical packages: 2
[ 0.456453] smpboot: Total of 2 processors activated (11900.44 BogoMIPS)
[ 0.520313] devtmpfs: initialized
[ 0.554612] clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, ms
[ 0.555640] futex hash table entries: 512 (order: 3, 32768 bytes, linear)
[ 0.572077] PM: RTC time: 09:15:08, date: 2020-09-05
[ 0.574440] thermal_sys: Registered thermal governor 'step_wise'
[ 0.574913] thermal_sys: Registered thermal governor 'user_space'
[ 0.594401] NET: Registered protocol family 16
[ 0.607504] audit: initializing netlink subsys (disabled)
[ 0.615827] audit: type=2000 audit(1599297307.643:1): state=initialized audi1
[ 0.640609] cpuidle: using governor menu
[ 0.645179] ACPI: bus type PCI registered
[ 0.655304] PCI: Using configuration type 1 for base access
[ 0.667653] mtrr: your CPUs had inconsistent fixed MTRR settings
[ 0.668161] mtrr: your CPUs had inconsistent variable MTRR settings
[ 0.668538] mtrr: your CPUs had inconsistent MTRRdefType settings
[ 0.668881] mtrr: probably your BIOS does not setup all CPUs.
[ 0.669140] mtrr: corrected configuration.
[ 0.735315] HugeTLB registered 2.00 MiB page size, pre-allocated 0 pages
[ 0.752917] cryptomgr_test (26) used greatest stack depth: 15616 bytes left
[ 0.752701] cryptomgr_test (25) used greatest stack depth: 15512 bytes left
[ 0.757308] cryptomgr_test (28) used greatest stack depth: 15248 bytes left
[ 0.761485] cryptomgr_test (30) used greatest stack depth: 15200 bytes left
[ 0.786641] ACPI: Added _OSI(Module Device)
[ 0.787102] ACPI: Added _OSI(Processor Device)
[ 0.787437] ACPI: Added _OSI(3.0 _SCP Extensions)
[ 0.787709] ACPI: Added _OSI(Processor Aggregator Device)
[ 0.788541] ACPI: Added _OSI(Linux-Dell-Video)
[ 0.788800] ACPI: Added _OSI(Linux-Lenovo-NV-HDMI-Audio)
[ 0.789120] ACPI: Added _OSI(Linux-HPI-Hybrid-Graphics)
[ 0.855254] ACPI: 1 ACPI AML tables successfully acquired and loaded
[ 0.922832] ACPI: Interpreter enabled
[ 0.927575] ACPI: (supports S0 S3 S4 S5)
[ 0.927988] ACPI: Using IOAPIC for interrupt routing
[ 0.930631] PCI: Using host bridge windows from ACPI; if necessary, use "pcig
[ 0.936077] ACPI: Enabled 2 GPEs in block 00 to 0F
[ 1.063004] ACPI: PCI Root Bridge [PCI0] (domain 0000 [bus 00-ff])
[ 1.065986] acpi PNP0A03:00: _OSC: OS supports [ASPM ClockPM Segments MSI HP]
[ 1.070220] acpi PNP0A03:00: fail to add MMCONFIG information, can't access .
[ 1.081317] PCI host bridge to bus 0000:00
[ 1.082300] pci_bus 0000:00: root bus resource [io 0x0000-0x0cf7 window]
[ 1.082700] pci_bus 0000:00: root bus resource [io 0x0d00-0xffff window]
[ 1.083183] pci_bus 0000:00: root bus resource [mem 0x000a0000-0x000bffff wi]
[ 1.083590] pci_bus 0000:00: root bus resource [mem 0x40000000-0xfebfffff wi]
[ 1.083963] pci_bus 0000:00: root bus resource [mem 0x100000000-0x17fffffff ]
[ 1.084597] pci_bus 0000:00: root bus resource [bus 00-ff]
[ 1.089718] pci 0000:00:00.0: [8086:1237] type 00 class 0x060000
[ 1.113438] pci 0000:00:01.0: [8086:7000] type 00 class 0x060100
[ 1.116836] pci 0000:00:01.1: [8086:7010] type 00 class 0x010180
[ 1.125680] pci 0000:00:01.1: reg 0x20: [io 0xc040-0xc04f]
[ 1.129285] pci 0000:00:01.1: legacy IDE quirk: reg 0x10: [io 0x01f0-0x01f7]
[ 1.129839] pci 0000:00:01.1: legacy IDE quirk: reg 0x14: [io 0x03f6]
[ 1.130278] pci 0000:00:01.1: legacy IDE quirk: reg 0x18: [io 0x0170-0x0177]
[ 1.130806] pci 0000:00:01.1: legacy IDE quirk: reg 0x1c: [io 0x0376]
[ 1.134290] pci 0000:00:01.3: [8086:7113] type 00 class 0x068000
[ 1.136396] pci 0000:00:01.3: quirk: [io 0x0600-0x063f] claimed by PIIX4 ACI
[ 1.137008] pci 0000:00:01.3: quirk: [io 0x0700-0x070f] claimed by PIIX4 SMB
[ 1.140366] pci 0000:00:02.0: [1234:1111] type 00 class 0x030000
[ 1.142299] pci 0000:00:02.0: reg 0x10: [mem 0xfd000000-0xfdffffff pref]
[ 1.147077] pci 0000:00:02.0: reg 0x18: [mem 0xfebf0000-0xfebf0fff]
[ 1.157007] pci 0000:00:02.0: reg 0x30: [mem 0xfebe0000-0xfebeffff pref]
[ 1.161003] pci 0000:00:03.0: [8086:100e] type 00 class 0x020000
[ 1.163227] pci 0000:00:03.0: reg 0x10: [mem 0xfebc0000-0xfebdffff]
[ 1.166077] pci 0000:00:03.0: reg 0x14: [io 0xc000-0xc03f]
[ 1.177218] pci 0000:00:03.0: reg 0x30: [mem 0xfeb80000-0xfebbffff pref]
[ 1.200385] ACPI: PCI Interrupt Link [LNKA] (IRQs 5 *10 11)
[ 1.203375] ACPI: PCI Interrupt Link [LNKB] (IRQs 5 *10 11)
[ 1.204907] ACPI: PCI Interrupt Link [LNKC] (IRQs 5 10 *11)
[ 1.207419] ACPI: PCI Interrupt Link [LNKD] (IRQs 5 10 *11)
[ 1.208384] ACPI: PCI Interrupt Link [LNKS] (IRQs *9)
[ 1.220191] iommu: Default domain type: Translated
[ 1.237780] pci 0000:00:02.0: vgaarb: setting as boot VGA device
[ 1.238077] pci 0000:00:02.0: vgaarb: VGA device added: decodes=io+mem,owns=e
[ 1.238357] pci 0000:00:02.0: vgaarb: bridge control possible
[ 1.239394] vgaarb: loaded
[ 1.245302] SCSI subsystem initialized
[ 1.251502] ACPI: bus type USB registered
[ 1.253587] usbcore: registered new interface driver usbfs
[ 1.255144] usbcore: registered new interface driver hub
[ 1.256243] usbcore: registered new device driver usb
[ 1.258233] pps_core: LinuxPPS API ver. 1 registered
[ 1.258565] pps_core: Software ver. 5.3.6 - Copyright 2005-2007 Rodolfo Giom>
[ 1.259295] PTP clock support registered
[ 1.267616] Advanced Linux Sound Architecture Driver Initialized.
[ 1.310642] NetLabel: Initializing
[ 1.310888] NetLabel: domain hash size = 128
[ 1.311130] NetLabel: protocols = UNLABELED CIPSOv4 CALIPSO
[ 1.315547] NetLabel: unlabeled traffic allowed by default
[ 1.319100] PCI: Using ACPI for IRQ routing
[ 1.326621] hpet: 3 channels of 0 reserved for per-cpu timers
[ 1.328255] hpet0: at MMIO 0xfed00000, IRQs 2, 8, 0
[ 1.328843] hpet0: 3 comparators, 64-bit 100.000000 MHz counter
[ 1.335919] clocksource: Switched to clocksource hpet
[ 2.079487] VFS: Disk quotas dquot_6.6.0
[ 2.080490] VFS: Dquot-cache hash table entries: 512 (order 0, 4096 bytes)
[ 2.090630] pnp: PnP ACPI init
[ 2.109636] pnp: PnP ACPI: found 6 devices
[ 2.180056] clocksource: acpi_pm: mask: 0xffffff max_cycles: 0xffffff, max_is
[ 2.182819] NET: Registered protocol family 2
[ 2.211671] tcp_listen_portaddr_hash hash table entries: 512 (order: 1, 8192)
[ 2.212539] TCP established hash table entries: 8192 (order: 4, 65536 bytes,)
[ 2.213720] TCP bind hash table entries: 8192 (order: 5, 131072 bytes, linea)
[ 2.214816] TCP: Hash tables configured (established 8192 bind 8192)
[ 2.219441] UDP hash table entries: 512 (order: 2, 16384 bytes, linear)
[ 2.220675] UDP-Lite hash table entries: 512 (order: 2, 16384 bytes, linear)
[ 2.229321] NET: Registered protocol family 1
[ 2.241478] RPC: Registered named UNIX socket transport module.
[ 2.242065] RPC: Registered udp transport module.
[ 2.242669] RPC: Registered tcp transport module.
[ 2.243011] RPC: Registered tcp NFSv4.1 backchannel transport module.
[ 2.251119] pci_bus 0000:00: resource 4 [io 0x0000-0x0cf7 window]
[ 2.251568] pci_bus 0000:00: resource 5 [io 0x0d00-0xffff window]
[ 2.251872] pci_bus 0000:00: resource 6 [mem 0x000a0000-0x000bffff window]
[ 2.252301] pci_bus 0000:00: resource 7 [mem 0x40000000-0xfebfffff window]
[ 2.252666] pci_bus 0000:00: resource 8 [mem 0x100000000-0x17fffffff window]
[ 2.255465] pci 0000:00:01.0: PIIX3: Enabling Passive Release
[ 2.256303] pci 0000:00:00.0: Limiting direct PCI/PCI transfers
[ 2.256882] pci 0000:00:01.0: Activating ISA DMA hang workarounds
[ 2.258406] pci 0000:00:02.0: Video device with shadowed ROM at [mem 0x000c0]
[ 2.259330] PCI: CLS 0 bytes, default 64
[ 2.278056] Trying to unpack rootfs image as initramfs...
[ 2.509808] Freeing initrd memory: 1740K
[ 2.522747] check: Scanning for low memory corruption every 60 seconds
[ 2.537281] Initialise system trusted keyrings
[ 2.544437] workingset: timestamp_bits=56 max_order=18 bucket_order=0
[ 2.594227] NFS: Registering the id_resolver key type
[ 2.597307] Key type id_resolver registered
[ 2.597701] Key type id_legacy registered
[ 2.671657] Key type asymmetric registered
[ 2.671806] cryptomgr_test (54) used greatest stack depth: 15072 bytes left
[ 2.672553] Asymmetric key parser 'x509' registered
[ 2.673881] Block layer SCSI generic (bsg) driver version 0.4 loaded (major )
[ 2.674960] io scheduler mq-deadline registered
[ 2.675889] io scheduler kyber registered
[ 2.692246] input: Power Button as /devices/LNXSYSTM:00/LNXPWRBN:00/input/in0
[ 2.708693] ACPI: Power Button [PWRF]
[ 2.727276] Serial: 8250/16550 driver, 4 ports, IRQ sharing enabled
[ 2.736950] 00:05: ttyS0 at I/O 0x3f8 (irq = 4, base_baud = 115200) is a 165A
[ 2.751977] Non-volatile memory driver v1.3
[ 2.753276] Linux agpgart interface v0.103
[ 2.851081] brd: module loaded
[ 2.914253] loop: module loaded
[ 2.951588] scsi host0: ata_piix
[ 2.960226] scsi host1: ata_piix
[ 2.962216] ata1: PATA max MWDMA2 cmd 0x1f0 ctl 0x3f6 bmdma 0xc040 irq 14
[ 2.962789] ata2: PATA max MWDMA2 cmd 0x170 ctl 0x376 bmdma 0xc048 irq 15
[ 2.973501] e100: Intel(R) PRO/100 Network Driver, 3.5.24-k2-NAPI
[ 2.973883] e100: Copyright(c) 1999-2006 Intel Corporation
[ 2.974132] e1000: Intel(R) PRO/1000 Network Driver - version 7.3.21-k8-NAPI
[ 2.975046] e1000: Copyright (c) 1999-2006 Intel Corporation.
[ 3.161113] ata2.00: ATAPI: QEMU DVD-ROM, 2.5+, max UDMA/100
[ 3.221074] scsi 1:0:0:0: CD-ROM QEMU QEMU DVD-ROM 2.5+ P5
[ 3.271352] sr 1:0:0:0: [sr0] scsi3-mmc drive: 4x/4x cd/rw xa/form2 tray
[ 3.272808] cdrom: Uniform CD-ROM driver Revision: 3.20
[ 3.290413] sr 1:0:0:0: Attached scsi generic sg0 type 5
[ 3.539550] PCI Interrupt Link [LNKC] enabled at IRQ 11
[ 3.860194] e1000 0000:00:03.0 eth0: (PCI:33MHz:32-bit) 52:54:00:12:34:56
[ 3.862348] e1000 0000:00:03.0 eth0: Intel(R) PRO/1000 Network Connection
[ 3.863976] e1000e: Intel(R) PRO/1000 Network Driver - 3.2.6-k
[ 3.864574] e1000e: Copyright(c) 1999 - 2015 Intel Corporation.
[ 3.865323] sky2: driver version 1.30
[ 3.869597] ehci_hcd: USB 2.0 'Enhanced' Host Controller (EHCI) Driver
[ 3.870110] ehci-pci: EHCI PCI platform driver
[ 3.871168] ohci_hcd: USB 1.1 'Open' Host Controller (OHCI) Driver
[ 3.871721] ohci-pci: OHCI PCI platform driver
[ 3.872637] uhci_hcd: USB Universal Host Controller Interface driver
[ 3.874563] usbcore: registered new interface driver usblp
[ 3.875425] usbcore: registered new interface driver usb-storage
[ 3.878895] i8042: PNP: PS/2 Controller [PNP0303:KBD,PNP0f13:MOU] at 0x60,0x2
[ 3.891254] serio: i8042 KBD port at 0x60,0x64 irq 1
[ 3.892637] serio: i8042 AUX port at 0x60,0x64 irq 12
[ 3.902024] rtc_cmos 00:00: RTC can wake from S4
[ 3.912568] input: AT Translated Set 2 keyboard as /devices/platform/i8042/s1
[ 3.915808] rtc_cmos 00:00: registered as rtc0
[ 3.918965] rtc_cmos 00:00: alarms up to one day, y3k, 114 bytes nvram, hpets
[ 3.925111] device-mapper: ioctl: 4.42.0-ioctl (2020-02-27) initialised: dm-m
[ 3.928075] hid: raw HID events driver (C) Jiri Kosina
[ 3.935452] usbcore: registered new interface driver usbhid
[ 3.935972] usbhid: USB HID core driver
[ 3.989865] Initializing XFRM netlink socket
[ 3.994262] NET: Registered protocol family 10
[ 4.027592] Segment Routing with IPv6
[ 4.040912] sit: IPv6, IPv4 and MPLS over IPv4 tunneling driver
[ 4.052200] NET: Registered protocol family 17
[ 4.054765] Key type dns_resolver registered
[ 4.062984] IPI shorthand broadcast: enabled
[ 4.066674] registered taskstats version 1
[ 4.066974] Loading compiled-in X.509 certificates
[ 4.087955] PM: Magic number: 4:67:272
[ 4.090591] printk: console [netcon0] enabled
[ 4.091224] netconsole: network logging started
[ 4.102859] cfg80211: Loading compiled-in X.509 certificates for regulatory e
[ 4.350010] modprobe (65) used greatest stack depth: 14648 bytes left
[ 4.361889] input: ImExPS/2 Generic Explorer Mouse as /devices/platform/i8043
[ 4.392264] cryptomgr_probe (67) used greatest stack depth: 14344 bytes left
[ 4.419563] cfg80211: Loaded X.509 cert 'sforshee: 00b28ddf47aef9cea7'
[ 4.422015] Unstable clock detected, switching default tracing clock to "glo"
[ 4.422015] If you want to keep using the local clock, then add:
[ 4.422015] "trace_clock=local"
[ 4.422015] on the kernel command line
[ 4.427733] platform regulatory.0: Direct firmware load for regulatory.db fa2
[ 4.428210] ALSA device list:
[ 4.428210] No soundcards found.
[ 4.428208] cfg80211: failed to load regulatory.db
[ 4.575676] Freeing unused kernel image (initmem) memory: 1172K
[ 4.580816] Write protecting the kernel read-only data: 20480k
[ 4.589473] Freeing unused kernel image (text/rodata gap) memory: 2040K
[ 4.592322] Freeing unused kernel image (rodata/data gap) memory: 728K
[ 4.593817] Run /init as init process
Boot took 4.81 seconds
/bin/sh: can't access tty; job control turned off
/ # ls
bin init proc sys
dev linuxrc root usr
etc mk_init_ram_fs.sh sbin
/ # cd bin/
/bin # ./hello
Boot init app...
Hello, World
/bin #
Eclipse + Qemu调试Linux kernel
Eclipse安装
下载Eclipse
首先,下载Eclipse 工具,由于调试的是C/C++程序,因此选择Eclipse IDE for C/C++ Developers,下载地址为: Eclipse IDE for C/C++ Developers
解压Eclipse
$ tar zxvf eclipse-cpp-2020-09-R-linux-gtk-x86_64.tar.gz
运行Eclipse
进入eclipse目录下,直接执行eclipse可执行文件即可。
在linux终端中运行Eclipse的方法如下
~/kernel_dev/eclipse-cpp-2020-09-R-linux-gtk-x86_64$ ./eclipse
Eclipse编译Qemu方法
下载Qemu
首先,下载Qemu源码, 下载的源码是qemu-5.1.0.tar.xz
解压Qemu源码
$ xz -d qemu-5.1.0.tar.xz
$ tar xvf qemu-5.1.0.tar
配置Qemu
进入Qemu-5.1.0源码目录下,执行如下命令进行配置
$ cd qemu-5.1.0
$ ./configure --prefix=~/opt/qemu --target-list="arm-softmmu i386-softmmu x86_64-softmmu arm-linux-user i386-linux-user x86_64-linux-user"
Eclipse导入Qemu源码
步骤如下:
步骤1:
打开Eclipse后,执行File -> import -> C/C++ -> Existing Code as Makefile Project. 点击Next
步骤2:
选择Qemu源码所在的目录,工具链选择Linux GCC. 如下图
点击 Finish
Eclipse编译Qemu
执行Project -> build project
可能会出现找不到autoreconf工具,那么安装如下package即可。
$ sudo apt-get install autoconf libtool
编译完成后,在Qemu源码目录下的arm-softmmu和x86_64-softmmu下生成对应的qemu可执行文件qemu-system-arm和qemu-system-x86_64
Eclipse + Qemu调试Linux Kernel
步骤1:
执行run -> Run Configurations, 弹出如下对话框, 选择 C/C++ Application, 找到qemu-system-arm所在目录,如下图所示
步骤2:
选择 Arguments 页, Program arguments 中填写如下参数,表示qemu-system-x86_64程序允许后面携带的参数
-smp 2 -m 1024M -kernel /home/wxer/kernel_dev/linux-5.9.12/build/arch/x86_64/boot/bzImage -initrd /home/wxer/kernel_dev/initramfs-busybox.cpio.gz
步骤3:
执行Run -> Run, 则Eclipse + Qemu运行Linux Kernel就成功了