Skip to content

Instantly share code, notes, and snippets.

@kordless
Last active June 9, 2020 13:55
Show Gist options
  • Save kordless/7137609 to your computer and use it in GitHub Desktop.
Save kordless/7137609 to your computer and use it in GitHub Desktop.
Building a CentOS Image for OpenStack in 10 Minutes

Building a CentOS Image for OpenStack in 10 Minutes

There are several pre-built images for OpenStack, including Ubuntu, Red Hat and Fedora. Images for CentOS and a few other Linux distros are not readily available, but they can be built from their respective installers using VirtualBox.

This guide provides a step-by-step method for building and deploying a CentOS images for OpenStack.

Prerequisites for Building a CentOS Image

The scripts for assisting in the build can be checked out from BlueChip's Github account:

mkdir ~/bluechip; cd ~/bluechip
git clone https://ababab
cd bluecent

Note: While the scripts are not necessary to complete the build, the steps below assume the above directory structure exists.

You'll also need to install VirtualBox on your computer before proceeding.

Double click the package to run through the installation on your local machine and then continue by watching the video guide.

Video Guide

It is recommended you familiarize yourself with the build process by watching the screencast below before proceeding.

ScreenShot

Installing CentOS on VirtualBox

The process for installing CentOS requires downloading the net install ISO, mounting it to a new VM in VirtualBox, and then running through the install using the graphical interface console in VirtualBox.

Option #1: Build the VM from the Scripts

Several bash scripts have been written to speed up the install process. The manual instructions are located below for completeness.

Start the automated setup of a CentOS install in VirtualBox by doing the following:

cd ~/bluechip/bluecent
./install_centos.sh

Proceed with the install by skipping over the 'Option #2' section and going straight into 'Start the Install' section below.

Option #2: Build the VM Manually from the Command Line

The following contains detailed commands for building a new VirtualBox instance and populating it with the CentOS 6.4 net installer. If you want to install via another ISO or version, please refer to the list of CentOS mirrors.

Download the Net Installer

Start by downloading the network based installer from the Stanford mirror:

cd ~/bluechip/bluecent
curl http://mirror.stanford.edu/yum/pub/centos/6.4/isos/x86_64/CentOS-6.4-x86_64-netinstall.iso > centos_netinstall.iso
Create the VM Using VBoxManage

VBoxManage is the command line interface for VirtualBox. Start by creating the VM and its disk:

VBoxManage createvm --name "BlueCentOS" --ostype "RedHat_64" --register
VBoxManage createhd --filename ~/VirtualBox\ VMs/BlueCentOS/BlueCentOS.qcow --size 8192

Note: This assumes VirtualBox is creating instances in the default 'VirtualBox VMs' directory in your home directory.

Now create and attach the disk:

VBoxManage storagectl "BlueCentOS" --name "SATA Controller" --add sata --controller IntelAHCI
VBoxManage storageattach "BlueCentOS" --storagectl "SATA Controller" --port 0 --device 0 --type hdd --medium ~/VirtualBox\ VMs/BlueCentOS/BlueCentOS.qcow

Next, attach the install file as a DVD:

VBoxManage storagectl BlueCentOS --name "IDE Controller" --add ide
VBoxManage storageattach BlueCentOS --storagectl "IDE Controller" --port 0 --device 0 --type dvddrive --medium centos_netinstall.iso

Finally, add a few key settings, including port forwarding for ssh:

VBoxManage modifyvm BlueCentOS --ioapic on
VBoxManage modifyvm BlueCentOS --boot1 dvd --boot2 disk --boot3 none --boot4 none
VBoxManage modifyvm BlueCentOS --memory 1024 --vram 128
VBoxManage modifyvm BlueCentOS --natpf1 "ssh,tcp,,2222,,22"

Start the Install

To start the install, open VirtualBox and click on the 'BlueCentOS' instance and click on the start button at the top. Proceed through the install using the following steps:

  • Select 'Install or upgrade an existing system' (hit enter).
  • Hit 'tab' to select 'Skip' and hit enter on the 'testing media' dialog.
  • Select 'English' for language and 'us' keyboard (hit enter twice).
  • Under the 'installation method' dialog, select 'URL' and hit enter.
  • Under TCP/IP configuration, hit 'tab' (7) times to select 'OK' and hit enter.
  • Wait for the network configuration to take place.

