Basic Linux Tutorial: Automatic Installation of Linux Kickstart

Source: Internet
Author: User

Basic Linux Tutorial: Automatic Installation of Linux Kickstart

Starting from system installation

In systems such as RHEL, CentOS, and Fedora, the program used to install the system is named anaconda. It is a FedoraProject developed by Python and can provide graphic or text interfaces for system installation.

Before installing the system, there may be no operating system on the computer's hardware. Therefore, to run the installation program, a temporary operating system is required to boot the system and start the installation program, when you use a CD to install an operating Linux system (specifically the RHEL series system), there are two phases: boot and installation.
 
Stage 1

When using the CD boot, the system boot process is POST (power-on self-check) ---> BIOS hardware detection and loading the MBR of the CD ---> the boot program of the CD is isolinux. bin, which is based on isolinux. cfg generates a menu. After you choose to install the operating system, the boot program loads the kernel (vmlinuz) and initrd. img file, initrd. img generates a temporary operating system in the memory to provide an installation environment for the installation process. After the system switches to the initrd file system. the init process in img calls the/sbin/loader program, loader detects the installation media, and loads the CD/images/stage2.img (in RHEL6, it is called install. img), switch to stage2, stage2.img file system type is suqashfs, the installation system program anaconda contains.

Stage 2

Stage2.img is a SquashFS file system, which contains the installer anaconda and its configuration file. Anaconda provides a configuration interface for the installation process. It provides installation management methods such as text and graphics, and supports scripts such as kickstart to provide automatic installation. After the system is installed, the/root/anaconda-ks.cfg configuration information is automatically generated, which records the option selected by the installation system to facilitate automatic later installation.
 
The following is the menu interface of stage 1 during CentOS 6 installation:

The options in this menu are all set by the/isolinux. cfg file on the CD. On the menu interface, Press Esc to enter the command line mode and enter linux. The effect is equivalent to the first option in the menu, that is, to install the Linux operating system.

In the command line interface, you can also use other commands:
Network Configuration:
Ip = IPADDR
Netmask = MASK
Gateway = GATEWAY
Dns = DNS_IP
Ifname = NAME: MAC_ADDR

Specify the kickstart file path
Ks = cdrom:/path/to/ks. cfg
Ks = http: // server/path/ks. cfg
Ks = ftp: // server/path/ks. cfg
Ks = nfs: server:/path/ks. cfg

Dd: load the required driver

The ks command can specify the path of a kickstart configuration file. anaconda can automatically install the Operating System Based on the configuration of the kickstart file.

Kickstart

In general system installation, You need to manually select various system installation options. the kickstart file defines the options to be selected for these system installation. After anaconda reads the kickstart file, you can install the system based on the File Settings, without manually selecting the installation configuration.

The Kickstart file can be obtained through the network during installation. It supports http, ftp, nfs, and other protocols. It can also store the kickstart file in the installation media (such as a CD image ), read from the CD during installation.

Create a kickstart File

After the general system installation is complete, anaconda will generate a kickstart file with the same setup as this installation, which is located in the/root/anaconda-ks.cfg, you can modify this file for future use.

The RHEL system also provides a graphical system-config-kickstart tool to configure the kickstart file. You can select the installation option on the GUI and save the result as a kickstart file.

The kickstart file consists of three parts:

Command segment

Command segments can be divided into required commands and optional commands.

Required command
Keyboard us # keyboard type settings
Lang en_US # Language settings
Timezone [-- utc] Asia/Shanghai # Time Zone Selection
Reboot | poweroff | halt # operations after system installation (restart or shutdown)
Selinux -- disabled | -- permissive # Whether selinux is enabled
Authconfig -- useshadow -- passalgo = sha512 # system authentication method. Here, select password authentication. the encryption algorithm is sha512.
Rootpw -- iscrypted... # Encrypted root Password
Bootloader -- location = mbr -- driveorder = sda # the position where bootloader is installed. Select here to install it in mbr.

