首页 > 代码库 > x86_64的debian(wheezy)下使用qemu和busybox运行linux

x86_64的debian(wheezy)下使用qemu和busybox运行linux

1.编译kernel

进入源码根目录

make defconfig //这一步生成了默认的内核配置,请参考make help生成的信息。

make //这一步生成了bzImage

2.制作根文件系统

dd if=/dev/zero of=rootfs.img bs=1M count=10 //生成了rootfs.img,大小10M

mkfs.ext4 rootfs.img //在rootfs.img上制作ext4文件系统

mkdir rootfs

sudo mount -t ext4 -o loop rootfs.img rootfs

3.编译busybox

sudo apt-get install libncurses5-dev //make menuconfig需要这个库,否则编译报错

make menuconfig
(将busybox编译为静态连接方式)
- Busybox Settings
- Build options
- Build Busybox as a static binary
make
make install CONFIG_PREFIX=<path to rootfs>

sudo umount <path to rootfs>

4.安装qemu

sudo apt-get install qemu

5.运行qemu

qemu-system-x86_64 -kernel bzImage -hda rootfs.img -append "root=/dev/sda init=/bin/ash"

 

本文参考http://leave001.blog.163.com/blog/static/162691293201243110252209/