# Creating CentOS VM Image from Scratch

There are multiple ways to create a CentOS image compatible with OpenStack Glance image repository. You can:

* Download a pre-built image from RedHat RDO: <https://openstack.redhat.com/Image_resources> (default user is 'centos' on these images)
* Create the image from Scratch with or without cloud-init

{% hint style="info" %}
**Note**

The benefit of cloud-init is that it allows customization of virtual machines
{% endhint %}

{% hint style="success" %}
**Recommendation**

Platform9 recommends that you create your virtual machine images from scratch, as this gives you full flexibility to customize the image per your specific requirements, and ensure that it's configured appropriately, to reduce future errors.
{% endhint %}

This tutorial describes how you can create a CentOS guest image from scratch and also optionally install cloud-init.

### Step 1 - Download ISO

ISO images are available form CentOS and its mirrors <http://wiki.centos.org/Download>

Assuming you have a CentOS/Ubuntu system with libvirt and all the dependencies installed (see here for details: <http://virt-manager.org/>), go to /var/lib/libvirt/images and copy the downloaded iso.

{% tabs %}
{% tab title="CentOS" %}

```yaml
cd /var/lib/libvirt/images
wget http://mirror.hmc.edu/centos/6.6/isos/x86_64/CentOS-6.6-x86_64-minimal.iso
```

{% endtab %}
{% endtabs %}

### Step 2 - Create a Virtual Machine

Fire up your virt-manager and create a new virtual machine.

<figure><img src="https://1126553421-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZ8EciOmTwpkZCkUOCYd9%2Fuploads%2Fgit-blob-c499ede06d7468bbb323732473ba9d175a0da488%2F1605290628.png?alt=media" alt=""><figcaption></figcaption></figure>

Pick the ISO you just downloaded.

<figure><img src="https://1126553421-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZ8EciOmTwpkZCkUOCYd9%2Fuploads%2Fgit-blob-9e55151fa4fac1d4662d0e4bd30c96de5aa10c3c%2F1605290658.png?alt=media" alt=""><figcaption></figcaption></figure>

Use OS type = Linux, Version= Red Hat Enterprise Linux 6

<figure><img src="https://1126553421-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZ8EciOmTwpkZCkUOCYd9%2Fuploads%2Fgit-blob-e8fb6f1c65bee4da127b57dce72e742541a86496%2F1605290680.png?alt=media" alt=""><figcaption></figcaption></figure>

Pick the amount of CPU, Memory and Storage.

<figure><img src="https://1126553421-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZ8EciOmTwpkZCkUOCYd9%2Fuploads%2Fgit-blob-9be6bda4e6db4e8d2058d11aed23a62a3f4ea7ea%2F1605290708.png?alt=media" alt=""><figcaption></figcaption></figure>

<figure><img src="https://1126553421-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZ8EciOmTwpkZCkUOCYd9%2Fuploads%2Fgit-blob-d4767aab37d6dd14a66bfdc59af7a232d29e1785%2F1605290724.png?alt=media" alt=""><figcaption></figcaption></figure>

### Step 3 - Install & Configure OS

Pick the options you like, I generally install minimal with just SSH. Depending upon how you want your consumers to logon to the virtual machine, you can configure the users, password and SSH configuration (no-password vs password logon). I suggest putting a specific admin user with a password/ssh key that can be used by your system administrators to logon. Platform9 (and OpenStack), will allow the owner of the virtual machine to pass a SSH key at boot time, but this specific admin user can be used exclusively by a system administrator as a powerful debugging tool.

### Step 4 - (Optional) Install cloud-init

Once the OS is installed, reboot and log in; by default OS comes up with DHCP configured. Install epel repository to fetch cloud-init and then install cloud-init.

<figure><img src="https://1126553421-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZ8EciOmTwpkZCkUOCYd9%2Fuploads%2Fgit-blob-0e93b4d757d3742db666a6143a10ce561437e828%2F1605290754.png?alt=media" alt=""><figcaption></figcaption></figure>

### Step 6 - Power Off the Virtual Machine

Now go ahead and power-off the virtual machine. You are one step away from the setup.

### Step 7 - Call virt-sysprep

{% tabs %}
{% tab title="Bash" %}

```bash
cd /var/lib/libvirt/images/
virt-sysprep -a
```

{% endtab %}
{% endtabs %}

Congratulations! Your image is ready, copy it to the "ImageLibrary" in Platform9 or any other glance installation and it is ready to go.