Optional commands
Install | upgrade # install/upgrade the Operating System
Url -- url =... # specifies that the system is installed through the FTP or HTTP path of the remote host.
Firewall -- disabled | -- enabled # Enable firewall
Firstboot -- disabled | -- enabled # whether the user configuration is performed after the system is started for the first time
Text | graphical # The installation page is text/graphic
Clearpart -- linux | -- all # which partitions of the system are cleared before installation. -- all indicates that all partitions are cleared.
Zerombr # this option must be added when clearpart -- all is used. Otherwise, the installation process will be paused and you must manually select
Part # partition settings
Part swap -- size = 2048 # example of swap partitioning
Part/boot -- fstype ext4 -- size = 100000 # example of partitioning/boot
Part pv. <id> -- size =... # create a PV
Volgroup vgname pvname # create VG
Logval/home -- fstype ext4 -- name = home -- vgname = vgname -- size = 1024 # example of creating a logical volume
% Include # The contents of other files can be included in the kickstart file. The files must be accessible during system installation.

Software Package selection segment

The software package to be installed is defined here. The package group starts with @. You can also specify a single package name, for example:
% Packages
@ Base
@ Core
@ Base
@ Basic-desktop
@ Chinese-support
@ Client-mgmt-tools
@ Core
@ Desktop-platform
@ Fonts
@ General-desktop
@ Graphical-admin-tools
@ Legacy-x
@ Network-file-system-client
@ Perl-runtime
@ Remote-desktop-clients
@ X11
Lftp
Tree
% End

Script segment

Script allocation prefix and post-installation script

% Pre indicates the pre-installation script. In this case, the Linux system environment is a micro-version environment, and the script should be as simple as possible.

The script here is usually used to query some system information, and then dynamically set the installation configuration based on the information, such as using the following script
% Pre
# Set the partition configuration. The swap size is 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

This script is executed before the system is installed. It queries the system memory size and generates partition commands Based on the memory size, which are stored in the/tmp/partitoin. ks file.

Then include the partition. ks file in the kickstart file to dynamically set the partition size:
% Include/tmp/partitions. ks

% Post indicates the script after installation. At this time, the Linux system environment is a system that has been installed.

The script can be configured after system installation, such as public key injection, repository configuration, third-party software installation, and modification of system service configuration files.

Create a boot Disc

As mentioned above, system installation is divided into two editions: boot and installation. On the installation CD of CentOS 6, the/isolinux directory stores the boot program for guidance. It is responsible for guiding the system, loading a kernel, entering the temporary system, and starting the anaconda installation program. Then, the installer will perform some initial settings on the system to install the user program software package.

Then, you can create a boot CD, which is only responsible for system boot, and all the installation trees required for installing the system are stored in the remote host. The CD can also contain a kickstart file, modify the boot menu option so that it will be automatically installed using the kickstart file during installation.

The production process is as follows:
1. Prepare a working directory, such as/tmp/iso
2. Copy the/isolinux directory on the system installation disc to the/tmp/iso directory.
3. Add the pre-created kickstart file to the/tmp/iso directory.

4. Edit the/tmp/iso/isolinux. cfg file so that it can directly use the kickstart configuration file during installation.

Find the label linux menu item in the file and add ks settings after the append Command, for example:
Label linux
Menu label ^ Install or upgrade an existing system
Menu default
Kernel vmlinuz
Append initrd = initrd. img ks = cdrom:/ks. cfg


5. Create an iso image:
Mkisofs-R-J-T-v -- no-emul-boot -- boot-load-size 4 -- boot-info-table
-V "CentOS 6.6 X86_64 boot disk"-B isolinux/isolinux. bin-c isolinux/boot. cat-o/root/boot. iso cdrom/

Then you can use the boot. iso image to install the operating system. Of course, you must be able to access the remote host with the installation tree through the network during installation.

----------------------------- Split line -----------------------------

Use PXE + DHCP + Apache + Kickstart to install CentOS5.8 x86_64

Linux PXE unattended installation of PXE-E32: TFTP OPen timeout Solution

Use PXE and kickstart to automatically install Linux

RHCE-certified unattended Linux system installation (FTP + TFTP + DHCP + Kickstart + PXE)

PXE network installation (on-duty and unattended installation)

----------------------------- Split line -----------------------------

This article permanently updates the link address:

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.