自定义用户脚本

通过在自动安装过程中添加脚本,我们可以根据需要自定义安装并控制安装的不同阶段。

在自动安装过程中,可以执行五种脚本,这里将按照安装过程中“出现”的顺序进行说明。

所有脚本都必须在 <scritps> 部分中。

  • pre-scripts(很早,在其他任何事情真正发生之前)
  • postpartitioning-scripts(在分区和挂载到 /mnt 之后但在 RPM 安装之前——从 openSUSE 11.2 和 SLES11 SP3 开始)
  • chroot-scripts(安装包后,第一次启动前)
  • post-scripts(在已安装系统的第一次启动期间,没有运行任何服务)
  • init-scripts(在已安装系统的第一次启动期间,所有服务都启动并运行)

一些例子

  1. pre-script 预脚本
<pre-scripts config:type="list">
   <script>
       <filename>my-test.sh</filename>
       <interpreter>shell</interpreter>
       <source><![CDATA[#!/bin/sh
echo "This is a dummy pre script"
]]>
       </source>
   </script>
<aiPreScript/>
</pre-scripts>
  1. post script 后脚本
<post-scripts config:type="list">
    <script>
        <filename>enable_reboot_on_panic.sh</filename>
        <source> <![CDATA[#!bin/sh
echo "This is a dummy post script"
]]>
       </source>
    </script>
</post-scripts>
  1. chroot 脚本
<chroot-scripts config:type="list">
    <script>
        <chrooted config:type="boolean">true</chrooted>
        <interpreter>shell</interpreter>
        <filename>disable-ipv6.sh</filename>
        <source>
          <![CDATA[
sysctl -w net.ipv6.conf.all.disable_ipv6=1;
echo "net.ipv6.conf.all.disable_ipv6=1" >> /etc/sysctl.conf;
]]>
        </source>
    </script>
</chroot-scripts>
使为SuSE Linux创建autoyast xml文件教程

在本文中,将介绍一些可以根据要求使用的 autoyast xml 文件和语法示例。

SLES 中的 AutoYast2 xml 仅在概念上类似于与 Red Hat 一起使用的 kickstart,这意味着它们都用于自动安装,但使用的语法和变量完全不同。

AutoYaST2 是一种无需用户干预即可自动安装一个或者多个 SUSE Linux 系统的系统。
AutoYaST2 安装是使用带有安装和配置数据的 AutoYaST 配置文件执行的。
该配置文件可以使用 AutoYaST2 的配置界面创建,并且可以在安装期间以不同方式提供给 YaST2.

配置常规选项(时区、键盘和鼠标)

常规选项包括与安装过程和已安装系统环境相关的所有设置。

mode 部分配置 AutoYaST 在确认和重新启动方面的行为。

  • 默认情况下,用户必须确认自动安装过程。此选项允许用户在提交之前查看和更改目标系统的设置并可用于调试。
  • 确认默认设置为“true”,以避免在初始系统设置后系统安排重新启动时递归安装。如果要执行完全无人值守的安装,则仅禁用确认。
  • 使用halt,我们会导致AutoYaST 在安装完所有软件包后关闭机器。机器不是重新启动到第二阶段,而是关闭。引导加载程序已安装,所有 chroot 脚本都已运行。
  • final_halt 和 final_reboot 已在 openSUSE 11.0 和 SLES11 中引入。在第 2 阶段结束时完成安装和配置后,我们可以重新启动或者停止机器。

将突出显示的值替换为黄色 o 配置键盘和语言值

<general>
      <clock>
        <hwclock>UTC</hwclock>
        <timezone>Asia/Calcutta</timezone>
      </clock>
      <keyboard>
        <keymap>english-us</keymap>
      </keyboard>
      <language>en_US</language>
      <mode>
     <halt config:type="boolean">false</halt>
        <forceboot config:type="boolean">false</forceboot>
        <final_reboot config:type="boolean">false</final_reboot>
        <final_halt config:type="boolean">false</final_halt>
        <confirm config:type="boolean">true</confirm>
        <second_stage config:type="boolean">true</second_stage>  
      </mode>
      <mouse>
        <id>probe</id>
      </mouse>
      <report>
        <messages>
          <show config:type="boolean">true</show>
          <timeout config:type="integer">10</timeout>
          <log config:type="boolean">true</log>
        </messages>
        <errors>
          <show config:type="boolean">true</show>
          <timeout config:type="integer">10</timeout>
          <log config:type="boolean">true</log>
        </errors>
        <warnings>
          <show config:type="boolean">true</show>
          <timeout config:type="integer">10</timeout>
          <log config:type="boolean">true</log>
        </warnings>
      </report>
    </general>

配置引导加载程序

autoyast xml 中的以下部分是强制性的,尽管可以相应地修改突出显示的值

<bootloader>
      <activate config:type="boolean">false</activate>
      <loader_type>grub</loader_type>
      <repl_mbr config:type="boolean">false</repl_mbr>
      <global>
        <boot_mbr config:type="boolean">true</boot_mbr>
      </global>
    </bootloader>

配置网络、DNS、路由

  • YaST 将保留安装期间创建的网络设置(通过 Linuxrc)和/或者将其与 AutoYaST 配置文件(如果已定义)中的网络设置合并。
  • AutoYaST 设置的优先级高于现有配置文件。
  • YaST 将从配置文件写入 ifcfg-* 文件而不删除旧文件。
  • 如果有空的或者没有 dns 和路由部分,YaST 将保留已经存在的值。否则将应用配置文件中的设置。

为了自动配置网络设置和激活网络,使用一个全局资源来存储整个网络配置。

在下面的语法中,我创建了一个带有 DNS 服务器和主机名的接口

