日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > linux >内容正文

linux

构建linux根文件系统

發布時間:2025/3/15 linux 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 构建linux根文件系统 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
  • 內核 啟動后回去調用第一個程序init、給用戶提供操作界面的shell程序 、應用程序所依賴的庫文件。這些必須的基本的文件合起來稱為根文件系統,他們存放在一個分區中,Linux系統啟動之后首先掛載這個分區,稱為掛載根文件系統,其他的分區上的所有的目錄、文件的集合,也稱之為文件系統。
  • linux系統中沒有C、D、E等盤的概念,linux中以樹狀管理所有的文件目錄,其他的分區掛載在這個目錄上,這個目錄被稱之為掛載點或者安裝點,然后可以通過這個分區來訪問這個分區上的文件了,比如根文件系統被掛載在根目錄’/‘上之后,就可以在’/'看到根目錄下的文件了\
  • 在一個分區上存儲文件時需要遵循一定的格式,這種格式稱之為文件系統,比如fat16、ntfs、wxt2、ext3、jffs2、yaffs2等,除了這幾個擁有實實在在的存儲分區的文件系統之外,linux還有幾個虛擬的文件系統類型,比如proc、yaffs等,他們的文件并不存在實際的設備上,而是訪問他們時有linux內核臨時的生成。
  • /etc下的文件
    export 用來配置NFS文件系統
    fstab 用來指明執行"mount -a"時的需要掛載的文件系統
    mtab 用來顯示已經加載的文件系統,通常是/proc/mounts的鏈接文件
    ftpusers 啟動FTP服務時,用來配置用戶的訪問權限
    group 用戶的組文件
    inittab init進程的配置文件
    ld.so.conf 其它共享庫的路徑
    passed 密碼文件
  • /proc目錄
    proc可以為空,linux內核創建的臨時文件,proc文件系統,是一個虛擬的文件系統,他沒有實際的存儲設備,里面的目錄、文件都是內核臨時生成的,用來表示系統的運行狀態,也可已操作其中的文件控制系統。
    系統啟動之后使用以下命令掛載proc文件系統(常在/etc/fstab進行設置以自動掛載)
#mount -t proc none /proc
  • /tmp用于存放臨時文件,減少系統對flash的操作,所以/tmp目錄必須保證可以訪問到。可使用以下命令記性==進行掛載
# mount -t tmpfs none /tmp

linux文件類型

  • 普通文件
  • 目錄文件
  • 字符設備文件
  • 塊設備文件
  • FIFO
  • 套接字
  • 連接文件

啟動第一個程序init

文件在linux源碼的init/main.c中

/* This is a non __init function. Force it to be noinline otherwise gcc* makes it inline to init() and it becomes part of init.text section*///若果使用的是 __attribute__(noinline)的話代表的是,返回的出錯將被當成警告處理static int noinline init_post(void) {free_initmem();unlock_kernel();mark_rodata_ro();system_state = SYSTEM_RUNNING;numa_default_policy();if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)printk(KERN_WARNING "Warning: unable to open an initial console.\n");(void) sys_dup(0);(void) sys_dup(0); //因為是linux內核剛剛啟動所以打開的文件描述符是0、1、2,并且使用sys_dup將0、1、2都連接到打開的額console上 //> 之后就能實現將標準輸入標準輸出和標注錯誤輸出重定向到console上。if (ramdisk_execute_command) {run_init_process(ramdisk_execute_command);printk(KERN_WARNING "Failed to execute %s\n",ramdisk_execute_command);}/** We try each of these until one succeeds.** The Bourne shell can be used instead of init if we are* trying to recover a really broken machine.*/// execute_command ==> init = /linuxrc//因為這種函數都是死循環的樣式進行的,所以無論是 /linuxrc還是// /sbin/init 等程序都是只能執行一個if (execute_command) {run_init_process(execute_command);printk(KERN_WARNING "Failed to execute %s. Attempting ""defaults...\n", execute_command);}run_init_process("/sbin/init");run_init_process("/etc/init");run_init_process("/bin/init");run_init_process("/bin/sh");panic("No init found. Try passing init= option to kernel."); }

