Wednesday, May 27, 2015

Creating a VM

[root@blade30 ~]# qemu-img create -f qcow2 /tmp/comviva-spr-centos7.qcow2 10G
Formatting '/tmp/comviva-spr-centos7.qcow2', fmt=qcow2 size=10737418240 encryption=off cluster_size=65536

[root@blade30 ~]# virt-install --virt-type kvm --name comviva-spr-centos6.4 --ram 1024 --cdrom=/home/iso/CentOS-6.4-x86_64-bin-DVD1.iso --disk /tmp/comviva-spr-centos7.qcow2,format=qcow2 --network network=default --graphics vnc,listen=0.0.0.0 --noautoconsole --os-type=linux --os-variant=rhel6

Starting install...
Creating domain...                                                                                                         |    0 B     00:00
Domain installation still in progress. You can reconnect to
the console to complete the installation process.


<<< snapshots to be placed here >>>>

[root@blade30 ~]# ssh root@192.168.122.207
The authenticity of host '192.168.122.207 (192.168.122.207)' can't be established.
RSA key fingerprint is be:73:31:4e:f0:d4:08:6c:0d:8e:f3:a1:f6:43:0e:7c.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.122.207' (RSA) to the list of known hosts.
root@192.168.122.207's password:
Last login: Wed Apr  8 19:16:38 2015
[root@spr ~]#

[root@spr ~]# cat /etc/resolv.conf
; generated by /sbin/dhclient-script
nameserver 192.168.122.1

vi /etc/yum.repos.d/CentOS-Base.repo
[local]
name=CentOS-$releasever - Base
baseurl=http://192.168.122.1/centos6.4
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

[root@spr ~]# yum -y install ca-certificates.noarch

[root@spr ~]# yum install -y http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm

[root@spr ~]# yum install -y cloud-utils cloud-init parted
[root@spr ~]# vi /etc/cloud/cloud.cfg
......
cloud_init_modules:
 - migrator
 - bootcmd
.....
 - users-groups
 - ssh
 - resolv-conf

[root@spr ~]# vi /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=spr.comviva.com
NOZERCONF=yes

[root@spr ~]# yum install -y openssh-clients sysstat vim
[root@spr ~]# chkconfig mysqld on
[root@spr ~]# poweroff

Broadcast message from root@spr.comviva.com
        (/dev/pts/0) at 19:53 ...

The system is going down for power off NOW!
[root@spr ~]# Connection to 192.168.122.207 closed by remote host.
Connection to 192.168.122.207 closed.

[root@blade30 ~]# cd /tmp
[root@blade30 tmp]# ls -lh *.qcow2
-rw-r--r--. 1 root root 1.2G Apr  8 19:53 comviva-spr-centos7.qcow2

[root@blade30 tmp]# virt-sysprep -d comviva-spr-centos7
libguestfs: error: no libvirt domain called 'comviva-spr-centos7': Domain not found: no domain with matching name 'comviva-spr-centos7'

[root@blade30 tmp]# virt-sysprep -d comviva-spr-centos7
libguestfs: error: no libvirt domain called 'comviva-spr-centos7': Domain not found: no domain with matching name 'comviva-spr-centos7'
[root@blade30 tmp]# virt-sparsify --compress comviva-spr-centos7.qcow2 comviva-vspr-centos7.qcow2
Create overlay file to protect source disk ...
Examine source disk ...
Fill free space in /dev/vda1 with zero ...
Fill free space in /dev/vg_spr/lv_root with zero ...
Copy to destination and make sparse ...

Sparsify operation completed with no errors.  Before deleting the old
disk, carefully check that the target disk boots and works correctly.
[root@blade30 tmp]# ls -lh *.qcow2
-rw-r--r--. 1 root root 1.2G Apr  8 19:53 comviva-spr-centos7.qcow2
-rw-r--r--. 1 root root 307M Apr  8 19:58 comviva-vspr-centos7.qcow2