Centos 8 kickstart四, 13/08/2020 - 11:18 的修訂版本

修訂版本可以讓你追蹤文章的多個版本的不同之處。

最後更新: 2020-08-04

前言

Anaconda is a free and open-source system installer for Linux distributions.

It is mainly written in Python with some modules written in C.

 


anaconda-ks.cfg

 

After the installation completes, all choices made during the installation are saved into a file named anaconda-ks.cfg

 


Verify tools

yum install pykickstart

ksvalidator /path/to/kickstart.ks

 


ks.cfg

To load your Kickstart file automatically without having to specify the "inst.ks=" boot option

file ks.cfg and place it on a storage volume labeled OEMDRV

ls cd

ks.cfg

genisoimage -V OEMDRV -o ks.iso cd

 


Sections

 

Sections must be specified in order. Items within the sections do not have to be in a specific order unless otherwise specified.

 


Syntax Reference

 

---- Disk ----

ignoredisk (optional)

Causes the installation program to ignore the specified disks.

--only-use - Specifies a list of disks for the installation program to use. All other disks are ignored.

                  用唔到, 因為唔知會係 sda 還是 vda

i.e.

ignoredisk --only-use=vda

clearpart (optional)

Removes partitions from the system, prior to creation of new partitions. By default, no partitions are removed.

--none (default) - Do not remove any partitions.

--initlabel - Initializes a disk (or disks) by creating a default disk label for ALL disks

in their respective architecture that have been designated for formatting (for example, msdos for x86).

autopart (optional)

Automatically creates partitions:

  • a root (/) partition (1 GB or larger),
  • a swap partition, and
  • an appropriate /boot partition for the architecture.
  • On large enough drives (50 GB and larger), this also creates a /home partition.

The autopart option cannot be used together with the part/partition, raid, logvol, or volgroup

i.e.

# type: lvm, btrfs, plain, thinp

# plain: Regular partitions with no LVM or Btrfs

autopart --type=plain --nohome

Note

要配合 clearpart 使用

part (optional)

Syntax

part|partition mntpoint --name=name --device=device --rule=rule [options]

Example

part /boot --fstype="xfs" --size=200 --label="boot" --ondisk=vda
part biosboot --fstype="biosboot" --size=1 --ondisk=vda
part /boot/efi --fstype="xfs" --size=200 --label="efi" --ondisk=vda
part swap --fstype="swap" --size=2000 --label="swap" --ondisk=vda
part / --fstype="xfs" --size=2000 --label="centos8-root" --ondisk=vda

mntpoint

swap

The partition is used as swap space.

# To determine the size of the swap partition automatically

swap --recommended

biosboot

# The partition will be used for a BIOS Boot partition.

# A 1 MiB BIOS boot partition is necessary on BIOS-based AMD64 and Intel 64 systems using a GUID Partition Table (GPT);

# the boot loader will be installed into it. It is not necessary on UEFI systems.

/boot/efi

# An EFI System Partition.

# A 50 MiB EFI partition is necessary on UEFI-based AMD, Intel, and ARM; the recommended size is 200 MiB.

# It is not necessary on BIOS systems. See also the bootloader command.

--label=

assign a label to an individual partition.

--ondisk= or --ondrive=

Forces the partition to be created on a particular disk.

Note

用了 ignoredisk 就不用 "--ondisk=vda" 了

要配合 clearpart 使用

--------

bootloader (required)

mbr - The default option.

Depends on whether the drive uses the Master Boot Record (MBR) or GUID Partition Table (GPT) scheme:

  •  On a GPT-formatted disk, this option will install stage 1.5 of the boot loader into the BIOS boot partition.
  •  On an MBR-formatted disk, stage 1.5 will be installed into the empty space between the MBR and the first partition.

i.e.

bootloader --location=mbr

eula (optional)

Use this option to accept the End User License Agreement (EULA) without user interaction.

eula --agreed

firewall

--remove-service

firstboot

Determine whether the Initial Setup application starts the first time the system is booted.

If enabled, the "initial-setup" package must be installed.

-----

UI: graphical(default), text, or cmdline

graphical (optional)

Perform the installation in graphical mode.

text (optional)

Perform the Kickstart installation in text mode.

cmdline (optional)

Perform the installation in a completely non-interactive command line mode.

Any prompt for interaction halts the installation.

-----

Install (optional)

You must specify the type of installation from cdrom, harddrive, nfs, liveimg, or url

-----

%addon com_redhat_kdump (optional)

%addon com_redhat_kdump --disable --reserve-mb='auto'
%end

keyboard (required)

keyboard --vckeymap=us --xlayouts='us'

lang (required)

lang en_US.UTF-8

network (optional)

network  --bootproto=dhcp --device=ens4 --nameserver=8.8.8.8,8.8.4.4 --noipv6 --activate

network  --hostname=c8

