Kickstart automated installation tutorial in Linux

Source: Internet
Author: User
Tags centos


In systems such as Rhel,centos,fedora, the installation system uses the program named Anaconda, which belongs to the Fedoraproject, developed by Python and can provide graphics or text interfaces for system installation. The Anaconda Installer has the greatest advantage: it can be used as a Kickstart
Features for non-interactive scripting installations. The Kickstart script is a simple ASCII text file that specifies the details of the installation requirements. The script can be written in a regular text editor or generated using the Kickstart configuration program.

The Kickstart script usually has three different parts.

Command section
Package section
Script section
Anaconda ignores all rows and blank lines that start with "#" in the Kickstart script.

I. Grammatical structure of Kickstart

1. Command part

This section is part of the command, from the beginning of the file to the line beginning with%packages. The command line must start with a recognizable keyword, and all parameters related to that keyword must appear in the same row. The commands section is used to specify all the standard information that Setup requires, except software options. The keywords can appear in any order in the command section.

In this part of the general we will specify the installation source, partition information, firewalls, user groups, and so on. As follows:

# Keyboard Type setting
Keyboard US
# language Settings
Lang en_US
# time zone, NTP server and hardware clock settings
TimeZone [--UTC] Asia/shanghai--ntpservers=ntp1.aliyun.com
# operation after system installation (reboot or shutdown)
Reboot | Poweroff | Halt
# whether to enable SELinux
SELinux--enforcing | --disabled
# Authentication Mode of the system, here Select Password Authentication encryption algorithm SHA512
Authconfig--useshadow--passalgo=sha512
# password set, plaintext or encrypted root password
ROOTPW--plaintext 361way or
ROOTPW--iscrypted Cipher String
# Install/Upgrade operating system
Install | Upgrade
# indicates the installation source or installation media, such as FTP or HTTP path
URL--url= ....
# whether to turn on the firewall
Firewall--disabled | --enabled--service=ssh,cups
# whether the user is configured after the first boot of the system
Firstboot--disabled | --enabled
# Installation interface for text/graphics
Text | Graphical
#允许通过vnc远程查看图形安装
VNC--password=361way
# bootloader Installation location, choose to install to MBR
Bootloader--LOCATION=MBR--BOOT-DRIVE=SDA
# which partitions of the system are cleared before installation,--all indicates that all partitions are cleared
Clearpart--all--drivers=sda,sdb--initlabel
# when using Clearpart--all, you need to add this option, otherwise the installation process will be paused, you need to manually select
Zerombr
# Ignoredisk The specified disk during installation
Ignoredisk--DRIVES=SDC
# Partition settings
Part
Part Swap--size=2048 # example of partitioning a swap
Part/boot--fstype Ext4--size=100000 # Example of partitioning/boot
Part pv.01--size=8192 # Create a PV
Volgroup vgname pvname # Create VG
Logval/home--fstype ext4--name=home--vgname=vgname--size=1024 # Example of creating a logical volume
# Network configuration and activation of network devices
Network--drive=eth0--BOOTPROTO=DHCP
# Default Service configuration
Services--disabled=networkmanager,ip6tables--enabled=network,iptables
# Create Local Users and groups
Group--name=admins--gid=10001
User--NAME=YBK--gecos= "itybku"--groups=admins--password=test--plaintext
# Specifies how anaconda will be logged during installation
Logging--hosts=www.361way.com--level=info
#firstboot confirm that Firstboot is started when the system first starts
Firstboot--disabled
# You can include the contents of other files in the Kickstart file, including files that you can access during the installation system
%include file name

2. Package part (%packages)

Part of the package is used to specify the software that needs to be installed. This section begins with the line beginning with%packages until the next behavior begins with the "%" character. This section usually takes one of the following two formats.

@ Component Name
Package-name

The first format is to use software groups to specify the software, where you must pay attention to the correct spelling of the software group name, and attention to case.

The second format is used to specify the specific name of the package to be installed. If the%packages row contains additional--resolvedeps parameters, a package that resolves dependencies is also installed.

Note: Use a dash (-) start to specify a package or group that is not used in the installation.

Examples are as follows:

%packages
@base
@core
@chinese-support
@fonts
Chrony
Rsync
Grub2
Firewalld
-networkmanager
-autofs

3, Script part

The script section is divided into the pre-installation script (pre) and the post-installation script (POST). This part must begin with%pre or%post, ending with%end. The order of the two is not related. One difference is that the preinstallation scripts do not run in the chroot environment.

In the official document, take the partition section for this part of the example, here I found a more appropriate example--swap partition settings. Swap partitions generally need to be defined by the size of physical memory, which can be written to the%pre section. As follows:

%pre represents the pre-setup script, where the Linux system environment is a miniature environment and the script should be as simple as possible. The script here is usually used to query some system information and then install the configuration according to the dynamic settings of the information.

