Creating qcow2 CentOS Image for OpenStack
Updated March 9, 2012 by Karve |Tags: None
Creating a CentOS 6 image
Same instructions can be used for Redhat 6 and Fedora
Same instructions can be used for Redhat 6 and Fedora
These instructons were run on Ubuntu 11.10 Server x86_64. Run
the following in a VNC Session on the hypervisor, you will need to install the
vnc4server, vncviewer.
#
Install the kvm-pxe to avoid the "pci_add_option_rom: failed to find
romfile "pxe-rtl8139.bin"" message
sudo apt-get install kvm-pxe
sudo apt-get install kvm-pxe
#
Download the CentOS DVD iso, alternatively check the mirrors at
http://isoredirect.centos.org/centos/6/isos/x86_64/ for downloading relevant
iso.
wget http://mirrors.usc.edu/pub/linux/distributions/centos/6.2/isos/x86_64/CentOS-6.2-x86_64-LiveDVD.iso
wget http://mirrors.usc.edu/pub/linux/distributions/centos/6.2/isos/x86_64/CentOS-6.2-x86_64-LiveDVD.iso
#
Create a qcow2 image that represents the main HDD of the virtual machine and
swap space. (Note: 5GB is not sufficient)
kvm-img create -f qcow2 centos.qcow2 10G
kvm-img create -f qcow2 centos.qcow2 10G
# Boot
the Virtual Machine from DVD iso, select an unused vnc
sudo kvm -m 1024 -cdrom CentOS-6.2-x86_64-LiveDVD.iso -drive file=centos.qcow2,if=virtio,index=0 -boot d -net nic -net user -nographic -vnc :2
# This command will block
sudo kvm -m 1024 -cdrom CentOS-6.2-x86_64-LiveDVD.iso -drive file=centos.qcow2,if=virtio,index=0 -boot d -net nic -net user -nographic -vnc :2
# This command will block
#
Connect to VM using vncviewer from another window
vncviewer :2
# This will show you the desktop that was booted form the DVD iso file. Now we install the CentOS on the attached image file.
vncviewer :2
# This will show you the desktop that was booted form the DVD iso file. Now we install the CentOS on the attached image file.
#
Double Click on the "Install to Hard Drive" icon on the desktop and
click Next
# Select the US English and click Next
# Select the default Storage and click Next, Click "Yes, Discard any data" on the popup
# Leave the default hostname and Click Next
# Default TimeZone and click Next
# Type the root password (at least 6 characters long) and confirm and click Next
# Select "Create custom layout", the "Review and modify partitioning layout" will automatically be checked and click Next
# Select the Free and Click on Create, Standard Partition, Create
# Select / as the Mount Point with ext4 as the File System Type and 9120 as the Size (MB), Fixed Size and click OK
# Select the Free and Click on Create, Standard Partition, Create
# Don't select the "Mount Point", instead Select swap for the "File System Type", the Mount Point will be grayed out, select the "Fill to maximum allowable size" and click OK
# Now you show see the vda1 with ext4 and vda2 as swap, Click Next, Format and Click on "Write Changes to Disk"
# Leave the defaults for the Boot loader and click Next
# It will copy the live image to hard drive, complete the post-installation. After completion, it will show the "Congratulations" message. Click Close.
# Select System and "Shut Down" the VM
# Select the US English and click Next
# Select the default Storage and click Next, Click "Yes, Discard any data" on the popup
# Leave the default hostname and Click Next
# Default TimeZone and click Next
# Type the root password (at least 6 characters long) and confirm and click Next
# Select "Create custom layout", the "Review and modify partitioning layout" will automatically be checked and click Next
# Select the Free and Click on Create, Standard Partition, Create
# Select / as the Mount Point with ext4 as the File System Type and 9120 as the Size (MB), Fixed Size and click OK
# Select the Free and Click on Create, Standard Partition, Create
# Don't select the "Mount Point", instead Select swap for the "File System Type", the Mount Point will be grayed out, select the "Fill to maximum allowable size" and click OK
# Now you show see the vda1 with ext4 and vda2 as swap, Click Next, Format and Click on "Write Changes to Disk"
# Leave the defaults for the Boot loader and click Next
# It will copy the live image to hard drive, complete the post-installation. After completion, it will show the "Congratulations" message. Click Close.
# Select System and "Shut Down" the VM
# Now
back to the bash prompt on the hypervisor, start the VM from the qcow2 image
without the DVD iso
sudo kvm -m 1024 -drive file=centos.qcow2,if=virtio,index=0,boot=on -boot c -net nic -net user -nographic -vnc :2
sudo kvm -m 1024 -drive file=centos.qcow2,if=virtio,index=0,boot=on -boot c -net nic -net user -nographic -vnc :2
#
Reconnect to VM using vncviewer from the second window
vncviewer :2
# This will show you the Welcome page. Click Forward, Accept license, Forward
# Do not create any user (you may create if you want to, but not necessary if you only want root), click Forward
# Select Date time and click Forward# Select Date and click forward
# Ignore the "Insufficient memory to configure kdump!" message, click OK and Finish.
# Click on "Other", type root and hit Enter and your password and hit Enter and login to the VM.
# Close the root superuser warning message.
# Rightclick on the desktop and Open Terminal
# Install the latest updates
sudo yum -y update
# Enable ssh daemon to autostart
sudo chkconfig --level 345 sshd on
# Check that the levels for 345 are on
sudo chkconfig --list | grep sshd
# The firewall is set by default to allow ssh on port 22, you can check it by going to System, Administration, Firewall to verify
# Shutdown the VM (Careful - Don't shutdown the hypervisor, run this in VM's Terminal)
shutdown -h now
vncviewer :2
# This will show you the Welcome page. Click Forward, Accept license, Forward
# Do not create any user (you may create if you want to, but not necessary if you only want root), click Forward
# Select Date time and click Forward# Select Date and click forward
# Ignore the "Insufficient memory to configure kdump!" message, click OK and Finish.
# Click on "Other", type root and hit Enter and your password and hit Enter and login to the VM.
# Close the root superuser warning message.
# Rightclick on the desktop and Open Terminal
# Install the latest updates
sudo yum -y update
# Enable ssh daemon to autostart
sudo chkconfig --level 345 sshd on
# Check that the levels for 345 are on
sudo chkconfig --list | grep sshd
# The firewall is set by default to allow ssh on port 22, you can check it by going to System, Administration, Firewall to verify
# Shutdown the VM (Careful - Don't shutdown the hypervisor, run this in VM's Terminal)
shutdown -h now
# Now back to the bash prompt on the hypervisor
The centos.qcow2 is ready to be added to glance
Adding the image to glance
# Run the following command to get the Access token Id. Note
set the hostname to the glance hostname if it is different from current
hostname
myhostname=`hostname`
accesstokenid=`curl -d '{"auth":{"passwordCredentials":{"username": "adminUser","password": "password"}}}' -H "Content-type: application/json" http://$myhostname:35357/v2.0/tokens | python -mjson.tool | grep -A3 access | grep id | sed "s/.*:.*\"\(.*\)\"/\\1/"`
echo $accesstokenid
myhostname=`hostname`
accesstokenid=`curl -d '{"auth":{"passwordCredentials":{"username": "adminUser","password": "password"}}}' -H "Content-type: application/json" http://$myhostname:35357/v2.0/tokens | python -mjson.tool | grep -A3 access | grep id | sed "s/.*:.*\"\(.*\)\"/\\1/"`
echo $accesstokenid
# or
curl -d '{"auth":{"passwordCredentials":{"username": "adminUser","password": "password"}}}' -H "Content-type: application/json" http://`hostname`:35357/v2.0/tokens | python -mjson.tool
# Note the access token id above and set the accesstokenid manually
sudo glance -A $accesstokenid -v add name="centos-qcow2" is_public=True disk_format="qcow2" < centos6.qcow2
curl -d '{"auth":{"passwordCredentials":{"username": "adminUser","password": "password"}}}' -H "Content-type: application/json" http://`hostname`:35357/v2.0/tokens | python -mjson.tool
# Note the access token id above and set the accesstokenid manually
sudo glance -A $accesstokenid -v add name="centos-qcow2" is_public=True disk_format="qcow2" < centos6.qcow2
Convert disk format to raw
Instead of qcow2, you can convert the image to raw and add it to
glance as follows. Note: set the accesstokenid as above before adding to
glance.
qemu-img convert -O raw centos.qcow2 centos.raw
sudo glance -A $accesstokenid -v add name="centos-raw" is_public=True < centos.raw
sudo glance -A $accesstokenid -v add name="centos-raw" is_public=True < centos.raw
List the images
nova --username=adminUser --apikey=password
--projectid=adminTenant --url=http://`hostname`:5000/v2.0/ image-list
0 comments:
Post a Comment