RHEL7: Install Red Hat Enterprise Linux systems as virtual guests
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 --fstype="ext4" --ondisk=vda --size=500
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
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: httpin 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.
Additional Resources
There is a documentation about the Anaconda installer. 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.
Leave a comment