根文件系统制作并启动 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
~ # 
相关推荐
TDD_06284 小时前
【运维】Centos硬盘满导致开机时处于加载状态无法开机解决办法
linux·运维·经验分享·centos
x66ccff4 小时前
vLLM 启动 GGUF 模型踩坑记:从报错到 100% GPU 占用的原因解析
linux
William.csj5 小时前
Linux——开发板显示器显示不出来,vscode远程登录不进去,内存满了的解决办法
linux·vscode
KeithTsui5 小时前
GCC RISCV 后端 -- 控制流(Control Flow)的一些理解
linux·c语言·开发语言·c++·算法
森叶5 小时前
linux如何与windows进行共享文件夹开发,不用来回用git进行拉来拉去,这个对于swoole开发者来说特别重要
linux·git·swoole
liulilittle5 小时前
Linux 高级路由策略控制配置:两个不同路由子网间通信
linux·网络·智能路由器
学习至死qaq6 小时前
windows字体在linux访问异常
linux·运维·服务器
在野靡生.6 小时前
Ansible(4)—— Playbook
linux·运维·ansible
Linux技术芯6 小时前
Linux内核内存管理 ARM32内核内存布局的详细解析和案例分析
linux
烨鹰6 小时前
戴尔电脑安装Ubuntu双系统
linux·运维·ubuntu