Skip to content

Commit 282dcd9

Browse files
committed
-
1 parent a3a209e commit 282dcd9

4 files changed

Lines changed: 100 additions & 4 deletions

_posts/2024/2024-05-27-incident-analysis-of-decentralized-finance.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ date: 2024-05-27 20:55:00 +0800
66
categories: [blockchain]
77
tags: [blockchain]
88
math: false
9-
pin: true
9+
pin: false
1010
---
1111

1212
The original paper is included in IEEE ICBC 2024 proceeding, view or cite it: [https://ieeexplore.ieee.org/document/10634335](https://ieeexplore.ieee.org/document/10634335).

_posts/2024/2024-07-27-key-value-storage.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ date: 2024-07-27 20:55:00 +0800
66
categories: [blog, c]
77
tags: [c, linux]
88
math: true
9-
pin: true
9+
pin: false
1010
---
1111

1212
Key Value Storage is an assignment of *CSIE3006 - Operating System* by [Hung-Chang Hsiao](https://www.csie.ncku.edu.tw/en/members/27) at National Cheng Kung University. In this assignment, I made a single-threaded key value storage in C++. In this assignment, I referenced famous key-value storage projects such as [LevelDB](https://en.wikipedia.org/wiki/LevelDB) and other search and storage algorithms, and utilized [Bloom filter](https://en.wikipedia.org/wiki/Bloom_filter), [skip list](https://en.wikipedia.org/wiki/Skip_list), [sorted string tables (SSTable)](https://www.scylladb.com/glossary/sstable/), and [binary search](https://en.wikipedia.org/wiki/Binary_search) to enhance the speed of database searches. As a result, I achieved the second-highest grade in this assignment.

_posts/2025/2025-07-09-boot-tiny-linux.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: Booting a Minimal Linux Kernel on Ubuntu 24
2+
title: Booting a Minimal Linux Kernel on QEMU Ubuntu 24
33
image: /assets/img/default-banner.jpg
44
author: jack
55
date: 2025-07-09 20:55:00 +0800
@@ -9,7 +9,7 @@ math: false
99
pin: false
1010
---
1111

12-
This post documents my process of manually downloading, configuring, and compiling Linux kernel (v6.12) on an Ubuntu 24.04 machine.
12+
This post documents my steps of manually downloading, configuring, and compiling Linux kernel (v6.12) on an Ubuntu 24.04 machine.
1313

1414
## Installing Required Tools
1515

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
---
2+
title: Booting Linux Kernel with a custom init program on QEMU Ubuntu 24
3+
image: /assets/img/default-banner.jpg
4+
author: jack
5+
date: 2025-07-13 20:55:00 +0800
6+
categories: [blog, linux]
7+
tags: [linux]
8+
math: false
9+
pin: false
10+
---
11+
12+
This post documents how I wrote and compiled a minimal `init` program in C, built a simple `initramfs`, and successfully booted it using a custom Linux kernel v6.12 on Ubuntu 24.04 via QEMU. Before you begin, make sure you’ve already built your own Linux kernel as shown in [this post](/posts/boot-tiiny-linux).
13+
14+
## Create a Minimal C Project
15+
16+
```bash
17+
mkdir -p my-init/bin
18+
cd my-init
19+
touch init.c
20+
```
21+
22+
Edit `init.c`:
23+
24+
```c
25+
// init.c
26+
#include <stdio.h>
27+
#include <unistd.h>
28+
29+
int main() {
30+
while (1) {
31+
printf("$ ");
32+
fflush(stdout);
33+
34+
char input[256];
35+
if (fgets(input, sizeof(input), stdin) == NULL) break;
36+
37+
printf("Sorry, I don't know how to do that.\n");
38+
}
39+
return 0;
40+
}
41+
```
42+
43+
Now compile this as a statically linked binary. This ensures the kernel doesn’t rely on any external shared libraries or runtime:
44+
45+
```bash
46+
gcc init.c -static -o bin/init
47+
```
48+
49+
## Build an initramfs Image
50+
51+
Before the kernel can execute the `init` program, we must place it inside an initial RAM-based file system (initramfs). The kernel will extract this archive into memory at boot and use it as the root filesystem.
52+
53+
```bash
54+
cd bin
55+
chmod +x init
56+
cd ..
57+
find . -print0 | cpio --null --create --verbose --format=newc | gzip -9 > ../initrd
58+
```
59+
60+
This generates an `initrd` file — a gzipped `cpio` archive — which contains your custom `init` binary.
61+
62+
## Enable Kernel Features
63+
64+
Make sure your kernel supports `initramfs`, ELF binaries, and 64-bit execution. Run:
65+
66+
```bash
67+
make menuconfig
68+
```
69+
70+
Then enable these options:
71+
72+
1. General setup ---> Initial RAM filesystem and RAM disk (initramfs/initrd) support
73+
2. Executable file formats ---> Kernel support for ELF binaries
74+
3. Processor type and features ---> 64-bit kernel
75+
76+
Recompile the kernel afterward if needed.
77+
78+
## Boot with QEMU
79+
80+
Now boot your kernel and initramfs using QEMU:
81+
82+
```bash
83+
qemu-system-x86_64 -kernel arch/x86/boot/bzImage -initrd initrd -nographic -append "console=ttyS0"
84+
```
85+
86+
Expected output:
87+
88+
```text
89+
$ Sorry, I don't know how to do that.
90+
$ Sorry, I don't know how to do that.
91+
...
92+
```
93+
94+
Each time you type a line and press Enter, it responds with a fixed message — just like the minimal shell we designed!
95+
96+
![](https://raw.githubusercontent.com/blueskyson/image-host/master/2025/tiny-linux-init-1.png)

0 commit comments

Comments
 (0)