Creating centos/rhel7 Cloud Images using qemu-img and virt-install

by Anish


Posted on Tuesday June 26



Cloud Image Manual Creation

Install the CPU checker

sudo apt install cpu-checker

Check for kvm support

sudo kvm-ok
INFO: /dev/kvm exists
KVM acceleration can be used

Install the qemu-img and virt-install packages

yum -y install qemu-img virt-install

Verify Network is Active

virsh net-list
 Name                 State      Autostart     Persistent
----------------------------------------------------------
 default              active     yes           yes

If network is not Active then start it by doing:

virsh net-start default

Download the Centos ISO image from centos7 Minimal image from mirror site

wget http://centos.excellmedia.net/7/isos/x86_64/CentOS-7-x86_64-Minimal-1804.iso

Create the qemu centos img example 3G

qemu-img create -f qcow2 centos7-minimal-cloud.qcow2 3G
Formatting 'centos7-minimal-cloud.qcow2', fmt=qcow2 size=3221225472 encryption=off cluster_size=65536 lazy_refcounts=off refcount_bits=16

Run the osinfo-query os command to see a range of allowed --os-variant options.

osinfo-query os | grep centos7
 centos7.0            | CentOS 7.0                                         | 7.0      | http://centos.org/centos/7.0

Install the Centos7 using virt-install

virt-install --virt-type kvm --name centos7-minimal-cloud --ram 2048 --cdrom CentOS-7-x86_64-Minimal-1804.iso --disk centos7-minimal-cloud.qcow2,format=qcow2 --network=bridge:virbr0 --graphics vnc,listen=0.0.0.0 --wait=-1  --noautoconsole --os-type=linux --os-variant=centos7.0 --noreboot
Starting install...
Creating domain...                                                                                                       |    0 B  00:00:02     
Domain installation still in progress. Waiting for installation to complete.

Connect through the VNC server VNC password can be found at .

cat /etc/libvirt/qemu.conf | grep vnc_password
vnc_password = "XYZ12345"

Install Centos7 .

Verify Installation Destinations .

Create Necessary Users .

Reboot the Server When Prompted .

After the reboot check the console. it will display the below messages

Domain creation completed.
You can restart your domain by running:
virsh --connect qemu:///system start centos7-minimal-cloud

Re-Connect to the VNC

virsh --connect qemu:///system start centos7-minimal-cloud

Login to the System with the configured user


Update the /etc/sysconfig/network-scripts/ifcfg-eth0 file so it only contains the following values

cat /etc/sysconfig/network-scripts/ifcfg-eth0 
TYPE=Ethernet
DEVICE=eth0
ONBOOT=yes
BOOTPROTO=dhcp
NM_CONTROLLED=no

Disable the zeroconf route

echo "NOZEROCONF=yes" >> /etc/sysconfig/network

Configure the Console Edit the File /etc/default/grub and add the console tty

GRUB_CMDLINE_LINUX="crashkernel=auto rd.lvm.lv=cl/root rd.lvm.lv=cl/swap console=tty0 console=ttyS0,115200n8"

Generate Grub Configuration file

grub2-mkconfig -o /boot/grub2/grub.cfg
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-3.10.0-514.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-514.el7.x86_64.img
Found linux image: /boot/vmlinuz-0-rescue-c1b5666cc6334b14bfcf1f9b18bd1e4a
Found initrd image: /boot/initramfs-0-rescue-c1b5666cc6334b14bfcf1f9b18bd1e4a.img
Done

Install the ACPI service , cloud-init & cloud-utils-growpart

yum -y  install acpid cloud-init cloud-utils-growpart

ENable the ACPI service

systemctl enable acpid

Poweroff the Machine

poweroff

Finally cleanup the Machine remove MAC address

virt-sysprep -d centos
[   0.0] Examining the guest ...
[  38.0] Performing "abrt-data" ...
[  38.0] Performing "bash-history" ...
[  38.0] Performing "blkid-tab" ...
[  38.0] Performing "crash-data" ...
[  38.0] Performing "cron-spool" ...
[  38.0] Performing "dhcp-client-state" ...
[  38.0] Performing "dhcp-server-state" ...
[  38.0] Performing "dovecot-data" ...
[  38.0] Performing "logfiles" ...
[  38.1] Performing "machine-id" ...
[  38.1] Performing "mail-spool" ...
[  38.1] Performing "net-hostname" ...
[  38.1] Performing "net-hwaddr" ...
[  38.1] Performing "pacct-log" ...
[  38.1] Performing "package-manager-cache" ...
[  38.1] Performing "pam-data" ...
[  38.1] Performing "puppet-data-log" ...
[  38.1] Performing "rh-subscription-manager" ...
[  38.1] Performing "rhn-systemid" ...
[  38.1] Performing "rpm-db" ...
[  38.1] Performing "samba-db-log" ...
[  38.1] Performing "script" ...
[  38.1] Performing "smolt-uuid" ...
[  38.1] Performing "ssh-hostkeys" ...
[  38.1] Performing "ssh-userdir" ...
[  38.2] Performing "sssd-db-log" ...
[  38.2] Performing "tmp-files" ...
[  38.2] Performing "udev-persistent-net" ...
[  38.2] Performing "utmp" ...
[  38.2] Performing "yum-uuid" ...
[  38.2] Performing "customize" ...
[  38.2] Setting a random seed
[  38.5] Performing "lvm-uuids" ...
python Cryptography Topics
Topics
For Coffee/ Beer/ Amazon Bill and further development of the project Support by Purchasing, The Modern Cryptography CookBook for Just $9 Coupon Price

Kubernetes for DevOps

Hello Dockerfile

Cryptography for Python Developers

Cryptography for JavaScript Developers

Go lang ryptography for Developers