尝试用qemu启动busybox以及内核。方便学习内核的代码和内部的流程。
主机x86_64
linux-3.13.1.tar.gz
qemu-2.8.0.tar.xz
busybox-1.25.0.tar.bz2
1编译qemu
cd qemu-2.8.0
./configure
make -j4
sudo make install
2 编译linuxkernel
make defconfig
make
得到bzimage
3编译busybox
make menuconfig
选择静态编译
Busyboxsetting->build options->Build Busybox as a static binary
保存
make -j4
4 构建根文件系统
dd if=/dev/zero of=rootfs.img BS=1M count=10
mkdir tempmount
mkfs.ext4 -F -L linuxroot rootfs.img
sudo mount -o loop rootfs.img tempmount
进入Busybox的编译目录
sudo make install CONFIG_PREFIX=/path/to/tempmount
sudo umount tempmount
5启动整个busybox
qemu-system-x86_64 -kernel bzImage -hda rootfs.img -append "root=/dev/sda rootfstype=ext4 init=/bin/ash"
为了能够在文件或者主机终端中看到qemu的输出。
1 qemu执行命令中需要添加
-serial stdio 或者-serial file:/home/a.txt 将qemu串口输出到 本地终端或者文件。
2内核命令行中需要添加
console=tty console=ttyAMA0 console=ttyS0
qemu-system-x86_64 -kernel bzImage -hda rootfs.img -serial stdio -append "root=/dev/sda console=tty console=ttyAMA0 console=ttyS0 rootfstype=ext4 init=/bin/ash"