当前位置: 首页 > ai >正文

4.5 使用busybox制作根文件系统

4.1. 使用busybox制作文件系统

4.1.1 busybox源码下载:

下载地址:Index of /downloads

4.1.2.  busybox源码中修改Makefile

ARCH = arm
CROSS_COMPILE = /usr/local/arm/arm-2009q3/bin//arm-none-linux-gnueabi-

4.1.3. make menuconfig配置busybox

(1)静态方式编译busybox

Busybox Settings--->
    Build Options--->
        [*]Build BusyBox as a static binary(no shared libs)

(2)命令行vi风格

Busybox Library Tuning--->
    [*]vi-style line editing commands

(3)配置模块,在驱动中会使用到

Linux Module Utilities--->
    [ ]Simplified modutils
    [*]insmod
    [*]rmmod
    [*]lsmod
    [*]modprobe
    [*]depmod

(4)配置mdev,/dev中的驱动设备节点由mdev创建

Linux System Utilities--->[*]mdev
    [*]Support /etc/mdev.conf
    [*]Support subdirs/symlinks
    [*]Support regular expressions substitutions when renaming dev
    [*]Support command execution at device addition/removal
    [*]Support loading of firmwares

(5)配置安装目录

Busybox Settings--->

        Installation Options("make install" behavior)--->

                BusyBox installation prefix

(6)然后make编译,make install安装,rootfs文件夹就会有如下结果:

4.1.4. 添加/dev/inittab文件

Linux系统启动之后就会启动init进程,init进程会根据/etc/inittab这个文件来启动在不同的运行级别进程或操作。

inittab的格式: id:runlevels:action:process

 id:登记项标识符,用于惟一地标识/etc/inittab文件中的每一个登记项

runlevels:系统运行级别,指定登记项的运行级别,runlevels的级别有:

0让init关闭所有进程并终止系统
1单用户模式,单用户模式只能有系统管理员进入,runlevels的编号1也可以用S代替。
2允许系统进入多用户的模式,但并不支持文件共享
3最常用的运行模式,主要用来提供真正的多用户模式
4这个模式保留未用
5表示图形用户模式
6关闭所有运行的进程并重新启动系统

action:用于设置process的运行方式

respawninit应该监视这个进程,即使其结束后也应该被重新启动
waitinit应该运行这个进程一次,并等待其结束后再进行下一步操作
onceinit只运行一次该进程
boot系统启动时运行该进程
bootwait在系统启动时运行,init等待进程完成
ctrlaltdel当Ctrl+Alt+Del三个键同时按下时运行,把SIGINT信号发送给init
sysinit在运行boot或bootwait进程之前运行
powerfail当init收到SIGPWR信号时运行
powerokwait当收到SIGPWD信号且/etc/文件中的电源状态包含OK时运行
powerwait当收到SIGPWD信号,并且init等待进程结束时运行

process:表示所要执行的shell命令

inittap示例:

#first:run the system script file
::sysinit:/etc/init.d/rcS
#::askfirst:-/bin/sh
::sysinit:/bin/login
::ctrlaltdel:-/sbin/reboot
#umount all filesystem
::shutdown:/bin/umount -a -r
#restart init process
::restart:/sbin/init

4.1.5. /dev/init.d/rcS文件

#!/bin/sh#环境变量设置,操作系统执行程序默认到PATH指定的目录下寻找该程序
PATH=/sbin:/bin:/usr/sbin:/usr/binrunlevel=S        #单用户模式
prevlevel=Numask 022           #指定当前用户在创建文件时的默认权限export PATH runlevel prevlevel    #导出环境变量mount -a#调用mdev管理程序动态的创建插拔设备。kernel在每次设备出现变动时调用/sbin/mdev来处理对应的信息
echo /sbin/mdev > /proc/sys/kernel/hotplug
mdev -s/bin/hostname -F /etc/sysconfig/HOSTNAME    #设置主机名称ifconfig eth0 192.168.1.10    #设置ip地址

4.1.6. /etc/fstab

# /etc/fstab: static file system information.
#
# Use 'vol_id --uuid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
#       <file system>   <mount point>   <type>  <options>       <dump>  <pass>proc                    /proc                   proc    defaults        0               0sysfs                   /sys                    sysfs   defaults        0               0tmpfs                   /var                    tmpfs   defaults        0               0tmpfs                   /tmp                    tmpfs   defaults        0               0tmpfs                   /dev                    tmpfs   defaults        0               0

4.1.7. /etc/profile

用于命令行打印出用户名和主机名称

# Ash profile
# vim: syntax=sh# No core files by default
ulimit -S -c 0 > /dev/null 2>&1USER="`id -un`"
LOGNAME=$USER
PS1='[\u@\h \W]\# '
PATH=$PATHHOSTNAME=`/bin/hostname`export USER LOGNAME PS1 PATH

4.1.8. etc/passwd

root:x:0:0:root:/root:/bin/sh

4.1.9. /etc/shadow

root:xoQIkAeyYSSLI:14610:0:99999:7:::

4.1.10. 复制交叉编译工具链动态链接库文件到rootfs

4.2. 制作根文件系统镜像

dd if=/dev/zero of=rootfs.ext2 bs=1024 count=10240
losetup  /dev/loop1 rootfs.ext2
mke2fs -m 0 /dev/loop1 10240
mount -t ext2 /dev/loop1 ./rootfs/

将之前使用busybox制作的rootfs的文件复制过来,然后取消挂载,然后制作镜像

umount /dev/loop1
losetup -d /dev/loop1

inittap参考:Linux根文件系统:/etc/inittab文件分析 - LinFeng-Learning - 博客园

http://www.xdnf.cn/news/3454.html

相关文章:

  • Kotlin 基础
  • GitHub 趋势日报 (2025年05月01日)
  • Google机器学习系列 - 监督学习
  • Flutter BottomNavigationBar 详解
  • 综合案例:使用vuex对购物车的商品数量和价格等公共数据进行状态管理
  • ARM 指令集(ubuntu环境学习)第七章:系列总结与未来展望
  • 【愚公系列】《Manus极简入门》012-自我认知顾问:“内在探索向导”
  • 数据结构与算法:图论——最短路径
  • LearningFlow:大语言模型城市驾驶的自动化策略学习工作流程
  • Golang 身份证号码校验
  • bilibili如何获取视频的分节的目录
  • 【安装指南】Chat2DB-集成了AI功能的数据库管理工具
  • Shell 脚本基础
  • RabbitMQ的交换机
  • 解决The‘InnoDB’feature is disabled; you need MySQL built with ‘InnoDB’ to have it
  • ARM架构详解:定义、应用及特点
  • 计算机组成原理实验(6) 微程序控制单元实验
  • 大模型开发学习笔记
  • 提示词版本化管理:AI开发中被忽视的关键环节
  • 【Linux】基础指令(2)
  • 冯·诺依曼体系:现代计算机的底层逻辑与百年传承
  • C++ 与 Lua 联合编程
  • Python-pandas-操作Excel文件(读取数据/写入数据)及Excel表格列名操作详细分享
  • 单链表操作(single list)
  • Python高级爬虫之JS逆向+安卓逆向1.7节: 面向对象
  • NY204美光闪存MT29F8T08EQLCHL5-QA:C
  • python设置word字体的方法
  • GBDT 基本概述
  • JVM——JVM 是如何执行方法调用的?
  • 华为云Astro轻应用利用自定义连接器调用第三方接口实际操作