使用busybox制作rootfs
Prerequisites
-
Download busybox and linux kernel source code.
-
Create some necessary directories.
1
2
3mkdir initrd
cd initrd
mkdir {proc,sys,etc} -
Create
initfile.1
2
3
4
5
mount -t proc proc /proc
mount -t sysfs sysfs /sys
mknod /dev/ttyS0 c 4 64
setsid sh -c 'exec sh </dev/ttyS0 >/dev/ttyS0 2>&1'
Don’t forget to make
initexecutable
Compile linux kernel
Here, I use default configuraton file, you can tweak it with gui through make menuconfig or manually configure .config file. you can get more help from make help.
1 | make defconfig |
Compile busybox
1 | make defconfig |
Make virtual file system
1 | find . | cpio -o -H newc | gzip -9 > initramfs.img |
or
1 | find . -print0 | cpio -0 -o -H newc | gzip -9 > initramfs.img |
Boot linux with qemu
1 | qemu-system-x86_64 \ |
Alternatively you can pack rootfs into a disk
1
2
3
4
5
6
7
8
9 dd if=/dev/zero of=rootfs.img bs=1M count=10
mkfs.ext4 rootfs.img
mkdir rootfs
sudo mount rootfs.img rootfs
# rootfs directory
mkdir {proc,sys}
# busybox directory
make install CONFIG_PREFIX=../rootfs
sudo umount rootfsThen boot with
qemu
1
2
3
4
5 qemu-system-x86_64 \
-kernel kernel/bzImage \
-hda rootfs.img \
-append "root=/dev/sda console=ttyS0" \
-nographic
Tips and Tricks
-
method to quit qemu
-
Ctrl + AthenX -
Ctrl + AthenCthen typequit
-
References:
[1] Build a minimal Linux with only Busybox in 1 hour
[2] How to build bare minimal Linux system | Busybox, RAMfs ( initrd ) & system boot with Linux Kernel
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 SY's Webpage!

