Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
CentOS 7 Linux Server Cookbook, Second Edition

You're reading from   CentOS 7 Linux Server Cookbook, Second Edition Get your CentOS server up and running with this collection of more than 80 recipes created for CentOS 7 - essential for Linux fans!

Arrow left icon
Product type Paperback
Published in Jan 2016
Publisher
ISBN-13 9781785887284
Length 326 pages
Edition 2nd Edition
Tools
Arrow right icon
Author (1):
Arrow left icon
Jonathan Hobson Jonathan Hobson
Author Profile Icon Jonathan Hobson
Jonathan Hobson
Arrow right icon
View More author details
Toc

Table of Contents (17) Chapters Close

Preface 1. Installing CentOS FREE CHAPTER 2. Configuring the System 3. Managing the System 4. Managing Packages with YUM 5. Administering the Filesystem 6. Providing Security 7. Building a Network 8. Working with FTP 9. Working with Domains 10. Working with Databases 11. Providing Mail Services 12. Providing Web Services 13. Operating System-Level Virtualization 14. Working with SELinux 15. Monitoring IT Infrastructure Index

Installing CentOS 7 using a kickstart file

While installing CentOS 7 manually using the graphical installer utility is fine on a single server, doing so on a multiple number of systems can be tedious. Kickstart files can automate the installation process of a server system and here we will show how this can be done. They are simple text based configuration files which provide detailed and exact instructions on how the target system should be set up and installed (for example, which keyboard layout or additional software packages to install).

Getting ready

To successfully complete this recipe, you will need access to an already installed CentOS 7 system to retrieve the kickstart configuration file we want to work with and use for automated installation. On this pre-installed CentOS server, you also need a working Internet connection to download additional software.

Next, we will need to download and create installation media for the DVD or the Everything image (download the latest CentOS-7-x86_64-DVD-XXXX.iso or CentOS-7-x86_64-Everything-XXXX.iso file), instead of the minimal iso file shown in another recipe in this chapter. Then you need another USB device which must be read and writable on Linux systems (formatted as FAT16, FAT32, EXT2, EXT3, EXT4, or XFS filesystem).

How to do it...

