Create a Good Image for OpenStack

This post will describe how to construct a good OpenStack image. After VM started, cloud-init will overwrite VM’s settings (Network, Service, User and so on), so we can configure our image file for better user experience.

Environment Preparation

We use Ubuntu 16.04 for demo, you can decide use which Linux distribution by yourself. Install following package in your Image build machine.

qemu-utils

virtinst

virt-manager

libguestfs-tools

Create Image disk

Here is my custom create script, take a look or use following command:

Install and operate VM by virt-viewer

If you were stuck in /dev/vda1: clean, 60739/589824 files, 367171/2359040 blocks, you can select the different video simulated options, it might work.

Install Prerequisite Package

cloud-init（Install when your vm is done）

vim

dhcpcd5

openssh-server

VM Configuration

dhcpcd configuration

Delete network interface dhcp config from:

123

# The primary network interfaceauto ens3iface ens3 inet dhcp

to

12

# The primary network interfaceauto ens3

and start service: sudo service dhcpcd start

sudo without password

Use sudo visudo to edit sudoer file as following:

# User privilege specification
root ALL=(ALL:ALL) ALL
# Members of the admin group may gain root privileges
%admin ALL=(ALL) ALL
# Allow members of group sudo to execute any command
%sudo ALL=(ALL:ALL) ALL
ubuntu ALL=(ALL) NOPASSWD:ALL
# See sudoers(5) for more information on "#include" directives:
#includedir /etc/sudoers.d