admin管理员组

文章数量:1595683

Kickstart文件的编写

荣涛
2022年1月27日

文档修改日志

日期修改内容修改人备注
2022年1月27日创建荣涛
2022年2月11日用户荣涛
2022年2月14日分区荣涛

Kickstart简介

Kickstart提供了一种可以部分或完全自动化安装OS过程的方法。由红帽创建。

Kickstart文件包含部分或全部OS安装选项。例如,时区、应该如何分区驱动器,或者应该安装哪些包。提供一个准备好的Kickstart文件就可以在不需要任何用户干预的情况下进行安装。这在同时在大量系统上部署OS时特别有用。

Kickstart可以使用本地DVD,本地硬盘,或者NFS,FTP,HTTP(s)。

自动化安装流程

  1. 创建Kickstart文件;
  2. 使Kickstart文件可用;
  3. 创建可启动介质/安装源或PXE;
  4. 使安装源可用;
  5. 使用ks文件和启动介质安装;

使用Kickstart文件

/var/lib/tftpboot/pxelinux/pxelinux.cfg/default配置文件对应位置添加inst.ks=http://192.168.122.174/kickstart/cclinux-2203-x86_64.cfg选项。

视kickstart配置文件在具体HTTP服务器中的位置而定。

创建Kickstart文件

Chapter 4, Creating Kickstart files.

可以使用下面的方法获取ks文件:

  • 使用在线配置工具;
  • 拷贝ks文件;
  • 手动编写ks文件;
  • 从低版本转换;
  • 虚拟化环境,创建自定义OS镜像,是哦那个Image Builder。

在线生成kickstart文件

访问红帽Kickstart Generator

手动编写Kickstart文件

依照红帽Kickstart Generator作为目录结构,并添加一些补充。

1. 基本配置

1.1. 默认语言

# 美国英文
lang en_US
lang en_US.UTF-8
# 简体中文
lang zh_CN
lang zh_CN.UTF-8

1.2. 键盘

keyboard us

1.3. 时区

--isUtc表示是否使用UTC

timezone Asia/Shanghai --isUtc
timezone Asia/Shanghai --utc

1.4. root用户密码

rootpw $2b$10$xtBFXV8dXm5y1Cz0vEnKSODi4eGUgtmapMGHEe7icZL/qyNVrOO/C --iscrypted
# 锁定
rootpw --iscrypted --lock $6$rMt1qgFxWxQ//N2X$SJlNvEJDVEx7fMWfgBWDsyczBtRmueR820jR5Gd/fDrjibR/o65t3KKv/4dM47dDwrFacsfwiZcch6xpIUJ1I0

1.5. 创建用户

语法:

user --name=username [options]

示例:

# 创建用户rongtao
user --groups=wheel --name=rongtao --password=$6$hTwcIUUv.UAuaAbW$Ceb8LL.I.hgmWnvAt9t8olV0N8c18xUgBNXM5qxuJvhnkMH9tU9pUVLDUNQ0MyC.8UCqVe9hn0VFeoEszsWAI/ --iscrypted --gecos="rongtao"

更多参数:

  • –name= – Provides the name of the user. This option is required.
  • –gecos= – Provides the GECOS information for the user. This is a string of various system-specific fields separated by a comma. It is frequently used to specify the user’s full name, office number, and so on. See the passwd(5) man page for more details.
  • –groups= – In addition to the default group, a comma separated list of group names the user should belong to. The groups must exist before the user account is created. See the group command.
  • –homedir= – The home directory for the user. If not provided, this defaults to /home/username.
  • –lock – If this option is present, this account is locked by default. This means that the user will not be able to log in from the console. This option will also disable the Create User screens in both the graphical and text-based manual installation.
  • –password= – The new user’s password. If not provided, the account will be locked by default.
  • –iscrypted – If this option is present, the password argument is assumed to already be encrypted. This option is mutually exclusive with –plaintext.
  • –shell= – The user’s login shell. If not provided, the system default is used.
  • –uid= – The user’s UID (User ID). If not provided, this defaults to the next available non-system UID.
  • –gid= – The GID (Group ID) to be used for the user’s group. If not provided, this defaults to the next available non-system group ID.
1.5.1. root用户密码

语法:

rootpw [--iscrypted|--plaintext] [--lock] password

