Skip to content

Commit

Permalink
新增了笔记。隐藏了 template
Browse files Browse the repository at this point in the history
  • Loading branch information
Chiichen committed Oct 28, 2023
1 parent 40eb525 commit 2cde2d6
Show file tree
Hide file tree
Showing 10 changed files with 140 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/.vuepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import theme from "./theme.js";

export default defineUserConfig({
base: "/",

port: 10086,
locales: {
"/": {
lang: "en-US",
Expand Down
2 changes: 2 additions & 0 deletions src/posts/template.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@ sticky: true
star: false
footer:
copyright: Copyright with marking the source
article: false
index: false
---
128 changes: 128 additions & 0 deletions src/zh/posts/Linux 内核/vscode+qemu开发Linux内核.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
---
title: vscode+qemu开发Linux内核

# cover: /assets/images/cover1.jpg

icon: page
order: 1
author: ChiChen
date: 2023-10-28
category:
- 笔记
- Linux 内核
tag:

- Linux 内核
- 开发环境
sticky: true
star: true
footer:
copyright: 转载请注明出处

---

参考于[QEMU调试Linux内核环境搭建](http://kerneltravel.net/blog/2021/debug_kernel_szp/)

## 获取Linux源码

-

## 编译Linux内核

```bash
cd /linux
export ARCH=x86
make CC=clang x86_64_defconfig
```

### config可选项

```bash

# 可选,可以开启调试选项
make menuconfig
# in menu
Kernel hacking --->
[*] Kernel debugging
Compile-time checks and compiler options --->
[*] Compile the kernel with debug info
[*] Provide GDB scripts for kernel debuggin

# 关闭内核随机地址
Processor type and features ---->
[] Randomize the address of the kernel image (KASLR)
```

### 编译

```bash
#编译,并用来获取 compile_commands.json 文件
bear make CC=clang -j 32
# 结束输出Kernel: arch/x86/boot/bzImage is ready
```

### clangd配置

```bash
--compile-commands-dir=${workspaceFolder}
--background-index
--completion-style=detailed
--header-insertion=never
-log=info
-pretty

```

## 配置BusyBox

启动内核还需要一个具有根文件系统的磁盘镜像文件,根文件系统中提供可供交互的shell程序以及一些常用工具命令。
我们借助busybox工具来制作根文件系统。

```bash
# 下载busybox源码
wget https://busybox.net/downloads/busybox-1.32.1.tar.bz2
tar -xvf busybox-1.32.1.tar.bz2
cd busybox-1.32.1
make menuconfig
# 配置为静态编译
# Settings --->
# [*] Build BusyBox as a static binary (no shared libs)
```

## 制作 rootfs

```bash
szp@r420-PowerEdge-R420:~/busybox-1.32.0$ dd if=/dev/zero of=rootfs.img bs=1M count=10

szp@r420-PowerEdge-R420:~/busybox-1.32.0$ mkfs.ext4 rootfs.img

szp@r420-PowerEdge-R420:~/busybox-1.32.0$ mkdir fs

szp@r420-PowerEdge-R420:~/busybox-1.32.0$ sudo mount -t ext4 -o loop rootfs.img ./fs

szp@r420-PowerEdge-R420:~/busybox-1.32.0$ sudo make install CONFIG_PREFIX=./fs

szp@r420-PowerEdge-R420:~/busybox-1.32.0/fs$ sudo mkdir proc dev etc home mnt

szp@r420-PowerEdge-R420:~/busybox-1.32.0/fs$ sudo cp -r ../examples/bootfloppy/etc/* etc/

szp@r420-PowerEdge-R420:~/busybox-1.32.0$ sudo chmod -R 777 fs/

# 写在 rootfs.img
szp@r420-PowerEdge-R420:~/busybox-1.32.0$ sudo umount fs
```

## 启动qemu

这里用的是我的配置,就是要有这个目录结构,然后cd进linux源码文件夹执行下面的命令即可

```bash
/.
/..
/linux
/busybox-1.32.1
```

```bash
qemu-system-x86_64 -kernel ./arch/x86_64/boot/bzImage -hda ../busybox-1.32.1/rootfs.img -append "root=/dev/sda console=ttyS0" -nographic
```
3 changes: 3 additions & 0 deletions src/zh/posts/template.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,8 @@ sticky: false
# this page will appear in starred articles
star: false
footer:
isOriginal: true
copyright: 转载请注明出处
article: false
index: false
---
1 change: 1 addition & 0 deletions src/zh/posts/编译原理/Chapter0 前言.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ sticky: true
star: false
footer:
copyright: 转载请注明出处
isOriginal: true
---

## 前言
Expand Down
1 change: 1 addition & 0 deletions src/zh/posts/编译原理/Chapter1 编译器组成.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ sticky: true
star: false
footer:
copyright: 转载请注明出处
isOriginal: true
---

## Chapter1 编译器组成
Expand Down
1 change: 1 addition & 0 deletions src/zh/posts/编译原理/Chapter2 词法分析.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ sticky: true
star: false
footer:
copyright: 转载请注明出处
isOriginal: true
---

# Chapter2 词法分析
Expand Down
1 change: 1 addition & 0 deletions src/zh/posts/编译原理/Chapter3 语法分析.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ sticky: true
star: false
footer:
copyright: 转载请注明出处
isOriginal: true
---

# Chapter3 语法分析
Expand Down
1 change: 1 addition & 0 deletions src/zh/posts/编译原理/Chapter4 语义分析.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ sticky: true
star: false
footer:
copyright: 转载请注明出处
isOriginal: true
---

# Chapter4 语义分析
Expand Down
1 change: 1 addition & 0 deletions src/zh/posts/编译原理/Chapter5 代码生成.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ sticky: true
star: false
footer:
copyright: 转载请注明出处
isOriginal: true
---

# Chapter5 代码生成
Expand Down

0 comments on commit 2cde2d6

Please sign in to comment.