network --bootproto=static --ip=192.168.88.126 --gateway=192.168.88.1 --netmask=255.255.255.0 --nameserver=192.168.88.1

--device=em1

specifies the device to be configured

If the --device= option is missing on the first use of the network command,

the value of the ksdevice= Anaconda boot option is used, if available.

part or partition (optional)

Creates a partition on the system.

# Device names in the sdX (or /dev/sdX) format are not guaranteed to be consistent across reboots

part / --fstype=xfs --onpart=sda1

# 所以要用

part / --fstype=xfs --onpart=/dev/disk/by-path/pci-0000:00:05.0-scsi-0:0:0:0-part1

OR

part / --fstype=xfs --onpart=/dev/disk/by-id/ata-ST3160815AS_6RA0C882-part1

Other Opts

--label= - assign a label to an individual partition.

reboot (optional)

Normally, Kickstart displays a message and waits for the user to press a key before rebooting.

reboot --eject

reboot --kexec        # 唔 work

rootpw (required)

Sets the system 's root password to the password argument.

rootpw --plaintext xxxx

selinux (optional)

selinux --disabled

services (optional)

services --disabled="chronyd"

timezone (required)

i.e.

# --nontp - Disable the NTP service automatic starting.

timezone Asia/Hong_Kong --isUtc --nontp

timezone --ntpservers=stdtime.gov.hk

user (optional)

Creates a new user on the system.

vnc (optional)

Allows the graphical installation to be viewed remotely through VNC.

skipx (optional)

If present, X is not configured on the installed system.

 


自動安裝 Package

 

repo (optional)

Configures additional yum repositories that can be used as sources for package installation.

i.e.

repo --name="Minimal" --baseurl=file:///run/install/repo/MyPackage

Remark:

Kickstart ISO Path: CD 的 "/" => "/run/install/repo"

Package Selection

# Specifying Individual Packages

 * 當 repo 沒有此 package 時就會 error

%packages
sqlite
curl
aspell
%end

More Info.

Link

 


Custom ISO

 

mkdir -p /home/myiso/unzip

cd /home/myiso/unzip

7z x /path/to/CentOS-8.2.2004-x86_64-minimal.iso -o.

cp ~/anaconda-ks.cfg /ks.cfg

yum install -y pykickstart

ksvalidator ~/ks.cfg

Add label to isolinux/isolinux.cfg

label Kickstart
menu label Kickstart
menu default
kernel vmlinuz
append initrd=initrd.img inst.stage2=hd:LABEL=CentOS8_x86_64 inst.ks=cdrom:/dev/cdrom:/ks.cfg net.ifnames=0 biosdevname=0

Build ISO

genisoimage -o ../centos8-custom.iso \
-boot-load-size 4 -boot-info-table -J -r -R -T \
-V 'CentOS8_x86_64' \
-no-emul-boot -b isolinux/isolinux.bin -c isolinux/boot.cat \
-eltorito-alt-boot  \
-no-emul-boot -eltorito-boot images/efiboot.img ./

 


Script

 

  • %pre ... %end
  • %post ... %end

%post

Copy file to new system

--nochroot

The post-install script is run in a chroot environment, therefore, performing tasks such as copying scripts or

RPM packages from the installation media do not work by default.

--interpreter

Default: bash

%post --interpreter=/usr/bin/python
--- Python script omitted --
%end

Path

  • CD 的 '/'        /run/install/repo
  • SYS 的 '/'       /mnt/sysimage
%post --nochroot
cd /mnt/sysimage
cp /run/install/repo/files/.screenrc /root
cp /run/install/repo/files/.vimrc    /root
rm -f /root/anaconda-ks.cfg  /root/original-ks.cfg
%end

%pre

# Determine disk type for clearpart on kickstarts (sda / sdb)

 


kickstart run script after reboot

 

# By cron job

/etc/crontab

...
@reboot /root/firstboot > /var/log/firstboot.log 2>&1

/root/firstboot

# Cleanup job
grep -v firstboot /etc/crontab > /etc/crontab.tmp
mv -f /etc/crontab.tmp /etc/crontab
service cron restart

# do something
...

# By Service

在 ks.cfg 的 %post Section 加入以下設定

Prior to Red Hat Enterprise Linux 7:

touch /tmp/runonce
cat << EOF >> /etc/rc.local
#!/bin/bash
if [ -e /tmp/runonce ]
then
   rm /tmp/runonce
   exec > /root/runonce.log 2>&1
   /path/to/my/script      # 此 script 要做 cleanup jobs, 比如清 /etc/rc.local
fi
EOF

Red Hat Enterprise Linux 7 and later:

cat << EOF > /etc/systemd/system/runonce.service
[Unit]
Description=Run once
Requires=network-online.target
After=network-online.target

[Service]
ExecStart=/root/runonce.sh

[Install]
WantedBy=multi-user.target
EOF

chmod 664 /etc/systemd/system/runonce.service

systemctl enable runonce