<networking>
      <dns>
        <dhcp_resolv config:type="boolean">true</dhcp_resolv>
        <domain></domain>
        <hostname>onitroad</hostname>
        <nameserver>127.0.0.1</nameserver>
      </dns>
      <routing>
        <ip_forward config:type="boolean">false</ip_forward>
        <routes config:type="list">
         <route>
             <destination>default</destination>
             <device>-</device>
             <gateway>192.168.1.32</gateway>
             <netmask>-</netmask>
          </route>
        </routes>
      </routing>
      <interfaces config:type="list">
        <interface>
          <device>eth0</device>
          <startmode>onboot</startmode>
          <bootproto>static</bootproto>
          <ipaddr>192.168.1.10</ipaddr>
          <netmask>255.255.255.224</netmask>
        </interface>
      </interfaces>
    </networking>

配置NTP

使用以下语法,我们可以使用 NTP 服务器列表配置 NTP 客户端

<ntp-client>
      <configure_dhcp config:type="boolean">false</configure_dhcp>
      <peers config:type="list">
        <peer>
          <address>10.10.10.102</address>
          <initial_sync config:type="boolean">true</initial_sync>
          <options></options>
          <type>server</type>
        </peer>
        <peer>
          <address>10.10.10.104</address>
          <initial_sync config:type="boolean">true</initial_sync>
          <options></options>
          <type>server</type>
        </peer>
      </peers>
      <start_at_boot config:type="boolean">true</start_at_boot>
      <start_in_chroot config:type="boolean">true</start_in_chroot>
    </ntp-client>

创建用户

要创建用户使用语法,如下所述,使用加密密码及其登录 shell

<users config:type="list">
      <user>
        <encrypted config:type="boolean">true</encrypted>
        <home>/root</home>
        <shell>/bin/bash</shell>
        <user_password>/.b.X4RxPGnig</user_password>
        <username>root</username>
      </user>
    </users>

配置分区

要了解有关此处使用的每种语法的更多信息,我们可以遵循 SuSE 的教程。

在下面的示例中,我正在创建基于 LVM 的配置,其中包含 root、boot、swap 和一些其他数据分区

<partitioning config:type="list" >
<drive>
<initialize config:type="boolean">true</initialize>
<partitions config:type="list">
  <!-- part for boot -->
  <partition>
    <format config:type="boolean" >false</format>
    <partition_id config:type="integer" >131</partition_id>
   <filesystem config:type="symbol" >ext3</filesystem>
   <format config:type="boolean" >true</format>
    <mount>/boot</mount>
    <size>128M</size>
  </partition>
  <!-- part for root -->
  <partition>
    <format config:type="boolean" >false</format>
    <lvm_group>system</lvm_group>
    <partition_id config:type="integer" >142</partition_id>
    <size>max</size>
  </partition>
<!-- max alloc root 128 auto -->
    </partitions>
    <use>all</use>
</drive>
<drive>
  <device>/dev/system</device>
    <initialize config:type="boolean" >false</initialize>
    <is_lvm_vg config:type="boolean" >true</is_lvm_vg>
    <lvm2 config:type="boolean" >true</lvm2>
    <partitions config:type="list" >
      <!-- LV for root -->
      <partition>
        <filesystem config:type="symbol" >ext3</filesystem>
        <format config:type="boolean" >true</format>
        <lv_name>root</lv_name>
        <mount>/</mount>
        <partition_id config:type="integer" >142</partition_id>
        <size>800m</size>
      </partition>
      <!-- LV for tmp -->
      <partition>
        <filesystem config:type="symbol" >ext3</filesystem>
        <format config:type="boolean" >true</format>
        <lv_name>tmp</lv_name>
        <mount>/tmp</mount>
        <partition_id config:type="integer" >142</partition_id>
        <size>2048m</size>
      </partition>
      <!-- LV for var -->
      <partition>
        <filesystem config:type="symbol" >ext3</filesystem>
        <format config:type="boolean" >true</format>
        <lv_name>var</lv_name>
        <mount>/var</mount>
        <partition_id config:type="integer" >142</partition_id>
        <size>4096m</size>
      </partition>
      <!-- LV for opt -->
      <partition>
        <filesystem config:type="symbol" >ext3</filesystem>
        <format config:type="boolean" >true</format>
        <lv_name>opt</lv_name>
        <mount>/opt</mount>
        <partition_id config:type="integer" >142</partition_id>
        <size>2048m</size>
      </partition>
      <!-- LV for swap -->
      <partition>
        <filesystem config:type="symbol" >swap</filesystem>
        <format config:type="boolean" >true</format>
        <lv_name>swap</lv_name>
        <mount>swap</mount>
        <partition_id config:type="integer" >142</partition_id>
      </partition>
    </partitions>
    <pesize>32M</pesize>
    <use>all</use>
</drive>
</partitioning>

配置软件

我们可以提供要在安装过程中安装或者删除的 rpm 的自定义列表

<software>
      <kernel>kernel-default</kernel>
      <patterns config:type="list">
         <pattern>Minimal</pattern>
      </patterns>
      <packages config:type="list">
        <package>update-alternatives</package>
        <package>vim-base</package>
        <package>vim-data</package>
        <package>vim</package>
        <package>audit</package>
        <package>libltdl7</package>
        <package>openssh</package>
        <package>man</package>
        <package>man-pages</package>
        <package>openssl1</package>
        <package>libopenssl1_0_0</package>
        <package>quota</package>
      </packages>
      <remove-packages config:type="list">
        <package>mpt-firmware</package>
      </remove-packages>
</software>
日期:2020-06-02 22:17:23 来源:oir作者:oir