For this recipe to work, we first need physical access to an existing kickstart file from another finished CentOS 7 installation, which we will use as a template for a new CentOS 7 installation.

  1. Log in as root on the existing CentOS 7 system and make sure the kickstart configuration file exists by typing the following command and pressing the Return key to execute (this will show you the details of the file):
    ls -l /root/anaconda-ks.cfg
    
  2. Next, physically plug in a USB device and then type the following command, which will give you a list of all the hard disk devices currently connected to the computer:
    fdisk -l
    
  3. Try to identify the device name by comparing its size, partitions, and identified filesystems with the specifications of your USB device. The device name will be of kind /dev/sdX, where X is an alphabetical character, such as b, c, d, e, … and so on. If you cannot find the right device name for your USB media using the fdisk command, try the following trick: run fdisk -l twice - first with plugged-out and then with plugged-in USB device and compare how the second output changed - it has one device name more than the first output: your device name of interest !
  4. If you have found the right device name in the list, create a directory to mount it to the current filesystem:
    mkdir /mnt/kickstart-usb
    
  5. Next, actually mount the stick to this folder, assuming that your USB partition of choice is at /dev/sdc1 (change this as required):
    mount /dev/sdc1 /mnt/kickstart-usb
    
  6. Now we will create our working copy of the kickstart file on the USB device for customizing:
    cp /root/anaconda-ks.cfg /mnt/kickstart-usb
    
  7. Next, open the copied kickstart file on the USB device with your favorite text editor (here we will use the editor nano, if you have not installed it yet type yum install nano):
    nano /mnt/kickstart-usb/anaconda-ks.cfg
    
  8. We will now modify the file for installing CentOS on a new target system. In nano, use the up and down arrow keys to go to the line which starts with (<your_hostname> will be the name of the hostname you gave during installation e.g. minimal.home):
    network  --hostname=<your_hostname>
    
  9. Now edit the <your_hostname> string to give it a new unique hostname. For example, add a -2 to the end of any existing name, as shown next:
    network  --hostname=minimal-2.home
    
  10. Next, move the cursor down using the up and down arrow keys until it stops at the line which says %packages. Append the following lines right below it (you can further customize this and provide additional packages that you want to install automatically):
    mariadb-server
    httpd
    rsync
    net-tools
    
  11. Now save and close the file, to do this in the nano editor use the key combination Ctrl+o (which means, hold down the Ctrl key on the keyboard and then the o key without releasing the Ctrl key) to write the changes. Then press Return to confirm the filename and Ctrl+x to exit the editor.
  12. Next, install the following CentOS package:
    yum install system-config-kickstart
    
  13. Now we validate the syntax of our kickstart file using the ksvalidator program, which is included in the package we just installed:
    ksvalidator /mnt/kickstart-usb/anaconda-ks.cfg
    
  14. If the config file is error-free, unmount the USB stick now by using the following commands:
    cd
    umount /mnt/kickstart-usb
    
  15. When you get a new command prompt again, unplug the USB device with the kickstart file for using on the target machine physically from the system.
  16. Now you need physical access to the target machine you want to install CentOS on, using the kickstart file just created. Disconnect any other external file storage(s) that you do not need during the installation.
  17. Power on the computer and put in your prepared CentOS installation media (must be a CentOS DVD or Everything installation disk image prepared on a CD/DVD disc or a USB device installer). Also connect to the computer the USB stick containing the kickstart file you just created in the earlier steps (if you using a USB drive for installing CentOS then you will need two free USB ports in total to complete this recipe).
  18. Next, start the server and press the correct key during the initial bootup screen, associated with booting the CentOS installation media you just connected.
  19. After the CentOS installer starts loading, the common standard CentOS 7 installation welcome screen will show up and the option Test this media & install CentOS 7 will be pre-selected by the cursor.
  20. Next, press the Esc key on your keyboard once to switch to the boot: prompt.
  21. Now we are ready to start the kickstart installation. To do this, you need to know the exact partition name on the USB device where the kickstart file is located. Type the following command, assuming that your partition is at /dev/sdc1 (change this as required), and press the Return key to start the kickstart installation process:
    linux ks=hd:sdc1:/anaconda-ks.cfg
    

    Note

    If you cannot find out the right device and partition name of the USB stick, you have to start the target system in rescue mode (refer to the Troubleshooting the system in rescue mode recipe) to identify the right device name and partition number by comparing its size, partitions, and identified filesystems with the specifications of your stick.

  22. The new system now gets installed automatically using the instructions from the provided kickstart file. You can watch the installation output messages as it is showing the user detailed installation progress.
  23. If the system has finished installing, reboot the system and log in to your new machine to verify that the new system has been setup the way we described using the kickstart file.

How it works...

In this recipe, you have seen that every server running a CentOS 7 installation keeps the kickstart file in its root directory, which contains detailed information on how the system had been set up during the installation. The kickstart files can be used to automate the installations of multiple systems with the same configuration. This can save a lot of time doing repetitive work as no user interaction during installation is needed. Also, we can use this method if the target machines don't meet the minimum requirement in RAM for graphical based installations but when needed other features the text mode installer does not provide such as custom partitioning of the system. Kickstart configuration files are simple plain text files which can be created manually from scratch. Because there are quite a number of different commands available to construct your system using the kickstart syntax, we used an existing file as a template and customized it to fit our needs, instead of starting out completely new. We did not use the minimal installation image to drive our kickstart installation because we installed some extra packages not included on the minimal ISO file, such as the Apache webserver.

You have been reading a chapter from
CentOS 7 Linux Server Cookbook, Second Edition - Second Edition
Published in: Jan 2016
Publisher:
ISBN-13: 9781785887284
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image