# 設定啟動後（postboot）的參數

啟動後設定包括完成初始設定、配置記憶體和 CPU 頻率參數。這些步驟可在系統啟動後確保正確的組態和功能。

## 啟動後框架概覽

啟動後指令碼檔案用來在 Qualcomm Linux 發行版上配置系統參數。

透過 *systemd service* 檔案管理啟動後設定。

欲深入瞭解 systemd，請參閱 [systemd(1) - Linux manual page](https://www.man7.org/linux/man-pages/man1/systemd.1.html)。

## Systemd 服務概覽

systemd 服務是根據特定條件而啟動或停止的背景處理序。

寫入 `systemd service` 檔案以允許 systemd 依照指示剖析、理解和運作。

欲深入瞭解背景處理序，請參閱 [background process](https://linuxhandbook.com/run-process-background/)。

## systemd 服務檔案的基礎結構

若要根據要求修改 systemd 的行為，請依照下述程序操作：

以下是 systemd 服務檔案的基礎結構：

[Unit]
    SourcePath=/etc/initscripts/log_restrict.sh
    Description=QTI logging service
    
    [Service]
    ExecStart=/etc/initscripts/post_boot.sh
    
    [Install]
    WantedBy=multi-user.target
    Copy to clipboard

### `[Unit]` 區段

在 systemd 中，單元是指系統知道如何操作和管理的任何資源。包含服務、套接字、裝置、掛載點和外部建立的處理序群組。

使用稱為 `unit` 檔案的組態檔來定義每個單元，檔案中包含中繼資料和組態詳細資訊。單元檔案中的 `[Unit]` 區段提供描述以及與其他單元的關係。

`[Unit]` 區段有以下欄位：

表：[Unit] 區段支援的欄位

| 欄位 | 說明 |
| --- | --- |
| Description<br>    Copy to clipboard | 人類可辨讀的systemd 服務標題。 |
| After<br>    Copy to clipboard | 設定對服務的相依性。例如，假設正在配置 WCN3960 網頁伺服器，而您要讓伺服器在網路上線之後啟動。 |
| Before<br>    Copy to clipboard | 在指定的服務之前啟動目前服務。在此範例中，WCN3960 網頁伺服器在下一個雲端的服務啟動之前執行，因為下一個雲端伺服器依賴 WCN3960 網頁伺服器。 |

### `[Service]` 區段

`[Service]` 區段包含服務執行和終止的詳細資訊。

`[Servicet]` 區段有以下欄位：

表：[Service] 區段支援的欄位

| 欄位 | 說明 |
| --- | --- |
| ExecStart<br>    Copy to clipboard | 服務啟動時必須執行的命令。例如要啟動的網頁伺服器服務。 |
| ExecReload<br>    Copy to clipboard | 選填欄位用來指定重新啟動服務的方式。如果是執行磁碟 I/O 的服務，建議先終止再重新啟動服務。如果想要特定的重新啟動機制，請使用 `ExecReload` 欄位。 |
| Type<br>    Copy to clipboard | 表示指定 systemd 服務的處理序啟動類型。可用選項包括 `simple`、`exec`、`forking`、`oneshot`、`dbus`、`notify` 和 `idle`。 |

如需更多資訊，請參閱 [Options](https://www.freedesktop.org/software/systemd/man/latest/systemd.service.html?ref=linuxhandbook.com#Options)。

### `[Install]` 區段

`[Install]` 區段處理 systemd 服務或單元檔案的安裝。執行 `systemctl enable` 或 `systemctl disable` 命令以啟用或停用服務時，使用此區段。

`[Install]` 區段有以下欄位：

- `WantedBy`：與 [\[Unit\] 區段](https://docs.qualcomm.com/doc/80-70020-3TC/topic/post-boot-settings.html#kernelexternaldocumentation-the-unit-section) 的 `After` 和 `Before` 欄位類似。但它用來指定與 systemd 等效的 **執行層級**。

    所有系統初始化完成並要求您登入時，會使用 `default.target`。大多數面向使用者的服務 (例如 WCN3960、cron、GNOME-stuff) 都使用此目標。

    `shutdown.target` 是在裝置關機之前執行服務。

    `multi-user.target` 是在系統啟動時以根使用者身分執行服務。

    它可以是目標或服務，例如 `network.target`。
- `RequiredBy`：此欄位與 `WantedBy` 類似。但此欄位指定 **硬相依性**。如果相依性失敗，則服務也會失敗。

## 安裝啟動後 systemd 服務

啟動後指令碼檔案位於 `meta-qcom-hwe` 層的核心配方中。

執行 postboot 指令碼以作為先前 systemd 服務的一部分。所有啟動後設定都託管在 `meta-qcom-hwe/recipes-core/initscripts/files/post_boot.sh` 指令碼中。

#!/bin/sh
    # Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights reserved.
    # SPDX-License-Identifier: BSD-3-Clause-Clear
    
    # Apply postboot settings
    Copy to clipboard

### 啟動後 systemd 服務的配方

使用 `initscripts_1.0.bbappend` 檔案瞭解配方配置程序以安裝 `post_boot` 指令碼。

用來在 `/etc/init.d` 中安裝啟動後 bash 指令碼的配方位於 `meta-qcom-hwe/recipes-core/initscripts/initscripts_1.0.bbappend` 檔案中。

# postboot
    
    inherit systemd externalsrc
    
    FILESEXTRAPATHS:prepend := "${THISDIR}/files:"
    SRC_URI:append = " \
       file://post_boot.sh \
       file://logging-restrictions.sh \
       file://log-restrict.service \
       file://post-boot.service \
       "
    
    do_install:append() {
       # postboot
       install -m 0755 ${WORKDIR}/post_boot.sh ${D}${sysconfdir}/initscripts/post_boot.sh
       install -m 0644 ${WORKDIR}/post-boot.service -D ${D}${systemd_unitdir}/system/post-boot.service
       ln -sf ${systemd_unitdir}/system/post-boot.service ${D}${systemd_unitdir}/system/multi-user.target.wants/post-boot.service
    }
    
    S = "${WORKDIR}"
    
    INITSCRIPT_PACKAGES =+ "${PN}-post-boot"
    INITSCRIPT_NAME:${PN}-post-boot = "post_boot.sh"
    
    PACKAGES =+ "${PN}-post-boot"
    FILES:${PN}-post-boot += "${systemd_unitdir}/system/post-boot.service ${systemd_unitdir}/system/multi-user.target.wants/post-boot.service ${sysconfdir}/initscripts/post_boot.sh"
    Copy to clipboard

Last Published: Jan 01, 2026

[Previous Topic
啟動流程和架構概覽](https://docs.qualcomm.com/bundle/publicresource/80-70020-3TC/topics/boot-flow-and-architecture-overview.md) [Next Topic
開發核心](https://docs.qualcomm.com/bundle/publicresource/80-70020-3TC/topics/kernel-development.md)