根文件系统制作并启动 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
~ # 
相关推荐
DD_陈东东10 分钟前
gdbus 常用数据结构与库函数
linux
DIY机器人工房1 小时前
代码详细注释:ARM-Linux字符设备驱动开发案例:LCD汉字输出改进建议开发板断电重启还能显示汉字,显示汉字位置自定义
linux·嵌入式·文件io·diy机器人工房
得物技术2 小时前
eBPF 助力 NAS 分钟级别 Pod 实例溯源|得物技术
linux
Rudon滨海渔村2 小时前
解决阿里云ubuntu内存溢出导致vps死机无法访问 - 永久性增加ubuntu的swap空间 - 阿里云Linux实例内存溢出(OOM)问题修复方案
linux·运维·ubuntu
A-刘晨阳2 小时前
【Linux】Redis 6.2.6 的二进制部署【适用于多版本】
linux·运维·redis
cat_with_cat3 小时前
Linux网络:UDP socket创建流程与简单通信
linux·网络·udp
2401_861615283 小时前
跨平台的ARM 和 x86 Docker 镜像:汇编语言实验环境搭建
linux·汇编·ubuntu·docker·容器
hz355723 小时前
IO多路复用--epoll
linux
努力学习的小廉3 小时前
深入了解linux系统—— System V之消息队列和信号量
android·linux·开发语言
华无丽言3 小时前
如何简单实现发版不影响客户使用?nginx负载
linux·nginx