You'll be prompted for a URL to use for the install. Here's a screenshot:

ScreenShot

Under the URL for the CentOS installation, enter the following (sorry, no cut/paste with the VirtualBox console):

http://mirror.stanford.edu/centos/6/os/x86_64

Hit 'tab' twice and hit enter on 'OK'.

Now run through the following steps to configure the rest of the CentOS install, all in the graphical interface:

  • Click the 'next' button on the welcome screen.
  • Click the 'next' button on the device selection screen.
  • Click 'discard any data' on the warning screen.
  • Click 'next' on the name this computer screen. This will be handled by cloud-init later.
  • Select your timezone and click 'next' to proceed to setting root's password.
  • Enter 'f00bar' for your root password. Ignore the short password warning - we'll wipe it later.
  • Leave 'replace system' checked and click 'next' on install type screen.
  • Click 'write changes to disk' and then click 'next'.
  • Click 'next' on the 'select software to install' screen.

The install process should commence and complete in about 5 minutes. When the button saying 'reboot' appears, close the VM's window and select 'power off' from the close options.

Remove the DVD and Start the Instance

To boot into the new system, the DVD drive needs to be unmounted. Enter the following to unmount the drive:

VBoxManage storageattach "BlueCentOS" --storagectl "IDE Controller" --port 0 --device 0 --type dvddrive --medium none

The instance is now ready to boot for the first time. Go into VirtualBox and click on the new instance and click start at the top of the VirtualBox Manager window.

Install a Few Key Packages

The instance should be running and booted in a minute or so. A forwarding rule has been built to allow you to ssh into the instance:

ssh root@localhost -p 2222

Remember, your password for root is 'f00bar'. Once you are logged in, install git and checkout the scripts again:

yum -y install git
  • rpm -Uvh http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
  • yum install cloud-init
  • yum install rsync
  • adduser ec2-user
  • mkdir /home/ec2-user/.ssh/
  • chown -R ec2-user.ec2-user .ssh
  • add ec2-user to wheel: vi /etc/group
  • remove tty requirement from vi /etc/sudoers
  • NOPASSWD in sudoers (uncomment wheel example)
  • edit /etc/ssh/sshd_config and set cleartext password off
  • passwd -l root
  • passwd -l ec2-user
  • rm /etc/udev/rules.d/70-persistent-net.rules
  • vi /etc/sysconfig/network-scripts/ifcfg-eth0

edit the /boot/grub/menu.lst

serial –unit=0 –speed=115200 terminal –timeout=10 console serial

kernel line... console=tty0 console=ttyS0,115200n8

#!/bin/bash
# download the net installer
ISO="centos_netinstall.iso"
if [ -f $ISO ]
then
echo "ISO downloaded already!"
else
curl http://mirror.stanford.edu/yum/pub/centos/6.4/isos/x86_64/CentOS-6.4-x86_64-netinstall.iso > $ISO
echo "ISO downloaded!"
fi
# build the VM in VirtualBox
VM="BlueCentOS"
VBoxManage createvm --name $VM --ostype "RedHat_64" --register
VBoxManage createhd --filename ~/VirtualBox\ VMs/$VM.qcow --size 8192
# add a qcow storage device
VBoxManage storagectl $VM --name "SATA Controller" --add sata --controller IntelAHCI
VBoxManage storageattach $VM --storagectl "SATA Controller" --port 0 --device 0 --type hdd --medium ~/VirtualBox\ VMs/$VM.qcow
# add the dvd install
VBoxManage storagectl $VM --name "IDE Controller" --add ide
VBoxManage storageattach $VM --storagectl "IDE Controller" --port 0 --device 0 --type dvddrive --medium $PWD/$ISO
# do a few important things
VBoxManage modifyvm $VM --ioapic on
VBoxManage modifyvm $VM --boot1 dvd --boot2 disk --boot3 none --boot4 none
VBoxManage modifyvm $VM --memory 1024 --vram 128
# set port forwarding
VBoxManage modifyvm $VM --natpf1 "ssh,tcp,,2222,,22"
#!/bin/bash
VBoxManage storageattach "BlueCentOS" --storagectl "IDE Controller" --port 0 --device 0 --type dvddrive --medium none
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment