owned this note changed 5 years ago
Linked with GitHub

rootfs 淺談 - Carl Su

tags: COSCUP2020 中階 TR213

歡迎來到 https://hackmd.io/@coscup/2020 共筆

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

點擊本頁上方的 開始用 Markdown 一起寫筆記!
手機版請點選上方 按鈕展開議程列表。

請從這裡開始

linux 四大元素

  • tool chain
    • 編譯與執行
  • blootloader
    • 開機用 grub or u-boot
  • linux kernel
  • rootfs
    涵蓋以上所有元素

rootfs 概觀

kernel 以 read-only 掛載 rootfs 到根目錄 (/) (為了使用 init)
執行 /sbin/init or /bin/sh
init 根據 /etc/fstab 重新掛載 rootfs 和其餘檔案系統
/sbin/init 由 systemd 接管 (symbolic link)

x86_64 開機流程

  • BIOS/UEFI
    • 檢測硬體狀況與數據
  • MBR/GPT
    • 讀寫磁區
  • Linux kernel
  • /sbin/init

ARM 開機流程

  • ROM code
    • 通常出廠就有 無法改
  • SPL (Secondary Program Loader)
    • 放在 SRAM (可以自己寫)
  • TPL (Tertitary Program Loader)
    • e.g. UBOOT
  • Linux kernel
  • /sbin/init

檔案系統階層標準 (FHS)

  • bin
    • 一定要有的sh
  • boot
    • boot loader / EFI
  • dev
    • device files
  • etc
    • 設定相關 config
  • lib
    • 必要的程式 library
    • gnu, glibc, ld
    • 一些共用 library
  • media
  • mnt
    • 可留白,需要掛載使用
  • opt
  • run
    • 系統正在執行的 process
  • sbin
    • read-only
    • for 系統管理員使用
  • srv
  • tmp
    • tmpfs
  • usr
    • In the original Unix implementations, /usr was where the home directories of the users were placed (that is to say, /usr/someone was then the directory now known as /home/someone). In current Unices, /usr is where user-land programs and data (as opposed to 'system land' programs and data) are. The name hasn't changed, but it's meaning has narrowed and lengthened from "everything user related" to "user usable programs and data". As such, some people may now refer to this directory as meaning 'User System Resources' and not 'user' as was originally intended.
    • wiki: 注意不是user的縮寫,而是"Unix Software Resource"的縮寫。
  • var

建立 rootfs 的方式

chroot history

  • 1979 chroot
  • bill joy chroot to bsd
  • willian cheswicj honey pot
  • jail command
  • 2014 1st jailbreak
  • docker

Arch Linux rootfs

mount --bind root.x86_64 root.x86_64 
sudo root.x86_64/bin/arch-chroot root.x86_64
edit root.x86_64/etc/pacman.d/mirrorlist
pacman-key --init
pacman-key --populate archlinux
pacman -Syy
pacman -S base --noconfirm

簡報連結

https://docs.google.com/presentation/d/1v7ScSVk00PVfthV8E-dEeT3o7YcV29Hm2qdDKxHlo-Y/edit?usp=sharing

Select a repo