24. Create KVM CentOS 7 ImageΒΆ

This page is not based on the OpenStack Installation Guide.

  1. From a web browser, access http://*CONTROLLER_ADDRESS*/dashboard.
  2. Log in using the admin credentials.
  3. In the left-hand menu, under “Admin”, and then “System”, click on “Hypervisors”:
_images/page24-hypervisors.png
  1. Click on the “Compute Host” tab:
_images/page24-compute-host.png
  1. Next to “compute1-vm”, click on “Disable Service”.
  2. Enter a reason of “Building KVM image”, and click “Disable Service”:
_images/page24-disable-service.png
  1. In the left-hand menu, under “Project”, and then “Compute”, click on “Instances”. Click on “Launch Instance”.
  2. Give the instance the name “centos7-kvm-build”, use the flavor m1.small (for a 20GB disk), and select “Boot from image” and the “CentOS 7 ISO” image. Launch the instance:
_images/page24-launch-instance1.png
  1. Wait for the instance to enter “Active” state. Then, in the left-hand menu, under “Project”, and then “Compute”, click on “Volumes”. Click on “Create Volume”.
  2. Name the image “centos7-kvm-build”, and set the size to 20 GB. Click “Create Volume”:
_images/page24-create-volume.png
  1. Once the volume enters “Available” status, click the “Actions” drop-down next to the volume, and select “Manage Attachments”.
  2. Under “Attach to instance”, select “centos7-kvm-build”, and click “Attach Volume”:
_images/page24-attach-volume.png
  1. In the left-hand menu, under “Project”, and then “Compute”, click on “Instances”. Under the “Actions” drop-down for the “centos7-kvm-build” instance, click on “Hard Reboot Instance”. Click on “Hard Reboot Instance” to confirm:
_images/page24-reboot-instance.png
  1. Wait for the instance to go back to “Active” state, and then click on the instance. Click on the “Console” tab, and then click on the grey “Connected (unencrypted) to: QEMU” bar so that keyboard input will be directed to the console:
_images/page24-console.png
  1. Highlight “Install CentOS 7”, and Enter.
  2. Wait for the installer to boot:
_images/page24-installer.png
  1. Select language and set the timezone.
  2. Click on “network & hostname” and activate the network interface by setting the switch to “On”:
_images/page24-enable-interface.png
  1. Click on “Installation Source”. Set the source to network, and then define a known-good mirror. You can use http://mirror.rackspace.com/CentOS/7.2.1511/os/x86_64/.
  2. Click on “Installation Destination”. Select “I will configure partitioning” and click on “Done”:
_images/page24-i-will-configure-partitioning.png
  1. Under “New mount points will use the following partition scheme”, select “Standard Partition”.
  2. Click on the + button. Set the mount point to / and click “Add mount point”:
_images/page24-set-mount-point.png
  1. Set “File System” to “ext4”, and then click “Done”:
_images/page24-ext4.png
  1. A yellow warning bar will appear. Click “Done” again, and then click on “Accept Changes”:
_images/page24-accept-changes.png
  1. Click “Begin installation”. Click on “Root Password” and set a good password.
  2. Once installation is complete, click “Reboot”.
  3. The server will be attempting to boot from the ISO once more. Press any key to stop the countdown.
  4. In the left-hand menu, under “Project” and then “Compute”, click on “Instances”. Select the “centos7-kvm-build” instance, and then click on “Terminate Instances”. Click “Terminate Instances” to confirm:
_images/page24-terminate-instances1.png
  1. In the left-hand menu, under “Project” and then “Compute”, click on Volumes.
  2. Click on the “Actions” drop-down next to “centos7-kvm-build”, and click on “Upload to Image”. Name the image “centos7-kvm-initialkick”, and set the “Disk Format” to “QCOW2”. Upload the image:
_images/page24-upload-image.png
  1. The volume will go to “Uploading” state. Wait for this to return to “Available” state.
  2. In the left-hand menu, under “Project” and then “Compute”, click on “Images”. Click on the “centos7-kvm-initialkick” image, which should be in “Active” state.
  3. In the top-right drop-down, click on “Update Metadata”.
  4. On the left-hand side, in the “custom” box, enter “hypervisor_type” and click on the + button.
  5. On the right-hand side, in the “hypervisor_type” box, enter “kvm”.
  6. On the left-hand side, in the “custom” box, enter “auto_disk_config”, and click on the + button.
  7. On the right-hand side, in the “auto_disk_config” box, enter “true”.
  8. On the left-hand side, in the “custom” box, enter “hw_qemu_guest_agent” and click on the + button.
  9. On the right-hand side, in the “hw_qemu_guest_agent” box, enter “true”, and click on the “Save” button:
_images/page24-update-metadata.png
  1. In the left-hand menu, under “Project”, and then “Compute”, click on “Volumes”. Highlight the “centos7-kvm-build” volume, and click on “Delete Volumes”. Click “Delete Volumes” to confirm:
_images/page24-delete-volume.png
  1. In the left-hand menu, under “Project” and then “Compute”, click on “Instances”.
  2. Click on “Launch Instance”. Give the instance the name “centos7-kvm-build”, use the flavor m1.small (for a 20GB disk), and select “Boot from image” and the “centos7-kvm-initialkick” image. Launch the instance:
_images/page24-launch-instance2.png
  1. Wait for the instance to enter “Active” state. SSH to the new instance as “root”, using the root password used during setup.

  2. Delete the static hostname file:

    # rm /etc/hostname
    
  3. Stop and disable the firewalld:

    # systemctl disable firewalld.service
    # systemctl stop firewalld.service
    
  4. Disable SELINUX:

    # setenforce 0
    # vim /etc/sysconfig/selinux
    
      SELINUX=permissive
    
  5. Update all packages on the instance:

    # yum update
    
  6. Install the qemu guest agent, cloud-init and cloud-utils:

    # yum install qemu-guest-agent cloud-init cloud-utils
    
  7. Enable and start the qemu-guest-agent service:

    # systemctl enable qemu-guest-agent.service
    # systemctl start qemu-guest-agent.service
    
  8. Enable kernel console logging:

    # vim /etc/sysconfig/grub
    
  • Append “console=ttyS0 console=tty0” to the end of the GRUB_CMDLINE_LINUX setting. For example:

    GRUB_CMDLINE_LINUX="crashkernel=auto rhgb quiet console=ttyS0 console=tty0"
    
  1. Rebuild the grub config file:

    # grub2-mkconfig -o /boot/grub2/grub.cfg
    
  2. Disable user creation at instance creation time:

    # vim /etc/cloud/cloud.cfg
    
      disable_root: 0
    
  • Also delete the “default_user:” section under “system_info”.
  1. Delete the static network configuration file:

    # rm /etc/sysconfig/network-scripts/ifcfg-eth0
    
  2. Clear the root bash history:

    # rm /root/.bash_history; history -c
    
  3. In horizon, click the “Create Snapshot” button next to the Instance. Name the image “CentOS 7 (KVM)”:

_images/page24-create-snapshot.png
  1. Wait for the image to go to “Active” state and then, in the drop-down box next to the image, click on “Edit Image”.
  2. Check the “public” and “protected” boxes, and click on “Update Image”:
_images/page24-update-image.png
  1. Select the “centos7-kvm-initialkick” image, and click on “Delete Images”. Click “Delete Images” to confirm:
_images/page24-delete-images.png
  1. In the left-hand menu, under “Project” and then “Compute”, click on “Instances”.
  2. Highlight the “centos7-kvm-build” instance, and click on “Terminate Instances”. Click “Terminate Instances” to confirm:
_images/page24-terminate-instances2.png
  1. In the left-hand menu, under “Admin” and then “System” click on “Hypervisors”. Next to “compute1-vm”, click on “Enable Service”.