%pre
# Set the configuration of the partition and configure the swap size to be the same as the memory size
#!/bin/sh
Act_mem= ' Cat/proc/meminfo | grep memtotal | awk ' {printf ('%d ', $2/1024)} '
echo "" >/tmp/partition.ks
echo "Clearpart--all--initlabel" >>/tmp/partition.ks
echo "Part/boot--fstype=ext3--asprimary--size=200" >>/tmp/partition.ks
echo "part swap--fstype=swap--size=${act_mem}" >>/TMP/PARTITION.KS
echo "part/--FSTYPE=EXT3--grow--size=1" >>/tmp/partition.ks
%end
%include/tmp/partitions.ks
%post represents the Post installation script, at which point the Linux system environment is already installed to complete the system. The script here can be configured after some system installation, such as public key injection, warehouse configuration, third party software installation, system service configuration file modification, etc. Here's a simple example:

%post--erroronfail
Rm-f/etc/udev/rules.d/70*
Cat >/etc/sysconfig/network-scripts/ifcfg-eth0 <<eof
Device=eth0
Onboot=yes
Bootproto=static
ipaddr=10.144.189.71
netmask=255.255.240.0
Eof
%end

Second, KS file generation verification and other

1, the generation of ks.cfg files

Ks.cfg files can be more cumbersome to write directly, but the system provides us with two quick ways to get the file.

Method 1: Custom installed Os/root directory will have a anaconda-ks.cfg file generation, directly can be copied a copy of the file for editing;

Method 2: Generate the profile using a graphical GUI program. Redhat/centos has a System-config-kickstart package, installed after the start of the 5 level to open the program, you can fool the next step to create a custom build the file.

Note:

A, the General people I don't tell him---------------------------------------ks.cfg files can be generated by using the following terminal commands without graphics. Anaconda-ks.cfg more content).

[Root@361way ~]# System-config-kickstart--generate/tmp/test.cfg
B, System-config-kickstart does not support the generation of advanced KS configurations, such as LVM, soft raid, and so on.

2, the verification of KS documents

The Yum source has a Python-written toolkit pykickstart that contains several more useful tools, including ksvalidator for the KS Syntax Verification tool, as follows:

[Root@361way ~]# Ksvalidator/tmp/anaconda-ks.cfg
The problem occurs on line 16th of the Kickstart file:
Unknown command:netwrk
The network section of the above configuration file I removed a letter o, and it mentions what went wrong in a row. If there is no output after execution, the file has no syntax errors.

3, Rhel 7 changes in relation to Rhel 6

The syntax of the kickstart file has also changed in some ways because RHEL7 has changed a lot compared to previous versions. The difference is not to worry about. The Ksverdiff in the Pykickstart Toolkit can help us understand the difference between the two, as follows:

[Root@361way ~]# Ksverdiff--help
Usage:ksverdiff [Options]
Options:
-H,--help show this Help and exit
F,--from=f
-T,--to=t
[Root@361way ~]# ksverdiff-f rhel6-t rhel7
The following command is removed in RHEL7:
Monitor Interactive
The following commands are not recommended in RHEL7:
Upgrade
The following command is added in RHEL7:
Btrfs Realm EULA Liveimg
The following options are added to Logvol, in RHEL7:
--metadatasize--thin--thinpool--chunksize--label--resize
The following options are removed from the Logvol in RHEL7:
--bytes-per-inode
The following options are added to firewall, in RHEL7:
--remove-service
The following options are removed from the firewall in RHEL7:
--telnet
........................ Omitted
4. Summary of common items

Kickstart configurable items are more, but most of them are fixed in the enterprise usage scenario, and some of the more important configurations that we typically need to focus on when installing are:

%packages
Auth
Url
%post
Clearpart
Services
Rootpw
Part
TimeZone
Network

Third, the use of KS file installation

I've been in the pre-KVM virtualization Summary (c) The Guest installation section has already mentioned examples of using KS files for installation, and here is an example of installing a virtual machine in a KVM to automate the installation of the OS with the following reference to the KS part.

Virt-install-n RHCE--hvm-r 2048 \
--vcpus=2--os-type Linux--os-variant=rhel7 \
--network bridge=br0--nographics \
--location= ' Http://192.168.0.102/centos7 '
--extra-args= ' ks=http://192.168.0.102/kvm_rhel7.ks ksdevice=eth0 ip=192.168.0.120 netmask=255.255.255.0 dns= 8.8.8.8 gateway=192.168.0.1 text console=tty0 console=ttys0,115200n8 serial ' \
--disk path=/data/img/rhce/centos7.img,size=30
Of course, the actual application, not limited to the installation of virtual machines, the same applies to the installation of physical machines. And in many automated installation scenarios like cobbler, it's also a solution to the two-time encapsulation of KS.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.