直接设置

rootpw "password here"

或者使用哈希值

rootpw --iscrypted "password_hash"

这个hash值的生成方式

MD5

$ openssl passwd -1
Password: 输入
Verifying - Password: 确认输入
$1$HJt71Ctj$OLbT94PMwQz8XXkBn6fZB/

sha256

$ openssl passwd -5
Password: 输入
Verifying - Password: 确认输入
$5$UTlAHAYXij9kL0ID$nJazXmEI8aYV0b3iYv6WxPKjMuz6dISH0LyvWK6v2h1

sha512

$ openssl passwd -6
Password: 输入
Verifying - Password: 确认输入
$6$7OSrg1wIHvakPCs3$EdBenUucQ17Hv1TX2CbO/mfOqmjTP1mAnQSmrg7d9WlA/ZVYzzf934ZP1e9FWWW5EquAkVF/qkzt4ATWu29Cf0
1.5.2. 设置用户sshkey公钥
# 创建用户示例
user --name=myuser
# 为这个用户设置key
sshkey --username=myuser "ssh-pub-key-value"

密钥对通过ssh-keygen -t rsa -C "rongtao@email"命令生成,"ssh-pub-key-value"对应生成的~/.ssh/id_rsa.pub文件内容。

  • 一个设置密码并且设置密钥的示例
# Users
# 锁定 root
rootpw --lock
# 创建 rongtao 用户,并设置密码 `123456`
# Use `openssl passwd -6` generate password sha512 hash value
user --groups=wheel --name=rongtao --password=$6$7vfYx9tPGWjTcW8T$bwVWM0Rm71BBXTZuZIN/S1whb8PsHzoGuXuscNXGLdEB9ExIC5HXNgGY2UBFkGnCBgrlsRD2Kf
s32kZ2HFZmX1 --iscrypted --gecos="rongtao"
# 为 rongtao 用户设置密钥
sshkey --username=rongtao "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDCbEJ7XaCB1DuMLRktuWatB9J9eNXswAGh7slMyOWLEQR3+ueAjMlzJCYHY9RhpjL8ZwCt441LFubCKr1Qf8OIaG0fk2xezqRE5E1597MWG5Q7vBPNwM80T6rVmfk8KRowJHKkFYRuzivlatDBrn8M+BYgrAe7YEDm1t7SGL0BXmFaXLvfcll9B8FQas6d7utfzwYYZiXJJWC/MinEG+lLmld9MnbVg89gpN14fKH6Wxro/naE6zBysvog2UvveBtd2irunlfxessEcAVsh3p7n8TdzIg7Rn9o86uzmwt5oBnYXP6XtGBwSkrDre7NgcN9yhO52aS5QHjxW/Enblk6zSPfkQPQe64J/PO2m0bL6PIPaBagA5Uj3CD+XoUdxjc1n50NaVuIMrc2BtN4sOtN3AQ1zZ7fxNjw3/lYDzjfhwUgjXxyg26D6W83crscEcW7I7hhNkqKWKgjO6jjfLJI/lQrCgPRTKUikuy1IHBRr1wUpQJUU4jHBwGByM+7c2c= rongtao@???"

1.6. 目标架构

1.7. 安装后是否重启

reboot

1.8. 使用图形模式安装

graphical

1.9. 使用text模式安装

text

2. 安装

2.1. 安装源和安装树的位置

# DVD安装
cdrom
# http
url --url=http://192.168.122.22/CCLinux-2203-x86_64-rc1/
# ftp
url --url=ftp://192.168.122.22/CCLinux-2203-x86_64-rc1/
# nfs
nfs --server=nfs://nfstest --dir=/CCLinux-2203-x86_64-rc1
# harddrive
harddrive --partition=/dev/sda1 --dir=/CCLinux-2203-x86_64-rc1

3. 分区

3.1. 清理主分区记录

zerombr

3.2. 移除现存分区和初始化磁盘标签

clearpart --all --initlabel

3.3. 忽略磁盘

# 仅仅使能 vds
ignoredisk --only-use=vda

3.4. 使用自动分区

autopart

3.5. 自定义分区

参数如下:

  • –type=
  • –fstype=
  • –nohome
  • –nolvm
  • –encrypted
  • –passphrase=
  • –escrowcert=URL_of_X.509_certificate
  • –backuppassphrase
  • –cipher=

一个分区示例

# Disk partitioning information
part / --fstype="xfs" --ondisk=sda --size=1142902
part /boot --fstype="ext4" --ondisk=sda --size=1024
part /boot/efi --fstype="efi" --ondisk=sda --size=200 --fsoptions="umask=0077,shortname=winnt"

4. BootLoader

4.1. Grub密码

bootloader --append="rhgb quiet crashkernel=auto" --iscrypted --password=grub.pbkdf2.sha512.10000.A98B43E3F163821C5395AAD07FD44FA508AE0FB6A55873FACD49228D90496A9012033FEEAC0E795ACAEB71F5B3DEB2D9B69323A43DBD2D5DA6309967188BE347.6F792B5C7DEF1865B82F44A100FC398032CA3C8D51A5BD856D87D19FFE31DC81FCEF452ABCD125074D844F706E9F88592ECEF99BF625DB6631D5D9EB25E88330

4.2. 使用UEFI

4.3. 内核参数

bootloader --append="rhgb quiet crashkernel=auto"

5. 数据包

根据架构不同,发行版不同,安装包差异也比较大。

%packages
@^graphical-server-environment
@debugging
@network-server
@performance
@remote-desktop-clients
@virtualization-tools
%end

数据包graphical-server-environmentAppStream/comps.xml中定义,这是repodata数据。

5.1. CentOS-Stream-9数据包类型

具体参见ISO中comps.xml文件。

6. 身份验证

6.1. 密码算法

auth --passalgo=sha512 --useshadow

7. 网络

7.1. 使用默认网络DHCP

8. 安全

8.1. SELinux

是否激活

selinux --enforcing
selinux --permissive
selinux --disabled

8.2. 使能防火墙

是否允许http,ftp,smtp,ssh;
允许其他端口;

firewall --enabled --http --ftp --smtp --ssh --port=1234,2345,3456

9. 展示Display

不安装图形环境(skipx)

skipx

第一次启动,指定agent

firstboot --enable
firstboot --disable

10. 安装前脚本

%pre
#!/bin/bash
ls
%end

11. 安装后脚本

%post --interpreter=#!/bin/bash
#!/bin/bash
echo hello world > /hello.txt
%end

12. 一个完成的示例

# Generated by Anaconda 34.25.0.17
# Generated by pykickstart v3.32
#version=RHEL9
# Use graphical install
graphical

# http installation source
url --url=http://192.168.122.22/CCLinux-2203-x86_64-rc1/

%addon com_redhat_kdump --enable --reserve-mb='auto'

%end

# Keyboard layouts
keyboard --xlayouts='cn'
# System language
lang zh_CN.UTF-8

# Use CDROM installation media
#cdrom

# Reboot after installation
reboot

%packages
@^graphical-server-environment
@debugging
@network-server
@performance
@remote-desktop-clients
@virtualization-tools

%end

# Run the Setup Agent on first boot
firstboot --enable

# Generated using Blivet version 3.4.0
ignoredisk --only-use=vda
autopart
# Partition clearing information
clearpart --none --initlabel

# System timezone
timezone Asia/Shanghai --utc

# Root password
rootpw --iscrypted --lock $6$rMt1qgFxWxQ//N2X$SJlNvEJDVEx7fMWfgBWDsyczBtRmueR820jR5Gd/fDrjibR/o65t3KKv/4dM47dDwrFacsfwiZcch6x
pIUJ1I0
user --groups=wheel --name=rongtao --password=$6$hTwcIUUv.UAuaAbW$Ceb8LL.I.hgmWnvAt9t8olV0N8c18xUgBNXM5qxuJvhnkMH9tU9pUVLDUNQ
0MyC.8UCqVe9hn0VFeoEszsWAI/ --iscrypted --gecos="rongtao"

selinux --permissive
firewall --enabled --http --ftp --smtp --ssh --port=1234,2345,3456

%pre
#!/bin/bash
echo ">>>>>>>>>>>>>> Just Do It <<<<<<<<<<<<<"
%end

%post --interpreter=/bin/bash
#!/bin/bash
echo hello world > /hello.txt
%end

参考链接

  • KICKSTART SYNTAX REFERENCE

Copyright (C) ???Com.

本文标签: 文件kickstart