RHEL7: Install Red Hat Enterprise Linux systems as virtual guests.

Share this link

Note: This is an RHCSA 7 exam objective.

Presentation

Installing an RHEL 7 system as virtual guest requires two steps:

  • creating a Kickstart file with all the configuration parameters (ip address, disk partitioning, etc),
  • running the command for the creation itself.

Kickstart File

To create a VM called postfix.example.com (here with an IP address of 192.168.1.10, a gateway in 192.168.1.1, a DNS server in 192.168.1.5, a repository server in 192.168.1.5, Pass1234 as a password, and a total disk size of 6GB), create the file /var/www/html/conf/ks_postfix.cfg and paste the following lines:

keyboard --vckeymap=us --xlayouts='us'
lang en_US.UTF-8
network --device=eth0 --bootproto=static --ip=192.168.1.10 --netmask=255.255.255.0 --gateway=192.168.1.1 --nameserver=192.168.1.5 --activate --ipv6=auto
network --hostname=postfix.example.com
rootpw Pass1234
timezone America/Los_Angeles --isUtc
bootloader --location=mbr --boot-drive=vda
clearpart --all --initlabel --drives=vda
ignoredisk --only-use=vda
part pv.9 --fstype="lvmpv" --ondisk=vda --size=5000
#part /boot/efi --fstype=efi --grow --maxsize=200 --size=20
part /boot --fstype="ext4" --ondisk=vda --size=300
volgroup rhel --pesize=4096 pv.9
logvol swap  --fstype="swap" --size=500 --name=swap --vgname=rhel
logvol /  --fstype="ext4" --size=3072 --name=root --vgname=rhel

%packages
@base
@core

%end
reboot

Note: Uncomment the line beginning with “part /boot/efi” in case of an EFI-based system.

Creation Command

Run the following command:

# /bin/virt-install \
--virt-type kvm \
--name=postfix.example.com \
--disk path=/var/lib/libvirt/images/postfix.example.com.img,size=6 \
--ram=1024 \
--vcpus=1 \
--os-variant=rhel7 \
--accelerate \
--graphics vnc \
-v -l http://192.168.1.5/repo/CentOS/7/os/x86_64/ \
--network bridge:br0 \
--extra-args="console=tty0 console=ttyS0,115200 ks=http://192.168.1.5/conf/ks_
postfix.cfg"

Note1: http in the previous command can be replaced with nfs, ftp, etc.
Note2: If you get this message “ERROR internal error: process exited while connecting to monitor: qemu-kvm: -chardev pty,id=charserial0: Failed to create chardev“, follow this thread.
Replace “devpts  /dev/pts  devpts  defaults  0  0” with “devpts  /dev/pts  devpts  gid=5,mode=620  0  0” in the /etc/fstab file of the KVM host.
Note3: Since RHEL 7.4, 1024MB of memory is not enough anymore, use at least 1064MB.

Additional Resources

There is a documentation about the Anaconda installer and a repository with sample Kickstarts.
Naftuli Tzvi Kay wrote a tutorial about using Packer to make Kickstart configuration easier.
Frank Caviggia has written a script that installs a system that is configured and hardened to meet government-level regulations.
Giovanni Torres provides a Bash script to build local virtual machines using KVM/libvirt and cloud-init.

