根文件系统制作并启动 Linux

根文件系统制作并启动 Linux

busybox 下载链接:https://busybox.net/

下载

shell 复制代码
wget https://busybox.net/downloads/busybox-1.36.1.tar.bz2

解压

shell 复制代码
 tar -vxf busybox-1.36.1.tar.bz2 

并进入其根目录

shell 复制代码
export ARCH=arm
export CROSS_COMPILE=arm-none-linux-gnueabihf-
make defconfig
make menuconfig
#   勾选  Settings-> [*] Build static binary (no shared libs)
make -j6
make install

上述步骤执行完后在 busybox 根目录生成了一个 _install 文件夹。

随便找一个目录,来创建 linux 的根文件系统

shell 复制代码
# 随便找一个目录,创建 linux 的根文件系统
cd rootfs

# 将 _install 的所有文件拷贝到 rootfs 文件夹中
cp -r /home/tyustli/code/open_source/busybox/busybox-1.36.1/_install/* ./

# 复制库文件
mkdir lib
cp -r /home/tyustli/cross_tool/gcc-arm-10.3-2021.07-x86_64-arm-none-linux-gnueabihf/lib/* lib/

# 创建设备节点
mkdir dev
cd dev
# 创建多个 tty 设备,注意子设备号不要重复
sudo mknod -m 666 tty1 c 4 1
sudo mknod -m 666 tty2 c 4 2
sudo mknod -m 666 tty3 c 4 3
sudo mknod -m 666 tty4 c 4 4
sudo mknod -m 666 tty5 c 4 5
sudo mknod -m 666 tty6 c 4 6
# 创建一个控制台节点
sudo mknod -m 666 console c 5 1
# 创建一个空节点
sudo mknod -m 666 null c 1 3

cd ../../
# 生成虚拟 SD 卡系统镜像
sudo dd if=/dev/zero of=rootfs.ext3 bs=1M count=32
# 格式化镜像
sudo mkfs.ext3 rootfs.ext3

#将根文件系统中的文件复制到镜像中
sudo mkdir tmpfs # 创建一个临时目录
sudo mount -t ext3 rootfs.ext3 tmpfs/ -o loop # 将 rootfs.ext3 镜像挂载到 tmpfs 目录下
sudo cp -r rootfs/*  tmpfs/ # 将  rootfs 目录下所有文件拷贝到 tmpfs 目录下,即拷贝的到 rootfs.ext3 镜像中
sudo umount tmpfs # 将临时挂载的文件系统卸载掉

上面的步骤执行完后,rootfs.ext3 镜像中就包含了 rootfs 目录下的所有内容,此时linux的根文件系统就已经制作完成,下一步就是使用这个 rootfs.ext3 镜像来启动 linux 内核

linux 启动文件

shell 复制代码
sudo qemu-system-arm -M vexpress-a9 -m 512M -kernel arch/arm/boot/zImage -dtb arch/arm/boot/dts/arm/vexpress-v2p-ca9.dtb -nographic \
-append "root=/dev/mmcblk0 rw console=ttyAMA0" -sd /home/tyustli/code/open_source/busybox/rootfs.ext3

这里比之前多指定了一个 sd 镜像。

linux 启动日志

shell 复制代码
 #0: ARM AC'97 Interface PL041 rev0 at 0x10004000, irq 37
input: ImExPS/2 Generic Explorer Mouse as /devices/platform/bus@40000000/bus@40000000:motherboard-bus@40000000/bus@40000000:motherboard-bus@40000000:iofpga@7,00000000/10007000.kmi/serio1/input/input2
drm-clcd-pl111 10020000.clcd: DVI muxed to daughterboard 1 (core tile) CLCD
drm-clcd-pl111 10020000.clcd: initializing Versatile Express PL111
EXT4-fs (mmcblk0): mounting ext3 file system using the ext4 subsystem
EXT4-fs (mmcblk0): mounted filesystem b28f1697-44d3-4ac5-879c-fffa4116c9cc r/w with ordered data mode. Quota mode: disabled.
VFS: Mounted root (ext3 filesystem) on device 179:0.
Freeing unused kernel image (initmem) memory: 1024K
Run /sbin/init as init process
random: crng init done
can't run '/etc/init.d/rcS': No such file or directory

Please press Enter to activate this console. 
~ # drm-clcd-pl111 10020000.clcd: DVI muxed to daughterboard 1 (core tile) CLCD
drm-clcd-pl111 10020000.clcd: initializing Versatile Express PL111
amba 1000f000.wdt: deferred probe pending
amba 10020000.clcd: deferred probe pending
amba 100e0000.memory-controller: deferred probe pending
amba 100e1000.memory-controller: deferred probe pending
amba 100e5000.watchdog: deferred probe pending
i2c 0-0039: deferred probe pending

~ # ls
bin         lib         lost+found  usr
dev         linuxrc     sbin
~ # 
相关推荐
虾..1 天前
Linux 软硬链接和动静态库
linux·运维·服务器
Evan芙1 天前
Linux常见的日志服务管理的常见日志服务
linux·运维·服务器
hkhkhkhkh1231 天前
Linux设备节点基础知识
linux·服务器·驱动开发
HZero.chen1 天前
Linux字符串处理
linux·string
张童瑶1 天前
Linux SSH隧道代理转发及多层转发
linux·运维·ssh
汪汪队立大功1231 天前
什么是SELinux
linux
石小千1 天前
Linux安装OpenProject
linux·运维
柏木乃一1 天前
进程(2)进程概念与基本操作
linux·服务器·开发语言·性能优化·shell·进程
Lime-30901 天前
制作Ubuntu 24.04-GPU服务器测试系统盘
linux·运维·ubuntu
百年渔翁_肯肯1 天前
Linux 与 Unix 的核心区别(清晰对比版)
linux·运维·unix