We can now create our custom OpenStack image, however, it is advisable to do so outside of our OpenStack installation. Also, you need to make sure that you do not have VirtualBox, Fusion, or similar virtualization technology, running on the system where you will be creating your image. We will be creating a KVM-based, CentOS image.
To begin with, ensure you are logged in to a Linux system that is not your OpenStack environment.
On Ubuntu, install the kvm/qemu
and libvirt
libraries:
sudo apt-get install qemu-kvm libvirt-bin virt-manager
Start the libvirt-bin
service with the following command:
sudo start libvirt-bin
On CentOS or RHEL:
sudo yum groupinstall "Virtualization" "Virtualization Platform" sudo chkconfig libvirtd on sudo service libvirtd start
On Fedora:
sudo yum groupinstall "Virtualization" "Virtualization Platform" sudo systemctl enable libvirtd sudo systemctl start libvirtd
Ideally, you will also need a VNC client, though our example could be done without using one.
Carry out the following steps to create a custom image:
kickstart
file called openstack.txt
:install text url --url http://mirror.rackspace.com/CentOS/6.6/os/x86_64/ lang en_US.UTF-8 keyboard us network --onboot yes --bootproto dhcp --noipv6 timezone --utc America/Chicago zerombr clearpart --all --initlabel bootloader --location=mbr --append="crashkernel=auto rhgb quiet" part / --fstype=ext4 --size=1024 --grow authconfig --enableshadow --passalgo=sha512 rootpw openstack firewall --disable selinux --disabled skipx shutdown %packages @core openssh-server openssh-clients wget curl git man vim ntp %end %post %end
sudo virt-install --virt-type kvm --name centos-6.6 --ram 1024 --location=http://mirror.rackspace.com/CentOS/6.6/os/x86_64/ --disk path=/tmp/centos-6.6-vm.img,size=5 --network network=default --graphics vnc,listen=0.0.0.0 --noautoconsole --os-type=linux --os-variant=rhel6 --initrd-inject=centos-6.6-x86_64-openstack.txt --extra-args="noverifyssl console=tty0 console=ttyS0,115200 ks=file:/centos-6.6-x86_64-openstack.txt "
Starting install... Retrieving file .treeinfo... | 728 B 00:00 ... Retrieving file vmlinuz... | 7.9 MB 00:00 ... Retrieving file initrd.img... | 66 MB 00:00 ... Creating domain... | 0 B 00:01 Domain installation still in progress. You can reconnect to the console to complete the installation process.
VNC server
will be running by default on host:5900
:If you do not have access to a VNC client, or for some reason cannot use it, wait for 10 minutes (a rough estimate) and proceed to the next step. We will assume things worked.
virsh
with the following commands:sudo virsh list --all Id Name State ---------------------------------------------------- 62 centos-6.6 running
sudo virsh destroy centos-6.6 Domain centos-6.6 destroyed
sudo virsh start centos-6.6 Domain centos-6.6 started
root
user with the password openstack
. To escape from the console session, press Ctrl + ].sudo virsh console centos-6.6 Connected to domain centos-6.6 Escape character is ^]
Now, let's exit by clicking Enter:
CentOS release 6.6 (Final) Kernel 2.6.32-504.el6.x86_64 on an x86_64 localhost.localdomain login: root Password:
cloud-init
package with the following commands:sudo yum install http://dl.fedoraproject.org/pub/epel/6Server/x86_64/epel-release-6-8.noarch.rpm sudo yum install cloud-init cloud-utils cloud-utils-growpart
config file /etc/cloud/cloud.cfg
with the following commands:rm /etc/cloud/cloud.cfg vi /etc/cloud/cloud.cfg
users: - default disable_root: 1 ssh_pwauth: 0 locale_configfile: /etc/sysconfig/i18n mount_default_fields: [~, ~, 'auto', 'defaults,nofail', '0', '2'] resize_rootfs_tmp: /dev ssh_deletekeys: 0 ssh_genkeytypes: ~ syslog_fix_perms: ~ cloud_init_modules: - bootcmd - write-files - resizefs - set_hostname - update_hostname - update_etc_hosts - rsyslog - users-groups - ssh cloud_config_modules: - mounts - locale - set-passwords - timezone - puppet - chef - salt-minion - mcollective - disable-ec2-metadata - runcmd cloud_final_modules: - rightscale_userdata - scripts-per-once - scripts-per-boot - scripts-per-instance - scripts-user - ssh-authkey-fingerprints - keys-to-console - phone-home - final-message system_info: distro: rhel default_user: name: centos lock_passwd: True shell: /bin/bash sudo: ["ALL=(ALL) NOPASSWD: ALL"] paths: cloud_dir: /var/lib/cloud templates_dir: /etc/cloud/templates ssh_svcname: sshd
sudo echo "NOZEROCONF=yes" >> /etc/sysconfig/network
sudo rm -f /etc/udev/rules.d/70-persistent-net.rules
/etc/sysconfig/network-scripts/ifcfg-eth0
file and remove lines starting with HWADDR
and UUID
:sudo sed -i '/HWADDR/d' /etc/sysconfig/network-scripts/ifcfg-eth0 sudo sed -i '/UUID/d' /etc/sysconfig/network-scripts/ifcfg-eth0
/etc/sysconfig/network-scripts/ifcfg-eth0
file should look like this:DEVICE="eth0" BOOTPROTO="dhcp" IPV6INIT="no" MTU="1500" NM_CONTROLLED="yes" ONBOOT="yes" TYPE="Ethernet"
yum
, logs
, temporary
files, and history with the following commands:sudo yum clean all sudo rm -rf /var/log/* sudo rm -rf /tmp/* sudo history -c
sudo shutdown -h now
sudo qemu-img convert -c /tmp/centos-6.6-vm.img -O qcow2 /tmp/centos-6.6.img
glance image-create --name centos-6.6 --disk-format=qcow2 --container-format=bare --file /tmp/centos-6.6.img