1 Star2 Stars3 Stars4 Stars5 Stars (5 votes, average: 4.80 out of 5)
Loading...
42 comments on “RHEL7: Install Red Hat Enterprise Linux systems as virtual guests.
  1. tcheung says:

    hi

    when I clicked the link “Install Red Hat Enterprise Linux automatically using Kickstart” from the web page “http://www.certdepot.net/rhel7-rhcsa-exam-objectives/”, I was re-directed to here. The hyperlink is wrong?

  2. hunter86_bg says:

    If you want to install RedHat from CD and you get your kickstart on another machine:
    Press “Esc” key, type “linux ks=nfs:/192.168.1.1/config/ks.cfg”
    nfs in the previous command can be replaced by “http” “ftp”, etc.
    Additional boot time options “ip=” “mask=255.255.255.0” “ksdevice=”

  3. travisby says:

    Hi! Just noticed that you mentioned to use 192.168.1.1 for the nameservers. Should that instead be 192.168.1.5, the master host we setup as DNS?

    Or is this article meant to be separate-able from the ‘lab setup’ portion?

    • CertDepot says:

      This tutorial was called from two different places.
      I have put 192.168.1.5 as the IP address of the nameserver to keep the lab settings simple.

  4. ak340 says:

    Hi CertDepot, wondering if from the exam we will be installing a VM server via kickstart, think it may consume a lot of exam period.

  5. ak340 says:

    Thanks CertDepot, I understand now that rhcsa exam is regarding fast execution, does this means as well that scripting will not be part of it?

  6. langtu1511 says:

    Hi,
    I prefer to use “console” parameter in the extra-args:

    -x “ks=http://192.168.1.5/conf/ks_postfix.cfg console=ttyS0”

    so that I can connect to VM by console directly “virsh console [vm-name]”

    • CertDepot says:

      Yes, you can add the following option:
      –extra-args=”console=tty0 console=ttyS0,115200 ks=http://192.168.1.5/conf/ks_
      postfix.cfg”

      Thanks for this useful comment. I updated the tutorial.

  7. eazlan says:

    Hi CertDepot

    After creating a kickstart file, how do I create a VM?

    Thanks in advance

    • CertDepot says:

      If you use KVM, after the creation of a kickstart file, you need to execute the virt-install command.
      You should read the tutorial about Installing RHEL systems as virtual guests.

      • eazlan says:

        Hi,

        I’m new in RHEL. Appreciate if you can help me on “CREATION COMMAND”. How to build? Do I need to create a new *.sh file?

        # /bin/virt-install \
        –virt-type kvm \
        –name=postfix.example.com \
        –disk path=/var/lib/libvirt/images/postfix.example.com.img,size=6 \
        –ram=1024 \
        –vcpus=1 \
        –os-variant=rhel7 \
        –accelerate \
        –graphics vnc \
        -v -l http://192.168.1.5/repo/CentOS/7/os/x86_64/ \
        –network bridge:br0 \
        –extra-args=”console=tty0 console=ttyS0,115200 ks=http://192.168.1.5/conf/ks_
        postfix.cfg”

        • CertDepot says:

          You can either type the virt-install command at the prompt or create a Bash script.
          If you create a Bash script, you need to start the script with the following line:

          #!/bin/bash

          This line defines which binary needs to be called when the script starts.
          You also need to give execution right on the script at the prompt:

          # chmod u+x script

          The x means execution right and the u represents the user/owner of the file.

  8. beshooo says:

    Hello CertDepot,
    I am required to remember the world for the Kickstart script? Is this too long to remember? Is there a easy way to create this kickstart from testing machine in exam?
    I think it is rare to come in exam?
    Sorry for my bad English.

    • CertDepot says:

      Yes, You are right. You shouldn’t need to learn everything about Kickstart because it doesn’t usually happen in the exam. The main reason is: it would take too long to install a VM from scratch. However, you should know the basics about Kickstart in case. Also, after the exam, Kickstart is a valuable skill to have.

      • beshooo says:

        Appreciate your fast feedback,
        Sorry I have another question:
        1-What is the exam redhat version 7 OR 7.2?
        2-If I use the old method of IP configuration by editing in ifcfg-eth0, is this a risky method so I wouldn’t get mark?

        Thanks in advance
        Bishooo

        • CertDepot says:

          1-Until this friday the exam was using version 7.0. This should change in the coming weeks.
          2-You can perfectly use the old method but you need to reload the NetworkManager configuration through a nmcli con reload command.

    • Gjorgi says:

      You could use anaconda-ks.cfg file in /root as a template to create a full-blown customized Kickstart file. Appropriate man pages that would further explain options in that file can be found by rpm -qd pykickstart (though formatting makes the document kind of hard to read).
      Sander Van Vugt’s guide has the greatest of all tutorials out there that explains how to set up a full-scale remote installation server and is a lot of fun.

    • blumeout86 says:

      I know this question is older, but these days, RedHat is relying more on Kubernetes and Ansible. I don’t know if those two can completely eliminate the need for Kickstart (I’m thinking of partitioning *physical* drives), but the Ansible route has quite a few advantages.

      • Lisenet says:

        Kickstart is used for provisioning, Ansible is used for configuration management. They serve different purposes.

        You can easily do Kickstart provisioning with Foreman, and then pass configuration management to Ansible once the system is up.

  9. asifshabir says:

    I am trying to install centos 7 using ks method. It picks up ks file, setting everything else fine. But I always get the error “For Installation source”
    “Error setting up base repository”. This is my ks.cfg file: http://www.heypasteit.com/clip/2LF9 . I have searched over net but could not solve this issue so far, Please extend your support for this.

    • CertDepot says:

      The problem seems to reside in the way you configured your repository at “http://192.168.1.200/rhel/”.
      I would advise you to check the following points:
      – an Apache webserver is correctly set (DOCUMENTROOT, etc) and started at 192.168.1.200 that gives access to servers at least in the 192.168.1.0/24 network (Require all granted),
      – SELinux is correctly configured for the /rhel directory for this webserver,
      – a copy of a CentOS/RHEL CDRom has been done according to the rules,
      – the firewall on this webserver leaves the 80 TCP port goes through and there is nothing in the /etc/hosts.deny file.

  10. ylemouel says:

    Hello,

    Thanks for your help, I’m also using Linux Academy, and they proposed using Virtual Manager for creating a VM via an iso downloaded from internet, is it enough?

  11. ntorga says:

    Is it possible to use Kickstart Generator on RHCSA?
    https://access.redhat.com/labs/kickstartconfig/

  12. neuraload says:

    Hello.

    1.) I don’t know how is this supposed to work but if you don’t specify bus=virtio for the –disk parameter the autoinstaller won’t start because there is now ‘vda’ with default bus which is IDE ( sda ).
    2.) “console=tty0 console=ttyS0” won’t work with graphical installer since the installation program will use ttyS0. I know, there is no reason to use the graphical installer. 🙂

  13. ercole1977 says:

    Hi guys. Just for info: am I supposed to create a VM from command line on RHCSA exam?

  14. lozingalo says:

    Hi, I’ll have the RHCSA exam on next Friday. In the objectives is not mentioned the installation using Kickstart but in this page it’s explained. Is it a requirement? How could I remember all the options to put in the kickstart file? Thank you

    • CertDepot says:

      No, you don’t need to learn all the options.

      • lozingalo says:

        Hi, here I am another time on this topic.
        As we already spoke about, the installation of a vm using kickstart is no longer belonging to the RHCSA objectives. In this page you explain the installation with kickstart. I hope there will be nothing like this in the exam but, which is the procedure that I have to know in order to install a vm? Thank you very much.

Leave a Reply

Upcoming Events (Local Time)

There are no events.

RHCSA7: Task of the day

Allowed time: 5 minutes.
Create two users "tom" and "engine". "tom" has the UID/GID 3000 and "engine" the UID/GID 4000. "engine" doesn't have an interactive shell.

RHCE7: Task of the day

Allowed time: 3 minutes.
Configure your machine to be a router.

Follow me on Twitter

Poll for favorite RHEL 7 book

What is your favorite RHEL 7 book to prepare RHCSA & RHCE exams?

View Results

Loading ... Loading ...

Poll for most difficult RHCSA 7 topic

What do you think is the most difficult RHCSA 7 topic?

View Results

Loading ... Loading ...

Poll for most difficult RHCE 7 topic

What do you think is the most difficult RHCE 7 topic?

View Results

Loading ... Loading ...