0%

基于 busybox 打包、制作根文件系统并通过 qemu 启动内核和文件系统

基于 busybox 打包、制作根文件系统并通过 qemu 启动内核和文件系统

1 busybox 打包、制作根文件系统

1.1 制作空镜像文件

1
$ dd if=/dev/zero of=./rootfs.ext3 bs=1M count=32 

1.2 将此镜像文件格式化为ext3格式

1
$ mkfs.ext3 rootfs.ext3 

1.3 挂载镜像文件,将根文件系统复制到挂载目录

1
2
3
$ mkdir fs
$ mount -o loop rootfs.ext3 ./fs
$ cp -rf ./_install/* ./fs

1.4 卸载镜像文件

1
$ umount ./fs 

1.5 打包 gzip 包

1
$ gzip --best -c rootfs.ext3 > rootfs.img.gz 

2 通过 qemu 启动内核和文件系统

2.1 安装 qemu

1
2
$ sudo apt install qemu
$ sudo apt install qemu-system-x86

2.2 启动内核和文件系统

1
2
3
4
5
$ qemu-system-x86_64 \
-kernel ./linux-4.9.229/arch/x86_64/boot/bzImage \
-initrd ./busybox-1.30.0/rootfs.img.gz \
-append "root=/dev/ram init=/linuxrc" \
-serial file:output.txt

img

2.3 执行一些命令作为测试,

img