Step 1: Install virt-sysprep

Type the following apt-get command/apt command to install virt-sysprep on a Debian or Ubuntu Linux:


$ sudo apt install libguestfs-tools

If you are using a CentOS/RHEL/Oracle/Scientific Linux, type the following yum command:


$ sudo yum install libguestfs-tools

If you are using a Fedora Linux, type the following dnf command to install the same:


$ sudo dnf install libguestfs-tools


Step 2: Download cloud image in .qcow2 format

You can grab cloud images from the following sites.

For demo purpose I am downloading and using CentOS 7 image using wget command:


$ wget https://cloud.centos.org/centos/7/images/CentOS-7-x86_64-GenericCloud.qcow2.xz


Use xz command for decompression:


$ xz -v -d CentOS-7-x86_64-GenericCloud.qcow2.xz


Step 3: Setup/inject an ssh keys

To inject an ssh key to the given “USER” will be able to log in over ssh without supplying a password. The “USER” must exist already in the guest. For CentOS 7 username is centos:


$ sudo virt-sysprep -a CentOS-7-x86_64-GenericCloud.qcow2 \
--ssh-inject centos:file:/home/vyga/.ssh/id_rsa.pub

Step 4: Launch a new VM using CentOS-7-x86_64-GenericCloud-1503.qcow2 image

The syntax is:

$ virt-install --import \
--name centos7-vm1 \
--memory 1024 \
--vcpus 2 \
--cpu host \
--disk path=/var/lib/libvirt/images/centos7.qcow2,size=10,bus=virtio,format=qcow \
--os-type=linux \
--os-variant=centos7.0 \
--graphics spice \
--noautoconsole \
--disk /home/vyga/modifyisoimages/CentOS-7-x86_64-GenericCloud.qcow2


Step 5: Test it with ssh

To find out your VM's IP address run:


$ virsh net-list
$ virsh net-dhcp-leases default



To log in using ssh command:


$ ssh user@vms-ip-address-here

 

?האם התשובה שקיבלתם הייתה מועילה 0 משתמשים שמצאו מאמר זה מועיל (0 הצבעות)