根文件系统制作并启动 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
~ # 
相关推荐
8***848214 小时前
如何在Linux中找到MySQL的安装目录
linux·运维·mysql
9***J62814 小时前
Linux下PostgreSQL-12.0安装部署详细步骤
linux·运维·postgresql
W***832015 小时前
如何在 Ubuntu 22.04 上安装 MySQL
linux·mysql·ubuntu
凌寒1116 小时前
Linux(Debain)安装Redis、数据迁移
linux·运维·服务器·redis
7***q60816 小时前
在linux(Centos)中Mysql的端口修改保姆级教程
linux·mysql·centos
用户4760220227817 小时前
机器配置免密切root
linux
zzzsde17 小时前
【Linux】基础开发工具(2):vim补充说明&&gcc/g++编译器
linux·运维·服务器
q***656918 小时前
使用Canal将MySQL数据同步到ES(Linux)
linux·mysql·elasticsearch
2301_8075832318 小时前
了解python,并编写第一个程序,常见的bug
linux·python
杨德杰18 小时前
Ubuntu设置VNC远程桌面
linux·运维·ubuntu