2015-08-29

The virtual instance OS image can be created outside the openstack. By default openstack comes with small Linux foot print instance called cirros and we have tested it. But as a customer , I would like to put custom image in openstack  for various requirement. In this article ,we will create Ubuntu custom image using the KVM hypervisor. This article will talk more about configuring the KVM/QEMU hypervisor , installing the required packages for KVM and creating the custom OS image using the KVM/QEMU. At the end of this article,  I will demonstrate that how to import the new instance image in Openstack.

Before going forward, we need to understand the various images type supported in Linux KVM. A virtual machine image or instance image is a single file which contains a virtual disk that has a bootable operating system installed on it.  Let’s see the various format used in the industry.

1. qcow2 ( QEMU copy on write version 2):

qcow2 is commonly used in  KVM hypervisor since its supports sparse representation  and  snapshot.

2. RAW:

raw image format is  a simple one and supported on both xen & kvm hypervisors.  The raw images are created using dd command. So it doesn’t support the sparse representation and snapshot. But this format is faster than the qcow2.

3. AMI/AKI/ARI :

These formats are used in Amazon EC2.

AMI (Amazon Machine Image): This is a virtual machine image in raw format.

AKI (Amazon Kernel Image) :A kernel file that the hypervisor will load initially to boot the image. (vmlinuz)

ARI (Amazon Ramdisk Image) :An optional ramdisk file mounted at boot time.(initrd).

4. VMDK:

VMDK (Virtual Machine DisK ) is a default format in VMware ESXi hypervisors.

5. VHDX:

VHDX is the default image format in Microsoft Hyper-V.

6. ISO:

The ISO format is a disk image formatted with the read-only ISO 9660 (also known as ECMA-119) filesystem commonly used for CDs and DVDs.

As I said earlier, prefer other than the Openstack controller machine for creating the OS images.  In my case , I am using the Ubuntu machine with VT enabled hardware to create the custom image for Openstack.

1.Login to the Ubuntu Server which has the VT enabled processors.

2. Verify the VT (virtualization Technology ) in that server.

Incase,  if you are running Ubuntu in virtual box or VMware workstation , you will error like “Your CPU does not support KVM extensions” .  In this case, you can use QEMU if your hardware has VT enabled processor. This can be validated using “virt-host-validate”.

3.  Install the KVM/QEMU packages using apt-get command. If you already have the qemu-kvm , just ignore this step.

4. Copy the Ubuntu server OS ISO  to the server .

5. Install “virtinst” package.

6. Create the virtual machine image file like below. Here I am using raw format to create the image.

7.Un-comment the below lines in qemu.conf file.

8.Create the virtual machine using below command. (Change the details according to your environment.)

9. Find the VNC port the virtual machine which you have started. Here we can see that virtual machine console is listening in “0.0.0.0:1 ” . Since the VNC port is listening in universal IP, So you can connect from anywhere. “:1” represents “5901” .

10. Open the VNCviewer and connect to the virtual instance VNC port.

11. You could see that system is booted using the ISO. During the installation , you must choose ssh-server package for instance access and configure the network to access the instance

12. Perform the typical  Ubuntu installation.  Once its done , just reboot the machine.

13. Here you can see that system is booted from the hard-drive.

If the virtual guest is not started automatically , it may went to shut-off state.  Login to your KVM machine and start like below. Follow the step 9 to find the VNC port for this machine.

14.  Virtual instance must have internet access to install cloud-init package.

15. Make sure that “/etc/apt/sources.list” file is up to date on  virtual instance. If not , you may not able to install the cloud init package.  If “/etc/apt/sources.list” is empty , use the “http://repogen.simplylinux.ch/”  to generate it .

My sources.list looks like below. (You  could use the same if you are using the Ubuntu 14.04.)

16. Install cloud-init package.

Upon the cloud-init package installation, file “/etc/cloud/cloud.cfg” will be created.  cloud-init is the Ubuntu package that handles early initialization of a cloud instance. Each cloud instance must have the cloud-init package.

17. Halt the instance .

18.Back to the KVM machine and perform the clean up of the instance. This process will remove the MAC , network configuration and other instance specific stuffs. First we need an utility called “virt-sysperp”. Let’s install it.

19. Run the virt-sysperp to perform the clean up against the image.

Command failed with error “Fatal error: exception Guestfs.Error(“/usr/bin/supermin-helper exited with error status 1.”. Let me enable the debug mode for virt-sysperp and run it to find the cause.

It’s failing with known error “/usr/bin/supermin-helper: ext2: parent directory not found: /lib: File not found by ext2_lookup “. To fix the issue ,

Update the “febootstrap” .

update the guestfs appliance and perform the guestfs test tool. If you get “TEST FINISHED OK” , then you are good to proceed with virt-sysprep”.

Re-run the command “virt-sysprep” for the newly created instance.

20. Un-define the virtual instance. The instances’ image file is now good to upload it in openstack.

In my setup, image is located in /var/tmp. Refer step 8 to know the image file location.

We have successfully created the Ubuntu cloud instance image.

Import newly created Image in Openstack:

1. Login to Openstack controller node.

2. Copy the Ubuntu image file which we have created in the KVM machine. I kept the new image instance file in /var/tmp.

3.Create the image using glance using the source image file.

In-case if you get error like below (403 Forbidden,Access was denied to this resource), make sure you have sourced properly.

You can gain the admin access and try to re-run it if you get above error.

Launch the Ubuntu Instance from Dashboard:

1. Login to openstack Dashboard.

2.  When  you click on launch instance tab , you should be able to choose ubuntu image like below.

3.  Once the instance is up & running , click on the instance & see the console.

In this article , we have see that how to create the custom OS image for the cloud instance and importing in to the openstack glance . At last ,we have launched the instance using the newly created image. Hope this article is informative to you.

The post How to create a custom image for Openstack ? appeared first on UnixArena.

Show more