Translation

(itstool) path: sect3/title

Custom Functions
4/160
Context English Chinese (Simplified) (zh_CN) State
Customization is done in two ways: 定制过程包含两步:
Configuration options 配置选项
Custom functions 定制函数
Configuration Options 配置选项
buildworld buildworld
installworld installworld
With configuration settings, it is possible to configure options passed to both the <_:buildtarget-1/> and <_:buildtarget-2/> stages of the <application>NanoBSD</application> build process, as well as internal options passed to the main build process of <application>NanoBSD</application>. Through these options it is possible to cut the system down, so it will fit on as little as 64MB. You can use the configuration options to trim down FreeBSD even more, until it will consists of just the kernel and two or three files in the userland. 通过对配置进行设置, 可以配置用以传递给 <application>NanoBSD</application> 构建过程中 <_:buildtarget-1/> 和 <_:buildtarget-2/> 阶段的联编和安装选项, 以及 <application>NanoBSD</application> 的主构建过程中的选项。 通过使用这些选项可以削减系统的尺寸, 使之能够放入 64MB 的存储。 您还可以进一步通过这些选项来削减 FreeBSD, 直到它只包含内核以及两三个用户环境文件为止。
The configuration file consists of configuration options, which override the default values. The most important directives are: 配置文件中包含用以代替默认值的配置选项。 最重要的语句包括:
<literal>NANO_NAME</literal> — Name of build (used to construct the workdir names). <literal>NANO_NAME</literal> ── 本次构建的名称 (用于创建工作目录的名字)。
<literal>NANO_SRC</literal> — Path to the source tree used to build the image. <literal>NANO_SRC</literal> ── 用以联编和构建映像的源码树的位置。
<literal>NANO_KERNEL</literal> — Name of kernel configuration file used to build kernel. <literal>NANO_KERNEL</literal> ── 用以联编内核的配置文件的名字。
<literal>CONF_BUILD</literal> — Options passed to the <_:buildtarget-1/> stage of the build. <literal>CONF_BUILD</literal> ── 用于传递给 <_:buildtarget-1/> 构建阶段的选项。
<literal>CONF_INSTALL</literal> — Options passed to the <_:buildtarget-1/> stage of the build. <literal>CONF_INSTALL</literal> ── 用于传递给 <_:buildtarget-1/> 构建阶段的选项。
<literal>CONF_WORLD</literal> — Options passed to both the <_:buildtarget-1/> and the <_:buildtarget-2/> stage of the build. <literal>CONF_WORLD</literal> ── 用以传递给 <_:buildtarget-1/> 和 <_:buildtarget-2/> 这两个构建阶段的选项。
<literal>FlashDevice</literal> — Defines what type of media to use. Check <filename>FlashDevice.sub</filename> for more details. <literal>FlashDevice</literal> ── 定义所用的介质类型。 要了解进一步的细节, 请参考 <filename>FlashDevice.sub</filename> 文件。
Custom Functions 功能定制
It is possible to fine-tune <application>NanoBSD</application> using shell functions in the configuration file. The following example illustrates the basic model of custom functions: 通过在配置文件中使用 shell 函数可以进一步微调 <application>NanoBSD</application>。 下面的例子展示了定制函数的基本模式:
cust_foo () (
echo "bar=baz" &gt; \
${NANO_WORLDDIR}/etc/foo
)
customize_cmd cust_foo
cust_foo () (
echo "bar=baz" &gt; \
${NANO_WORLDDIR}/etc/foo
)
customize_cmd cust_foo
A more useful example of a customization function is the following, which changes the default size of the <filename>/etc</filename> directory from 5MB to 30MB: 下面是一个更贴近实际的例子, 它将默认的 <filename>/etc</filename> 目录尺寸, 从 5MB 调整为 30MB:
cust_etc_size () (
cd ${NANO_WORLDDIR}/conf
echo 30000 &gt; default/etc/md_size
)
customize_cmd cust_etc_size
cust_etc_size () (
cd ${NANO_WORLDDIR}/conf
echo 30000 &gt; default/etc/md_size
)
customize_cmd cust_etc_size
There are a few default pre-defined customization functions ready for use: 除此之外, 还有几个默认的预定义定制函数:
<literal>cust_comconsole</literal> — Disables <citerefentry><refentrytitle>getty</refentrytitle><manvolnum>8</manvolnum></citerefentry> on the VGA devices (the <filename>/dev/ttyv*</filename> device nodes) and enables the use of the COM1 serial port as the system console. <literal>cust_comconsole</literal> ── 在 VGA 设备上禁止 <citerefentry><refentrytitle>getty</refentrytitle><manvolnum>8</manvolnum></citerefentry> (<filename>/dev/ttyv*</filename> 设备节点) 并启用串口 COM1 作为系统控制台。
<literal>cust_allow_ssh_root</literal> — Allow <systemitem class="username">root</systemitem> to login via <citerefentry><refentrytitle>sshd</refentrytitle><manvolnum>8</manvolnum></citerefentry>. <literal>cust_allow_ssh_root</literal> ── 允许 <systemitem class="username">root</systemitem> 通过 <citerefentry><refentrytitle>sshd</refentrytitle><manvolnum>8</manvolnum></citerefentry> 登录。
<literal>cust_install_files</literal> — Installs files from the <filename>nanobsd/Files</filename> directory, which contains some useful scripts for system administration. <literal>cust_install_files</literal> ── 从 <filename>nanobsd/Files</filename> 目录中安装文件, 这包含一些实用的系统管理脚本。
Adding Packages 安装预编译软件包
Packages can be added to a <application>NanoBSD</application> image using a custom function. The following function will install all the packages located in <filename>/usr/src/tools/tools/nanobsd/packages</filename>: 通过增加自定义的函数, 可以在 <application>NanoBSD</application> 增加预编译的软件包。 下面的函数会添加位于 <filename>/usr/src/tools/tools/nanobsd/packages</filename> 的全部预编译软件包:
install_packages () (
mkdir -p ${NANO_WORLDDIR}/packages
cp /usr/src/tools/tools/nanobsd/packages/* ${NANO_WORLDDIR}/packages
cp $(which pkg-static) ${NANO_WORLDDIR}/
chroot ${NANO_WORLDDIR} sh -c 'cd packages; /pkg-static add *;cd ..;'
rm -rf ${NANO_WORLDDIR}/packages ${NANO_WORLDDIR}/pkg-static
)
customize_cmd install_packages
install_packages () (
mkdir -p ${NANO_WORLDDIR}/packages
cp /usr/src/tools/tools/nanobsd/packages/* ${NANO_WORLDDIR}/packages
cp $(which pkg-static) ${NANO_WORLDDIR}/
chroot ${NANO_WORLDDIR} sh -c 'cd packages; /pkg-static add *;cd ..;'
rm -rf ${NANO_WORLDDIR}/packages ${NANO_WORLDDIR}/pkg-static
)
customize_cmd install_packages
Configuration File Example 配置文件举例
A complete example of a configuration file for building a custom <application>NanoBSD</application> image can be: 下面是一个用于构建定制的 <application>NanoBSD</application> 映像的完整例子:
NANO_NAME=custom
NANO_SRC=/usr/src
NANO_KERNEL=MYKERNEL
NANO_IMAGES=2

CONF_BUILD='
WITHOUT_KLDLOAD=YES
WITHOUT_NETGRAPH=YES
WITHOUT_PAM=YES
'

CONF_INSTALL='
WITHOUT_ACPI=YES
WITHOUT_BLUETOOTH=YES
WITHOUT_FORTRAN=YES
WITHOUT_HTML=YES
WITHOUT_LPR=YES
WITHOUT_MAN=YES
WITHOUT_SENDMAIL=YES
WITHOUT_SHAREDOCS=YES
WITHOUT_EXAMPLES=YES
WITHOUT_INSTALLLIB=YES
WITHOUT_CALENDAR=YES
WITHOUT_MISC=YES
WITHOUT_SHARE=YES
'

CONF_WORLD='
WITHOUT_BIND=YES
WITHOUT_MODULES=YES
WITHOUT_KERBEROS=YES
WITHOUT_GAMES=YES
WITHOUT_RESCUE=YES
WITHOUT_LOCALES=YES
WITHOUT_SYSCONS=YES
WITHOUT_INFO=YES
'

FlashDevice SanDisk 1G

cust_nobeastie() (
touch ${NANO_WORLDDIR}/boot/loader.conf
echo "beastie_disable=\"YES\"" &gt;&gt; ${NANO_WORLDDIR}/boot/loader.conf
)

customize_cmd cust_comconsole
customize_cmd cust_install_files
customize_cmd cust_allow_ssh_root
customize_cmd cust_nobeastie
NANO_NAME=custom
NANO_SRC=/usr/src
NANO_KERNEL=MYKERNEL
NANO_IMAGES=2

CONF_BUILD='
WITHOUT_KLDLOAD=YES
WITHOUT_NETGRAPH=YES
WITHOUT_PAM=YES
'

CONF_INSTALL='
WITHOUT_ACPI=YES
WITHOUT_BLUETOOTH=YES
WITHOUT_FORTRAN=YES
WITHOUT_HTML=YES
WITHOUT_LPR=YES
WITHOUT_MAN=YES
WITHOUT_SENDMAIL=YES
WITHOUT_SHAREDOCS=YES
WITHOUT_EXAMPLES=YES
WITHOUT_INSTALLLIB=YES
WITHOUT_CALENDAR=YES
WITHOUT_MISC=YES
WITHOUT_SHARE=YES
'

CONF_WORLD='
WITHOUT_BIND=YES
WITHOUT_MODULES=YES
WITHOUT_KERBEROS=YES
WITHOUT_GAMES=YES
WITHOUT_RESCUE=YES
WITHOUT_LOCALES=YES
WITHOUT_SYSCONS=YES
WITHOUT_INFO=YES
'

FlashDevice SanDisk 1G

cust_nobeastie() (
touch ${NANO_WORLDDIR}/boot/loader.conf
echo "beastie_disable=\"YES\"" &gt;&gt; ${NANO_WORLDDIR}/boot/loader.conf
)

customize_cmd cust_comconsole
customize_cmd cust_install_files
customize_cmd cust_allow_ssh_root
customize_cmd cust_nobeastie
Updating NanoBSD 更新 NanoBSD

Loading…

No matching activity found.

Browse all component changes

Glossary

English Chinese (Simplified) (zh_CN)
No related strings found in the glossary.

Source information

Source string comment

(itstool) path: sect3/title

Source string location
article.translate.xml:289
String age
a year ago
Source string age
a year ago
Translation file
articles/zh_CN/nanobsd.po, string 56