busybox的init程序對應代碼中的init/init.c文件
執行的過程如下:

busybox的inittab配置文件


上圖中的-/bin/sh中的 '-'代表程序是交互的方式啟動,這時就會彈出交互式shell窗口,嵌入式設備中是使用串口

下面是我的開發板上的inittab配置文件

# /etc/inittab init(8) configuration for BusyBox # # Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org> # # # Note, BusyBox init doesn't support runlevels. The runlevels field is # completely ignored by BusyBox init. If you want runlevels, use sysvinit. # # # Format for each entry: <id>:<runlevels>:<action>:<process> # # <id>: WARNING: This field has a non-traditional meaning for BusyBox init! # # The id field is used by BusyBox init to specify the controlling tty for # the specified process to run on. The contents of this field are # appended to "/dev/" and used as-is. There is no need for this field to # be unique, although if it isn't you may have strange results. If this # field is left blank, it is completely ignored. Also note that if # BusyBox detects that a serial console is in use, then all entries # containing non-empty id fields will be ignored. BusyBox init does # nothing with utmp. We don't need no stinkin' utmp. # # <runlevels>: The runlevels field is completely ignored. # # <action>: Valid actions include: sysinit, respawn, askfirst, wait, once, # restart, ctrlaltdel, and shutdown. # # Note: askfirst acts just like respawn, but before running the specified # process it displays the line "Please press Enter to activate this # console." and then waits for the user to press enter before starting # the specified process. # # Note: unrecognised actions (like initdefault) will cause init to emit # an error message, and then go along with its business. # # <process>: Specifies the process to be executed and it's command line. # # Note: BusyBox init works just fine without an inittab. If no inittab is # found, it has the following default behavior: # ::sysinit:/etc/init.d/rcS # ::askfirst:/bin/sh # ::ctrlaltdel:/sbin/reboot # ::shutdown:/sbin/swapoff -a # ::shutdown:/bin/umount -a -r # ::restart:/sbin/init # # if it detects that /dev/console is _not_ a serial console, it will # also run: # tty2::askfirst:/bin/sh # tty3::askfirst:/bin/sh # tty4::askfirst:/bin/sh # # Boot-time system configuration/initialization script. # This is run first except when booting in single-user mode. # ::sysinit:/etc/init.d/rcS# /bin/sh invocations on selected ttys # # Note below that we prefix the shell commands with a "-" to indicate to the # shell that it is supposed to be a login shell. Normally this is handled by # login, but since we are bypassing login in this case, BusyBox lets you do # this yourself... # # Start an "askfirst" shell on the console (whatever that may be) ::askfirst:-/bin/sh # Start an "askfirst" shell on /dev/tty2-4new_init_action(ASKFIRST, bb_default_login_shell, "");new_init_action(ASKFIRST, bb_default_login_shell, VC_2);new_init_action(ASKFIRST, bb_default_login_shell, VC_3);new_init_action(ASKFIRST, bb_default_login_shell, VC_4); VC_2 ==> tty2 ASKFIRST ==> askfirst -/bin/sh ==> bb_default_login_shelltty2::askfirst:-/bin/sh tty3::askfirst:-/bin/sh tty4::askfirst:-/bin/sh# /sbin/getty invocations for selected ttys tty4::respawn:/sbin/getty 38400 tty5 tty5::respawn:/sbin/getty 38400 tty6# Example of how to put a getty on a serial line (for a terminal) #::respawn:/sbin/getty -L ttyS0 9600 vt100 #::respawn:/sbin/getty -L ttyS1 9600 vt100 # # Example how to put a getty on a modem line. #::respawn:/sbin/getty 57600 ttyS2# Stuff to do when restarting the init process ::restart:/sbin/init# Stuff to do before rebooting ::ctrlaltdel:/sbin/reboot ::shutdown:/bin/umount -a -r ::shutdown:/sbin/swapoff -a

總結

以上是生活随笔為你收集整理的构建linux根文件系统的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。