惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

C
Check Point Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
博客园 - 聂微东
月光博客
月光博客
博客园 - 司徒正美
爱范儿
爱范儿
aimingoo的专栏
aimingoo的专栏
量子位
Recent Announcements
Recent Announcements
V
V2EX
P
Proofpoint News Feed
小众软件
小众软件
云风的 BLOG
云风的 BLOG
腾讯CDC
宝玉的分享
宝玉的分享
Microsoft Azure Blog
Microsoft Azure Blog
大猫的无限游戏
大猫的无限游戏
Vercel News
Vercel News
The GitHub Blog
The GitHub Blog
A
About on SuperTechFans
B
Blog
博客园_首页
GbyAI
GbyAI
博客园 - Franky

博客园 - 蜡笔小旧

elon musk's 5 steps work method sqlite rollback journal vs. wal cmd/powershell frozen issue MTU issue in Ubuntu 22.04 Cursor ai network issue workaround in Ubuntu 22.04 android app network monitor with mitmweb zsh vs. bash 在gitlab中使用fastlane编译ios 记一次gitlab artifact问题 Cursor in Ubuntu 22.04 Manual install .NET SDK 9 on ubuntu with .NET SDK 8 记一次阿里云主机被挖矿 防御性编程 hyper-v ubuntu 22.04 Configure oh my zsh Setting up development environment with Ubuntu 22.04 WSL linux reset password Windows 10 access ext4 IP Offline install net driver in ubuntu
linux kernel complie + QEMU
蜡笔小旧 · 2026-08-29 · via 博客园 - 蜡笔小旧

2026-08-29 22:06  蜡笔小旧  阅读(2)  评论()    收藏  举报

今天尝试了下编译linux kernel比想象中的简单很多。

  第一个花时间的在了下载源码,后面果断放弃git clone用浏览器走dl下载。

      第二个花时间的点是路径问题 `bin/busybox --install -s .` 始终都是绝对路径,最后改成了简单的ln方式。

sudo apt update
sudo apt install \
    build-essential \
    bc \
    bison \
    flex \
    libssl-dev \
    libelf-dev \
    libncurses-dev \
    qemu-system-x86 \
    cpio \
    busybox-static

#############################################################

# i use web browser instead of git 
git clone --depth=1 --branch v6.12 https://github.com/torvalds/linux.git
cd linux
mv linux kernel


#############################################################

# generate .config file
make defconfig

# start complie then generated a file `bzImage`
make -j$(nproc)

# Kernel: arch/x86/boot/bzImage is ready  (#1)

#############################################################
mkdir rootfs
cd ./rootfs

mkdir -p \
    bin \
    sbin \
    etc \
    proc \
    sys \
    dev \
    tmp

cp /usr/bin/busybox bin/

cd ..
cat > rootfs/init <<'EOF'
#!/bin/sh

# option 2
#mount -t devtmpfs none /dev
#mount -t proc none /proc
#mount -t sysfs none /sys

echo
echo "================================"
echo " Hello from my Linux kernel!"
echo "================================"
echo

exec /bin/sh

# option 2
# exec setsid cttyhack /bin/sh

EOF

chmod +x rootfs/init
ln -s busybox sh
ln -s busybox ls
ln -s busybox cat
ln -s busybox echo
ln -s busybox mount
ln -s busybox ps
# Create initramfs
cd rootfs
find . -print0 | cpio --null -ov --format=newc | gzip -9 > ../rootfs.cpio.gz
cd ..

# directory
# kernel/
#    arch/x86/boot/bzImage
#
# rootfs/
#    init
#    bin/
#    proc/
#    sys/
#    ...

# rootfs.cpio.gz
qemu-system-x86_64 
   -kernel ./kernel/arch/x86/boot/bzImage
   -initrd ./rootfs.cpio.gz 
   -append "console=ttyS0" 
   -nographic