• VMware

    Learn about VMware virtualization for its products like vsphere ESX and ESXi, vCenter Server, VMware View, VMware P2V and many more

  • Linux

    Step by step configuration tutorials for many of the Linux services like DNS, DHCP, FTP, Samba4 etc including many tips and tricks in Red Hat Linux.

  • Database

    Learn installation and configuration of databases like Oracle, My SQL, Postgresql, etc including many other related tutorials in Linux.

  • Did you find what you needed?
    Show your support and gratitude by making a contribution!!
    Life always offers you a second chance ... Its called tomorrow !!!

    Saturday, July 29, 2017

    Sample kickstart configuration file for RHEL/Centos 7

    In this article I will share separate sections of a kickstart file which can be used based on your requirement.

    A sample kickstart configuration file can be collected from here
    http://www.golinuxhub.com/p/kickstart-configuration-for-rhel7.html

    If you are starting with scratch to create a custom kickstart file it is always a good idea to use anaconda-ks.cfg which is available in the home folder of the 'root' user which can give you the different sections which are needed to do a scratch installation.

    I will try to explain the various options which can be selected for different section in the kickstart.

    IMPORTANT NOTE: Some of the parameters in this article may expire or not work over the period of time based upon RHEL dev, as they might change or remove the variables so it is always a good idea to validate your kickstart using 'ksvalidator' tool. This tool is a part of 'pykickstart' rpm.

    # ksvalidator kickstart.conf

    This should throw errors/warnings if any for your kickstart file and if the output is null this means the file is perfect to be used.

    Below is the link from Red Hat which has an overview of all the supported parameters in kickstart file for RHEL 7.
    Kickstart Syntax for Red Hat Enterprise Linux 7

    I will not be able to explain every parameter, but will try to explain the ones which are mostly used, if you want any additional help feel free to post the same in your comments and I can add those as well.

    Create custom repository

    Ideally the default directory in the Red Hat which contains all the list of rpms is "Packages" but assuming you would like to involve an additional repo to your list with some additional rpms.





    For eg on my TFTP server using which I will initiate a PXE installation using these kickstart files, I have repository as below path
    # cd /root/repo/rhel7_64
    Here I will create an additional directory which will contain all the additional rpms which I want to include in my repository
    # mkdir ExtraPackages
    Once all rpms are copied here, I have to execute
    # createrepo /root/repo/rhel7_64/ExtraPackages/
    This will configure it as a repo by creating needed xml files and repodata.

    Next add this line in the kickstart file
    ## Additional repository
    repo --name="ExtraPackages"
    --baseurl=file:///run/install/repo/ExtraPackages

    Mode of Installation

    Based on your requirement select the option
    # For text based installation
    text

    # For graphical based installation
    graphical

    Keyboard Layout and System Language

    Most of us normally use the standard "us" and "US-English" but there are many more options which can be used based on your region.

    To get the list of supported keyboard layout
    # localectl list-keymaps
    To get the list of supported system language
    # localectl list-locales
    To check the currently set values
    # localectl
       System Locale: LANG=
    en_US.utf8
           VC Keymap: us
          X11 Layout: us

    Based on your requirement fill the value in the kickstart file
    # System keyboard
    keyboard
    us

    # System language
    lang en_US.UTF-8

    Installation media details

    You have to provide the details of the server/location from which the installation of RHEL will be initiated.

    For eg: if a DVD is used for installation then use
    # Installation Media
    cdrom

    For NFS server
    # Installation Media
    nfs --server=10.43.138.1 --dir=/root/repo/rhel7_64

    For HTTP, HTTPS, FTP server
    url --url http://server/path
    url --url ftp://username:password@server/path

    Network Information

    Here you can define the network configuration of the target node based on your requirement.

    If you have a DHCP server which will give the details of the network then
    #Network Information
    network --bootproto=dhcp

    To assign static IP details below are some sample configuration

    For multiple interfaces with bond configuration using MII bonding and IPv6 disabled
    network --bootproto=static --hostname=deep-node2 --device=bond0 --gateway=10.43.138.30 --ip=10.43.138.5 --netmask=255.255.255.224 --noipv6 --nodns --onboot=on --activate --bondopts=mode=active-backup,miimon=100,updelay=1000,downdelay=1000,primary=eth0 --bondslaves=eth0,eth1
    network --bootproto=static  --device=bond1 --ip=192.168.130.5 --netmask=255.255.255.0 --noipv6 --nodns --onboot=on --activate --bondopts=mode=active-backup,miimon=100,updelay=1000,downdelay=1000,primary=eth2 --bondslaves=eth2,eth3
    network --bootproto=static  --device=bond2  --ip=192.168.131.5 --netmask=255.255.255.0 --noipv6 --nodns --onboot=on --activate --bondopts=mode=active-backup,miimon=100,updelay=1000,downdelay=1000,primary=eth4 --bondslaves=eth4,eth5
    network --bootproto=static  --device=bond3 --ip=192.168.132.5 --netmask=255.255.255.0 --noipv6 --nodns --onboot=on --activate --bondopts=mode=active-backup,miimon=100,updelay=1000,downdelay=1000,primary=eth6 --bondslaves=eth6,eth7

    For multiple interfaces with bond configuration using ARP bonding and IPv6 disabled
    network --bootproto=static --hostname=deep-node1 --device=bond0 --gateway=10.43.138.30 --ip=10.43.138.5 --netmask=255.255.255.224 --noipv6 --nodns --onboot=on --activate --bondopts=mode=active-backup,arp_interval=1000,arp_ip_target=,arp_validate=all,primary=eth0 --bondslaves=eth0,eth1
    network --bootproto=static  --device=bond1 --ip=192.168.130.5 --netmask=255.255.255.0 --noipv6 --nodns --onboot=on --activate --bondopts=mode=active-backup,arp_interval=1000,arp_ip_target=192.168.130.254,arp_validate=all,primary=eth2 --bondslaves=eth2,eth3
    network --bootproto=static  --device=bond2  --ip=192.168.131.5 --netmask=255.255.255.0 --noipv6 --nodns --onboot=on --activate --bondopts=mode=active-backup,arp_interval=1000,arp_ip_target=192.168.131.254,arp_validate=all,primary=eth4 --bondslaves=eth4,eth5
    network --bootproto=static  --device=bond3 --ip=192.168.132.5 --netmask=255.255.255.0 --noipv6 --nodns --onboot=on --activate --bondopts=mode=active-backup,arp_interval=1000,arp_ip_target=192.168.132.254,arp_validate=all,primary=eth6 --bondslaves=eth6,eth7

    For individual interfaces (without bond)
    network --bootproto=static --hostname=deep-node3 --device=eth0 --gateway=192.168.10.100 --ip=192.168.10.1 --netmask=255.255.255.0 --noipv6 --nodns --onboot=on --activate
    network --bootproto=static --device=eth1 --gateway=192.168.10.100 --ip=192.168.10.2 --netmask=255.255.255.0 --noipv6 --nodns --onboot=on --activate
    network --bootproto=static --device=eth2 --gateway=192.168.10.100 --ip=192.168.10.3 --netmask=255.255.255.0 --noipv6 --nodns --onboot=on --activate

    Configure Disk Partitioning

    This is one of the other important part of kickstart configuration wherein you have to give the complete layout of your partitioning scheme

    The first part of this is always to clear the existing partition table unless you want to retain some disk.
    For my case I want to completely scratch install my system
    # Clear existing data
    clearpart --all --initlabel

    IMPORTANT NOTE: The above command will clear all your disk drives including any network drive if attached, if you wish not clear complete data, assuming you have two disk (sda, sdb) and you only want to destroy sda then your argument should be
    clearpart --drives=sda
    zerombr

    The zerombr command initialises unused partition tables.
    NOTE: For the sake of this article I will use "clearpart --all" as I have to wipe out complete disk drives

    For setting an ext4 partition with a simple layout
    # Disk Partitioning
    autopart --type=plain --fstype=
    ext4

    For setting an ext4 partition with a software RAID 1 + LVM.
    Here my setup is having two disk (each with 838GB space) hence I am create Physical Volume accordingly, you can modify the value based on your disk size. You can also use "--size 1 --grow" if you do not wish to restrictively define a size for your physical volume and this will take the maximum available space in your disks.
    # -- raid part for boot --
    part raid.sda0 --size 512 --asprimary --ondrive=sda
    part raid.sdb0 --size 512 --asprimary --ondrive=sdb

    # -- raid part for pv.1 --
    part raid.sda2 --size
    821616 --ondrive=sda
    part raid.sdb2 --size 821616 --ondrive=sdb

    # -- raid part for root --
    part raid.sda1 --size 12288 --ondrive=sda
    part raid.sdb1 --size 12288 --ondrive=sdb

    # -- raid part for swap --
    part raid.sda3 --size 12288 --ondrive=sda
    part raid.sdb3 --size 12288 --ondrive=sdb

    # Raid device creation
    raid /boot --fstype ext4 --device md0 --level=RAID1 raid.sda0 raid.sdb0
    raid pv.1 --device md2 --level=RAID1 raid.sda2 raid.sdb2
    raid / --fstype ext4 --device md1 --level=RAID1 raid.sda1 raid.sdb1
    raid swap --fstype swap --device md3 --level=RAID1 raid.sda3 raid.sdb3

    # Volume group and logical volume creation
    volgroup vg00 --pesize=65536 pv.1
    logvol /var --fstype ext4 --vgname vg00 --size=16384 --name=var
    logvol /tmp --fstype ext4 --vgname vg00 --size=24576 --name=tmp
    logvol /home --fstype ext4 --vgname vg00 --size=8192 --name=home
    logvol /opt --fstype ext4 --vgname vg00 --size=16384 --name=opt
    logvol /usr --fstype ext4 --vgname vg00 --size=32768 --name=usr
    logvol /var/log --fstype ext4 --vgname vg00 --size=1 --grow --name=log

    For setting an ext4 partition with only LVM.
    Here my setp has a single disk (sda) and my physical volume is configured to use all the avilable space on the disk to create and configure the partition layout
    part /boot --size 512 --asprimary --fstype=ext4 --ondrive=sda
    part pv.1
    --size 1 --grow --fstype=ext4 --ondrive=sda

    volgroup system --pesize=32768 pv.1
    logvol / --fstype ext4 --vgname system --size=8192 --name=root
    logvol /var --fstype ext4 --vgname system --size=16384 --name=var
    logvol /tmp --fstype ext4 --vgname system --size=40960 --name=tmp
    logvol swap --vgname system --size=4096 --name=swap
    logvol /opt --fstype ext4 --vgname system --size=8192 --name=opt
    logvol /opt/deep --fstype ext4 --vgname system --size=6144 --name=deep
    logvol /opt/deep/log --fstype ext4 --vgname system --size=20480 --name=deeplog
    logvol /var/opt/data--fstype ext4 --vgname system --size=1 --grow --name=mybackup

    Timezone

    To get the list of supported timezone variables in the kickstart on a RHEL 7 node execute below command
    # timedatectl list-timezones
    This will give a long list of available timezones which can be used here, for me
    # System timezone
    timezone
    --utc Asia/Kolkata

    Root Password

    Here you have to give a password of the 'root' user which can be in below formats

    • encrypted
    • plaintext

    You can create an encrypted password with sha512 crypt-compatible hash using below command
    # python -c 'import crypt,getpass;pw=getpass.getpass();print(crypt.crypt(pw) if (pw==getpass.getpass("Confirm: ")) else exit())'
    Once you have the encrypted password
    #Root password
    rootpw --iscrypted $1$oVhMpzps$6FeGBc1uF2JmG2xTeSWML0

    You can also lock the 'root' user from logging in via console using "--lock". This option will also disable the Root Passwordscreens in both the graphical and text-based manual installation.

    List of Packages to be installed

    Here you can give a list of groups or individual rpms which you would like to be installed on your node, additionally you can also give a list of rpms which you want to be removed from your node. This is useful wherein you have selected a "Group" for package installation but still some of the rpms from this group is not needed hence the same can be removed during installation

    To get the details of the available group in a RHEL 7 DVD
    # yum group list ids
    Loaded plugins: product-id, search-disabled-repos, subscription-manager
    This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
    There is no installed groups file.
    Maybe run: yum groups mark convert (see man yum)
    Available Environment Groups:
       Minimal Install (
    minimal)
       Infrastructure Server (infrastructure-server-environment)
       File and Print Server (file-print-server-environment)
       Basic Web Server (web-server-environment)
       Virtualization Host (virtualization-host-environment)
       Server with GUI (graphical-server-environment)
    Available Groups:
       Compatibility Libraries (compat-libraries)
       Console Internet Tools (console-internet)
       Development Tools (development)
       Graphical Administration Tools (graphical-admin-tools)
       Legacy UNIX Compatibility (legacy-unix)
       Scientific Support (scientific)
       Security Tools (security-tools)
       Smart Card Support (smart-card)
       System Administration Tools (system-admin-tools)
       System Management (system-management)
    Done

    So here the id mentioned within ( ) can be used in the below section, By default we use @Core and @Base for minimal installation
    # list of packages to be installed
    %packages
    # Groups to be installed
    @ Core
    @ Base --nodefaults
    # Additional rpms to be installed
    dos2unix
    expect
    ksh
    libhbaapi
    nfs-utils
    python-devel
    perl
    # rpms to be removed
    -iwl2000-firmware
    -iwl5150-firmware
    -iwl3160-firmware
    -iwl1000-firmware
    -iwl3945-firmware
    -iwl100-firmware

    %end

    NOTE: The rpms to be removed must be started with a minus sign (-) but a (+) is not needed for any rpms you want to be installed additionally

    Pre and Post Installation script

    This section is one of the most useful feature as here you can do the real magic of customisation based on your organisation requirement.

    For eg once the installation is complete there are some custom scripts which are available on the node which I want to execute and save the date and time when the installation completed.
    %post --interpreter=shell --log=/var/log/kickstart_post.log
    echo "Executing post installation scripts"
    /tmp/post_scripts.sh

    echo "Installation Completed"
    date
    %end

    Similarly %pre section can be used to perform some activity before starting the installation based on the requirement.

    There are many more sections in a kickstart file which goes out of scope for this article, but if you feel you need any additional information on any of the parameter and assuming I have information on the same please let me know in the comment section and I will try to help you out.

    I hope this article was helpful.

    Related Articles:
    How to save %pre installation log file after installation in Red Hat 7
    How to perform interactive kickstart installation on Red Hat

    Follow the below links for more tutorials

    How to find the path of any command in Linux
    How to configure a Clustered Samba share using ctdb in Red Hat Cluster
    How to delete an iscsi-target from openfiler and Linux
    How to perform a local ssh port forwarding in Linux
    How to use yum locally without internet connection using cache?
    What is umask and how to change the default value permanently?
    Understanding Partition Scheme MBR vs GPT
    How does a successful or failed login process works in Linux
    How to find all the process accessing a file in Linux
    How to exclude multiple directories from du command in Linux
    How to configure autofs in Linux and what are its advantages?
    How to resize software raid partition in Linux
    How to configure Software RAID 1 mirroring in Linux
    How to prevent a command from getting stored in history in Linux

    0 comments:

    Post a Comment