Issue while creating a CentsOS 7 KVM Guest

It’s quite sometime since RHEL/CentOS 7 (2014-06-09) was released so a few days ago I thought I should try it out and maybe create a KVM Guest template in case I need it in the future.

So as I usually do in order to create a new KVM guest I execute the following command which worked while creating either a CentOS 5.x or a 6.x.

# virt-install -n centos7 -r 2048  \
--vcpus=1 --os-type linux --os-variant=rhel7 \
--network bridge=br0 --nographics \
--location='http://ftp.ntua.gr/pub/linux/centos/7/os/x86_64/' \
--extra-args='console=tty0 console=ttyS0,115200n8 serial' \
--disk path=/mnt/sdb/kvms/images/centos7.img,size=12 --hvm

After a while the script failed with the following message

[  OK  ] Reached target Basic System.
dracut-initqueue[545]: RTNETLINK answers: File exists
dracut-initqueue[545]: Warning: Could not boot.
dracut-initqueue[545]: Warning: /dev/root does not exist
Starting Dracut Emergency Shell...
Warning: /dev/root does not exist
Generating "/run/initramfs/rdsosreport.txt"
Entering emergency mode. Exit the shell to continue.
Type "journalctl" to view system logs.
You might want to save "/run/initramfs/rdsosreport.txt" to a USB stick or /boot
after mounting them and attach it to a bug report.
dracut:/#

It seems that it was trying to use the KVM’s host IP address. After a while I thought that I could give an another IP to the guest server to use while executing virt-install. How could I do that? Why not use a kickstart file as I did in my previous post

That’s why I created the following kickstart file

# text mode (no graphical mode)
text

# do not configure X
skipx

# install
install

# installation url
url --url=http://ftp.ntua.gr/pub/linux/centos/7/os/x86_64/

# Language support
lang en_US

# Keyboard
keyboard us

# Network
network --device eth0 --bootproto static --ip 192.168.1.2 --netmask 255.255.255.0 --gateway 192.168.1.254 --nameserver 8.8.8.8 --noipv6 --hostname centos7

# auth config
auth --useshadow --enablemd5

# root password
rootpw --iscrypted CHANGEME

# SElinux
selinux --disabled

# timezone
timezone  America/New_York

# bootloader
bootloader --location=mbr

# clear the MBR (Master Boot Record)
zerombr

# the Setup Agent is not started the first time the system boots
firstboot --disable

# Reboot after installation
reboot

# Logging lever
logging --level=info

# Remove all partitions
clearpart --all --initlabel

# create partitions on the system
part / --asprimary --fstype="ext4" --grow --size=1
part swap --recommended

# Packages installation
%packages
@core
wget
net-tools
--nobase
%end

%post
mkdir -p /root/.ssh
echo "MY_PUBLIC_SSH_KEY" > /root/.ssh/authorized_keys
%end

We can execute using a local kickstart file or a kickstart file that we are going to “load” from an http server. The way we execute virt-install depends whether we use a local kickstart file or one pulled from an http server

So if you are using a local kickstart file you execute

 # virt-install -n centos7 -r 2048  \
--vcpus=1 --os-type linux --os-variant=rhel7 \ 
--network bridge=br0 --nographics 
--location='http://ftp.ntua.gr/pub/linux/centos/7/os/x86_64/' \
--initrd-inject=/root/centos7x_kvm.ks 
--extra-args='ks=file:/centos7x_kvm.ks text console=tty0 console=ttyS0,115200n8 serial' \
--disk path=/var/lib/libvirt/images/centos7.img,size=12 --hvm 

What you need here is to use –initrd-inject=/root/centos7x_kvm.ks and also ks=file:/centos7x_kvm.ks
On ks=file:/centos7x_kvm.ks you just define the file name not the absolute path this is defined in –initrd-inject
One more thing you need to have in mind is that you don’t need to define network settings on extra-args otherwise execution will fail.

If you are pulling the kickstart file from an http server then you need to execute

 # virt-install -n centos7 -r 2048  \
--vcpus=1 --os-type linux --os-variant=rhel7 \
--network bridge=br0 --nographics \ 
--location='http://ftp.ntua.gr/pub/linux/centos/7/os/x86_64/' 
--extra-args='ks=http://MYSERVER.MYORG/centos7x_kvm.ks ksdevice=eth0 ip=192.168.1.2 netmask=255.255.255.0 dns=8.8.8.8 gateway=192.168.1.254 text console=tty0 console=ttyS0,115200n8 serial' \
--disk path=/var/lib/libvirt/images/centos7.img,size=12 --hvm

You can find my kickstarts in my github
https://github.com/mrdimka/kvm-scripts/tree/master/kickstarts

4 thoughts on “Issue while creating a CentsOS 7 KVM Guest

  1. I’m getting a network is unreachable when injecting the KS file. This is the virt-install command:

    virt-install –name cos7 –ram 4192 –vcpus=6 –os-variant=rhel7 –accelerate -v -w bridge:external,mac=00:1d:55:46:e6:29 –disk path=/dev/vmvg/cos7os –location nfs:16.89.91.2:/install/centos-7.2-x86_64 –initrd-inject=’/var/tmp/ks’ –nographics -x “ksdevice=eth0 console=tty0 console=ttyS0 headless text ssh=1 inst.ks=file:/ks serial text console=ttyS0” –force –autostart –noautoconsole

    Snippet of the KS file:

    nfs –server=16.89.91.2 –dir=/install/centos-7.2-x86_64
    network –onboot yes –device=eth0 –bootproto=static –noipv6 –ip=16.89.91.16 –netmask=255.255.254.0 –gateway=16.89.91.1 –nameserver=10.1.1.39 –hostname=test.
    local –activate

    Do I have to use –url?
    Strange that this works perfectly in centos 6.

    Like

  2. It’s worth mentioning the following:
    – The kickstart file overhere contains &quot instead of ‘
    – The shell command virt-install is missing some \ entries
    – When installing don’t be surprised if it’ll display Network is unreachable, it’ll continue anyway
    – The memory requirements to give to the VM should be at least 1500MB

    Like

Leave a comment