Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
docs:techref:preinit_mount [2018/04/13 20:43] – [Preinit] jeffdocs:techref:preinit_mount [2024/09/06 11:49] (current) – Add missing initramfs tag info feckert
Line 1: Line 1:
 ======= Preinit and Root Mount and Firstboot Scripts ======= ======= Preinit and Root Mount and Firstboot Scripts =======
  
-FIXME Outdated and obsolete information as of April, 2018+FIXME Information may be outdated and obsolete information as of April, 2018; Overview, Preinit and Overview, Failsafe updated from April 2018 based on reading ''master'' code.
  
 See [[docs:guide-user:additional-software:extroot_configuration|Rootfs on External Storage]] for information on external rootfs mounting. See [[docs:guide-user:additional-software:extroot_configuration|Rootfs on External Storage]] for information on external rootfs mounting.
Line 17: Line 17:
  
   - boot loader loads kernel   - boot loader loads kernel
-  - kernel loads whilst scaning the mtd partition //rootfs// for a valid superblock for mounting the SquashFS partition (which contains /etc). More info at [[docs:techref:filesystems#technical.details]] +  - kernel loads whilst scanning the mtd partition //rootfs// for a valid superblock for mounting the SquashFS partition (which contains /etc). More info at [[docs:techref:filesystems#technical.details]] 
-  - kernel calls ''/etc/preinit'' (the kernel considers this to be the ''init'' (or root) process+  - <del>kernel calls ''/etc/preinit'' (the kernel considers this to be the ''init'' (or root) process</del> ''/sbin/init'' now the init process, which in turn launches ''/sbin/procd -h /etc/hotplug-preinit.json'' (a.k.a., "plugd") followed by ''/bin/sh /etc/preinit'' Each is launched via ''fork'' and ''execvp'' and managed by the uloop library in libubox.
   - ''/etc/preinit'' prepares system for multiuser mode   - ''/etc/preinit'' prepares system for multiuser mode
   - ''/etc/preinit'' ''exec''s ''/sbin/init'' which becomes the ''init'' (or root) process and launches multiuser   - ''/etc/preinit'' ''exec''s ''/sbin/init'' which becomes the ''init'' (or root) process and launches multiuser
Line 28: Line 28:
  
 ====== Overview ====== ====== Overview ======
 +The following preinit scripts are available in the OpenWrt master branches for base and packages feed (Status September 2024)
 +| repo     | packages         | target      | subtarget   | file-repo                                                                          | file-target                                | hook               | info                  |
 +| packages | openssh          | all         | all         | net/openssh/files/sshd.failsafe                                                    | /lib/preinit/99_10_failsafe_sshd           | failsafe                                 |
 +| packages | btrfs-progs      | all         | all         | utils/btrfs-progs/files/btrfs-scan.init                                            | /lib/preinit/85_btrfs_scan                 | preinit_main       | INITRAMFS check 'NO'  |
 +| packages | lvm2             | all         | all         | utils/lvm2/files/lvm2.preinit                                                      | /lib/preinit/80_lvm2                       | preinit_main       | INITRAMFS check 'NO'  |
 +| base     | dropbear         | all         | all         | package/network/services/dropbear/files/dropbear.failsafe                          | /lib/preinit/99_10_failsafe_dropbear       | failsafe                                 |
 +| base     | zyxel-bootconfig | all         | all         | package/utils/zyxel-bootconfig/files/95_apply_bootconfig                           | /lib/preinit/95_apply_bootconfig           | preinit_main       | INITRAMFS check 'YES' |
 +| base     | linux            | imx         | cortexa53   | target/linux/imx/cortexa53/base-files/lib/preinit/79_move_config                   | /lib/preinit/79_move_config                | preinit_mount_root |                       |
 +| base     | linux            | imx         | cortexa7    | target/linux/imx/cortexa7/base-files/lib/preinit/79_move_config                    | /lib/preinit/79_move_config                | preinit_mount_root |                       |
 +| base     | linux            | imx         | cortexa9    | target/linux/imx/cortexa9/base-files/lib/preinit/79_move_config                    | /lib/preinit/79_move_config                | preinit_mount_root |                       |
 +| base     | linux            | rockchip    | armv8       | target/linux/rockchip/armv8/base-files/lib/preinit/79_move_config                  | /lib/preinit/79_move_config                | preinit_mount_root |                       |
 +| base     | linux            | omap        |             | target/linux/omap/base-files/lib/preinit/79_move_config                            | /lib/preinit/79_move_config                | preinit_mount_root |                       |
 +| base     | linux            | qoriq                   | target/linux/qoriq/base-files/lib/preinit/79_move_config                           | /lib/preinit/79_move_config                | preinit_mount_root |                       |
 +| base     | linux            | sifiveu                 | target/linux/sifiveu/base-files/lib/preinit/79_move_config                         | /lib/preinit/79_move_config                | preinit_mount_root |                       |
 +| base     | linux            | tegra                   | target/linux/tegra/base-files/lib/preinit/79_move_config                           | /lib/preinit/79_move_config                | preinit_mount_root |                       |
 +| base     | linux            | sunxi                   | target/linux/sunxi/base-files/lib/preinit/79_move_config                           | /lib/preinit/79_move_config                | preinit_mount_root |                       |
 +| base     | base-files       | all         | all         | package/base-files/files/lib/preinit/02_default_set_state                          | /lib/preinit/02_default_set_state          | preinit_main                             |
 +| base     | base-files       | all         | all         | package/base-files/files/lib/preinit/02_sysinfo                                    | /lib/preinit/02_sysinfo                    | preinit_main                             |
 +| base     | base-files       | all         | all         | package/base-files/files/lib/preinit/10_indicate_failsafe                          | /lib/preinit/10_indicate_failsafe          | failsafe                                 |
 +| base     | base-files       | all         | all         | package/base-files/files/lib/preinit/10_indicate_preinit                           | /lib/preinit/10_indicate_preinit           | preinit_main                             |
 +| base     | base-files       | all         | all         | package/base-files/files/lib/preinit/30_failsafe_wait                              | /lib/preinit/30_failsafe_wait              | preinit_main                             |
 +| base     | base-files       | all         | all         | package/base-files/files/lib/preinit/40_run_failsafe_hook                          | /lib/preinit/40_run_failsafe_hook          | preinit_main                             |
 +| base     | base-files       | all         | all         | package/base-files/files/lib/preinit/50_indicate_regular_preinit                   | /lib/preinit/50_indicate_regular_preinit   | preinit_main                             |
 +| base     | base-files       | all         | all         | package/base-files/files/lib/preinit/70_initramfs_test                             | /lib/preinit/70_initramfs_test             | preinit_main                             |
 +| base     | base-files       | all         | all         | package/base-files/files/lib/preinit/80_mount_root                                 | /lib/preinit/80_mount_root                 | preinit_main       | INITRAMFS check 'YES' |
 +| base     | base-files       | all         | all         | package/base-files/files/lib/preinit/99_10_failsafe_login                          | /lib/preinit/99_10_failsafe_login          | failsafe                                 |
 +| base     | base-files       | all         | all         | package/base-files/files/lib/preinit/99_10_run_init                                | /lib/preinit/99_10_run_init                | preinit_main       | INITRAMFS check 'NO'  |
 +| base     | linux            | bcm47xx                 | target/linux/bcm47xx/base-files/lib/preinit/01_sysinfo                             | /lib/preinit/01_sysinfo                    | preinit_main                             |
 +| base     | linux            | lantiq      | xway_legacy | target/linux/lantiq/xway_legacy/base-files/lib/preinit/05_set_preinit_iface_lantiq | /lib/preinit/05_set_preinit_iface_lantiq   | preinit_main                             |
 +| base     | linux            | lantiq      | xway        | target/linux/lantiq/xway/base-files/lib/preinit/05_set_preinit_iface_lantiq        | /lib/preinit/05_set_preinit_iface_lantiq   | preinit_main                             |
 +| base     | linux            | lanitq      | ase         | target/linux/lantiq/ase/base-files/lib/preinit/05_set_preinit_iface_lantiq         | /lib/preinit/05_set_preinit_iface_lantiq   | preinit_main                             |
 +| base     | linux            | armsr                   | target/linux/armsr/base-files/lib/preinit/01_sysinfo_acpi                          | /lib/preinit/01_sysinfo_acpi               | preinit_main                             |
 +| base     | linux            | armsr                   | target/linux/armsr/base-files/lib/preinit/79_move_config                           | /lib/preinit/79_move_config                | preinit_mount_root |                       |
 +| base     | linux            | x86                     | target/linux/x86/base-files/lib/preinit/02_load_x86_ucode                          | /lib/preinit/02_load_x86_ucode             | preinit_main                             |
 +| base     | linux            | x86                     | target/linux/x86/base-files/lib/preinit/15_essential_fs_x86                        | /lib/preinit/15_essential_fs_x86           | ?                  |                       |
 +| base     | linux            | x86                     | target/linux/x86/base-files/lib/preinit/20_check_iso                               | /lib/preinit/20_check_iso                  | preinit_mount_root |                       |
 +| base     | linux            | x86                     | target/linux/x86/base-files/lib/preinit/79_move_config                             | /lib/preinit/79_move_config                | preinit_mount_root |                       |
 +| base     | linux            | x86                     | target/linux/x86/generic/base-files/lib/preinit/45_mount_xenfs                     | /lib/preinit/45_mount_xenfs                | preinit_mount_root |                       |
 +| base     | linux            | x86         | 64          | target/linux/x86/64/base-files/lib/preinit/45_mount_xenfs                          | /lib/preinit/45_mount_xenfs                | preinit_mount_root |                       |
 +| base     | linux            | bcm27xx                 | target/linux/bcm27xx/base-files/lib/preinit/05_set_preinit_iface_brcm2708          | /lib/preinit/05_set_preinit_iface_brcm2708 | preinit_main                             |
 +| base     | linux            | bcm27xx                 | target/linux/bcm27xx/base-files/lib/preinit/79_move_config                         | /lib/preinit/79_move_config                | preinit_mount_root |                       |
 +| base     | linux            | bcm27xx                 | target/linux/bcm27xx/base-files/lib/preinit/81_set_root_part                       | /lib/preinit/81_set_root_part              | preinit_main       | INITRAMFS check 'YES' |
 +| base     | linux            | mediatek    |             | target/linux/mediatek/base-files/lib/preinit/05_set_preinit_iface                  | /lib/preinit/05_set_preinit_iface          | preinit_main                             |
 +| base     | linux            | mediatek    |             | target/linux/mediatek/base-files/lib/preinit/06_set_rps_sock_flow                  | /lib/preinit/06_set_rps_sock_flow          | preinit_main                             |
 +| base     | linux            | mediatek    |             | target/linux/mediatek/base-files/lib/preinit/07_trigger_fip_scrubbing              | /lib/preinit/07_trigger_fip_scrubbing      | preinit_main                             |
 +| base     | linux            | mediatek    | mt7623      | target/linux/mediatek/mt7623/base-files/lib/preinit/07_set_iface_mac               | /lib/preinit/07_set_iface_mac              | preinit_main                             |
 +| base     | linux            | mediatek    | mt7623      | target/linux/mediatek/mt7623/base-files/lib/preinit/79_move_config                 | /lib/preinit/79_move_config                | preinit_mount_root |                       |
 +| base     | linux            | mediatek    | filogic     | target/linux/mediatek/filogic/base-files/lib/preinit/04_set_netdev_label           | /lib/preinit/04_set_netdev_label           | preinit_main                             |
 +| base     | linux            | mediatek    | filogic     | target/linux/mediatek/filogic/base-files/lib/preinit/05_extract_factory_data.sh    | /lib/preinit/05_extract_factory_data.sh    | preinit_main                             |
 +| base     | linux            | mediatek    | filogic     | target/linux/mediatek/filogic/base-files/lib/preinit/09_mount_cfg_part             | /lib/preinit/09_mount_cfg_part             | preinit_main                             |
 +| base     | linux            | mediatek    | filogic     | target/linux/mediatek/filogic/base-files/lib/preinit/10_fix_eth_mac.sh             | /lib/preinit/10_fix_eth_mac.sh             | preinit_main                             |
 +| base     | linux            | mediatek    | filogic     | target/linux/mediatek/filogic/base-files/lib/preinit/75_rootfs_prepare             | /lib/preinit/75_rootfs_prepare             | preinit_main       | INITRAMFS check 'NO'  |
 +| base     | linux            | apm821xx    |             | target/linux/apm821xx/base-files/lib/preinit/05_set_preinit_iface_apm821xx         | /lib/preinit/05_set_preinit_iface_apm821xx | preinit_main                             |
 +| base     | linux            | apm821xx    |             | target/linux/apm821xx/base-files/lib/preinit/05_set_iface_mac_apm821xx             | /lib/preinit/05_set_iface_mac_apm821xx     | preinit_main                             |
 +| base     | linux            | apm821xx    |             | target/linux/apm821xx/base-files/lib/preinit/79_move_config                        | /lib/preinit/79_move_config                | preinit_mount_root |                       |
 +| base     | linux            | ixp4xx      |             | target/linux/ixp4xx/base-files/lib/preinit/05_set_ether_mac_ixp4xx                 | /lib/preinit/05_set_ether_mac_ixp4xx       | preinit_main                             |
 +| base     | linux            | kirkwood    |             | target/linux/kirkwood/base-files/lib/preinit/07_set_iface_mac                      | /lib/preinit/07_set_iface_mac              | preinit_main                             |
 +| base     | linux            | mvebu                   | target/linux/mvebu/base-files/lib/preinit/79_move_config                           | /lib/preinit/79_move_config                | preinit_mount_root |                       |
 +| base     | linux            | mvebu       | cortexa53   | target/linux/mvebu/cortexa53/base-files/lib/preinit/82_uDPU                        | /lib/preinit/82_uDPU                       | preinit_main       | INITRAMFS check 'NO'  |
 +| base     | linux            | mvebu       | cortexa9    | target/linux/mvebu/cortexa9/base-files/lib/preinit/81_linksys_syscfg               | /lib/preinit/81_linksys_syscfg             | preinit_main       | INITRAMFS check 'NO'  |
 +| base     | linux            | ipq806x                 | target/linux/ipq806x/base-files/lib/preinit/04_reorder_eth                         | /lib/preinit/04_reorder_eth                | preinit_main                             |
 +| base     | linux            | ath79       | generic     | target/linux/ath79/generic/base-files/lib/preinit/02_sysinfo_fixup                 | /lib/preinit/02_sysinfo_fixup              | preinit_main                             |
 +| base     | linux            | ath79       | generic     | target/linux/ath79/generic/base-files/lib/preinit/10_fix_eth_mac.sh                | /lib/preinit/10_fix_eth_mac.sh             | preinit_main                             |
 +| base     | linux            | ath79       | nand        | target/linux/ath79/nand/base-files/lib/preinit/10_fix_eth_mac.sh                   | /lib/preinit/10_fix_eth_mac.sh             | preinit_main                             |
 +| base     | linux            | bcm4908                 | target/linux/bcm4908/base-files/lib/preinit/75_rootfs_prepare                      | /lib/preinit/75_rootfs_prepare             | preinit_main       | INITRAMFS check 'NO' |
 +| base     | linux            | gemini      |             | target/linux/gemini/base-files/lib/preinit/05_set_ether_mac_gemini                 | /lib/preinit/05_set_ether_mac_gemini       | preinit_main                             |
 +| base     | linux            | loongarch64 |             | target/linux/loongarch64/base-files/lib/preinit/01_sysinfo_acpi                    | /lib/preinit/01_sysinfo_acpi               | preinit_main                             |
 +| base     | linux            | loongarch64 |             | target/linux/loongarch64/base-files/lib/preinit/79_move_config                     | /lib/preinit/79_move_config                | preinit_mount_root |                       |
 +| base     | linux            | mpc85xx                 | target/linux/mpc85xx/base-files/lib/preinit/05_set_preinit_iface_mpc85xx           | /lib/preinit/05_set_preinit_iface_mpc85xx  | preinit_main                             |
 +| base     | linux            | mpc85xx                 | target/linux/mpc85xx/base-files/lib/preinit/10_fix_eth_mac.sh                      | /lib/preinit/10_fix_eth_mac.sh             | preinit_main                             |
 +| base     | linux            | layerscape  |             | target/linux/layerscape/base-files/lib/preinit/02_sysinfo_fixup                    | /lib/preinit/02_sysinfo_fixup              | preinit_main                             |
 +| base     | linux            | layerscape  |             | target/linux/layerscape/base-files/lib/preinit/79_move_config                      | /lib/preinit/79_move_config                | preinit_mount_root |                       |
 +| base     | linux            | ramips      | mt7621      | target/linux/ramips/mt7621/base-files/lib/preinit/04_set_netdev_label              | /lib/preinit/04_set_netdev_label           | preinit_main                             |
 +| base     | linux            | ramips      | rt305x      | target/linux/ramips/rt305x/base-files/lib/preinit/04_handle_checksumming           | /lib/preinit/04_handle_checksumming        | preinit_main                             |
 +| base     | linux            | ramips      | rt3883      | target/linux/ramips/rt3883/base-files/lib/preinit/04_handle_checksumming           | /lib/preinit/04_handle_checksumming        | preinit_main                             |
 +| base     | linux            | ipq40xx                 | target/linux/ipq40xx/base-files/lib/preinit/05_set_iface_mac_ipq40xx.sh            | /lib/preinit/05_set_iface_mac_ipq40xx.sh   | preinit_main                             |
 +| base     | linux            | octeon      |             | target/linux/octeon/base-files/lib/preinit/01_sysinfo                              | /lib/preinit/01_sysinfo                    | preinit_main                             |
 +| base     | linux            | octeon      |             | target/linux/octeon/base-files/lib/preinit/79_move_config                          | /lib/preinit/79_move_config                | preinit_mount_root |                       |
 +
 +
 +
  
 ===== Preinit ===== ===== Preinit =====
  
 Preinit brings the system from raw kernel to ready for multiuser.  To do so, as of April, 2018, Preinit brings the system from raw kernel to ready for multiuser.  To do so, as of April, 2018,
-it performs the following tasks:+''/etc/preinit'' (ar71xx, Archer C7) performs the following tasks:
  
 +  - Checks to see if ''$PREINIT'' is empty; if so ''exec /sbin/init'' and skip the rest
   - Sources a set of files for common functions for boot/mount:   - Sources a set of files for common functions for boot/mount:
     * ''/lib/functions.sh''     * ''/lib/functions.sh''
Line 39: Line 121:
     *  ''/lib/functions/system.sh''     *  ''/lib/functions/system.sh''
   - Prepares the "hooks" for the various stages of the preinit process   - Prepares the "hooks" for the various stages of the preinit process
-    * boot_hook_init preinit_essential +    * preinit_essential 
-    * boot_hook_init preinit_main +    * preinit_main 
-    * boot_hook_init failsafe +    * failsafe 
-    * boot_hook_init initramfs +    * initramfs 
-    * boot_hook_init preinit_mount_root+    * preinit_mount_root
   - Source the contents of ''/lib/preinit/*'' which generally add ''sh'' functions to the appropriate hooks   - Source the contents of ''/lib/preinit/*'' which generally add ''sh'' functions to the appropriate hooks
   - Runs the ''preinit_essential'' hooks   - Runs the ''preinit_essential'' hooks
   - Runs the ''preinit_main'' hooks   - Runs the ''preinit_main'' hooks
 +
 +On an ar71xx device (Archer C7) the default functions added to the various hooks include (with functions from device-specific files in //italics)://
 +
 +
 +  * **preinit_main**
 +    - //do_ar71xx//
 +    - define_default_set_state
 +    - do_sysinfo_generic
 +    - //preinit_set_mac_address//
 +    - //set_preinit_iface//
 +    - preinit_ip
 +    - pi_indicate_preinit
 +    - failsafe_wait
 +    - run_failsafe_hook 
 +      * **failsafe** (if "$pi_preinit_no_failsafe" != "y" and "$FAILSAFE" = "true")
 +        - indicate_failsafe
 +        - failsafe_netlogin
 +        - failsafe_shell
 +    - indicate_regular_preinit
 +    - do_mount_root (if "$INITRAMFS" != "1")
 +    - do_urandom_seed
 +    - //check_patch_ath10k_firmware//
 +    - run_init
 +
 +Presently unused hooks, at least for the ar71xx Archer C7, appear to include
 +  * preinit_essential
 +  * initramfs
 +  * preinit_mount_root
  
  
  
-  - Mounts essential kernel filesystems like procfs 
-  - Initializes device tree (/dev)  
-  - Initializes console (serial console if present, otherwise dummy so that the script interpreter works properly) 
-  - Presents opportunity for the user to enter a special operating mode called **'failsafe'** (Failsafe mode is presented in a separate section.  Once failsafe  mode is entered it doesn't exit.  A reboot is necessary to enter normal  operating mode). 
-  - **Mounts the root filesystem** (this involves a number steps, presented in  a separate section) 
-  - If it's the first time booting after flashing the firmware, and a previous configuration was saved during the flashing process, that configuration is restored. 
-  - Becomes (though ''exec'') 'init' which goes to multiuser mode 
  
 ===== Failsafe ===== ===== Failsafe =====
Line 62: Line 165:
 The //root file system// is actually an overlay which can be consisted of a read-only SquashFS file system (mounted at ''/rom'') and a writable JFFS2 partition (mounted under ''/overlay''). In Failsafe mode only the squashfs FS will be mounted (changes made to jffs2 partitons will be ignored), plus the following steps: The //root file system// is actually an overlay which can be consisted of a read-only SquashFS file system (mounted at ''/rom'') and a writable JFFS2 partition (mounted under ''/overlay''). In Failsafe mode only the squashfs FS will be mounted (changes made to jffs2 partitons will be ignored), plus the following steps:
  
-  - Prepares network interface (optional) and notifies that failsafe mode is being entered +  - Notifies that failsafe mode is being entered (indicate_failsafe) 
-  - Launches daemon to allow network logins +  - Launches daemon to allow network logins (failsafe_netlogin) 
-  - Allows login via serial console, if there is one. +  - Allows login via serial console, if there is one (failsafe_shell) 
-  - When the serial console login process exits, failsafe doesn't exit, instead it continues to wait for network logins (whether or not they are actually possible).+    * If the serial console login process exits, failsafe doesn't exit, but restarts the process for additional logins.
  
  
Line 82: Line 185:
   - This is only reached if no other step succeeds; attempt to mount ''/dev/root'' (e.g. squashfs/all_jffs2) as root filesystem.   - This is only reached if no other step succeeds; attempt to mount ''/dev/root'' (e.g. squashfs/all_jffs2) as root filesystem.
  
-** * ** ''/overlay'' was previously named ''/jffs2''+** * ** ''/overlay'' was previously named ''/jffs2''.\\ 
 +** * ** NOTE: If volatile files (e.g. a config) were preserved across firmware update via ''sysupgrade'', step 3 is skipped. Instead, preinit_main hangs while the rootfs_data partition is formatted and the jffs2 overlay is mounted. Hypothetically, this is fatal on systems with weak cpu and exceptionally large rootfs_data partitions. For more information [[https://forum.openwrt.org/t/error-in-preinit-documentation-regarding-overlays/60188/4|consult this forum post]].
  
 ===== First Boot ===== ===== First Boot =====
  • Last modified: 2018/04/13 20:43
  • by jeff