mirror of
https://github.com/apache/cloudstack.git
synced 2025-12-18 19:44:21 +01:00
98 lines
9.3 KiB
HTML
98 lines
9.3 KiB
HTML
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||
<html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>12.11. Importing Amazon Machine Images</title><link rel="stylesheet" type="text/css" href="Common_Content/css/default.css" /><link rel="stylesheet" media="print" href="Common_Content/css/print.css" type="text/css" /><meta name="generator" content="publican 2.8" /><meta name="package" content="Apache_CloudStack-Admin_Guide-4.0.0-incubating-en-US-1-" /><link rel="home" href="index.html" title="CloudStack Administrator's Guide" /><link rel="up" href="working-with-templates.html" title="Chapter 12. Working with Templates" /><link rel="prev" href="create-windows-template.html" title="12.10. Creating a Windows Template" /><link rel="next" href="convert-hyperv-vm-to-template.html" title="12.12. Converting a Hyper-V VM to a Template" /></head><body><p id="title"><a class="left" href="http://cloudstack.org"><img src="Common_Content/images/image_left.png" alt="Product Site" /></a><a class="right" href="http://docs.cloudstack.org"><img src="Common_Content/images/image_right.png" alt="Documentation Site" /></a></p><ul class="docnav"><li class="previous"><a accesskey="p" href="create-windows-template.html"><strong>Prev</strong></a></li><li class="next"><a accesskey="n" href="convert-hyperv-vm-to-template.html"><strong>Next</strong></a></li></ul><div xml:lang="en-US" class="section" id="import-ami" lang="en-US"><div class="titlepage"><div><div><h2 class="title" id="import-ami">12.11. Importing Amazon Machine Images</h2></div></div></div><div class="para">
|
||
The following procedures describe how to import an Amazon Machine Image (AMI) into CloudStack when using the XenServer hypervisor.
|
||
</div><div class="para">
|
||
Assume you have an AMI file and this file is called CentOS_6.2_x64. Assume further that you are working on a CentOS host. If the AMI is a Fedora image, you need to be working on a Fedora host initially.
|
||
</div><div class="para">
|
||
You need to have a XenServer host with a file-based storage repository (either a local ext3 SR or an NFS SR) to convert to a VHD once the image file has been customized on the Centos/Fedora host.
|
||
</div><div class="note"><div class="admonition_header"><h2>Note</h2></div><div class="admonition"><div class="para">
|
||
When copying and pasting a command, be sure the command has pasted as a single line before executing. Some document viewers may introduce unwanted line breaks in copied text.
|
||
</div></div></div><div class="orderedlist"><ol><li class="listitem"><div class="para">
|
||
Set up loopback on image file:
|
||
</div><pre class="programlisting"># mkdir -p /mnt/loop/centos62
|
||
# mount -o loop CentOS_6.2_x64 /mnt/loop/centos54
|
||
</pre></li><li class="listitem"><div class="para">
|
||
Install the kernel-xen package into the image. This downloads the PV kernel and ramdisk to the image.
|
||
</div><pre class="programlisting"># yum -c /mnt/loop/centos54/etc/yum.conf --installroot=/mnt/loop/centos62/ -y install kernel-xen</pre></li><li class="listitem"><div class="para">
|
||
Create a grub entry in /boot/grub/grub.conf.
|
||
</div><pre class="programlisting"># mkdir -p /mnt/loop/centos62/boot/grub
|
||
# touch /mnt/loop/centos62/boot/grub/grub.conf
|
||
# echo "" > /mnt/loop/centos62/boot/grub/grub.conf
|
||
</pre></li><li class="listitem"><div class="para">
|
||
Determine the name of the PV kernel that has been installed into the image.
|
||
</div><pre class="programlisting"># cd /mnt/loop/centos62
|
||
# ls lib/modules/
|
||
2.6.16.33-xenU 2.6.16-xenU 2.6.18-164.15.1.el5xen 2.6.18-164.6.1.el5.centos.plus 2.6.18-xenU-ec2-v1.0 2.6.21.7-2.fc8xen 2.6.31-302-ec2
|
||
# ls boot/initrd*
|
||
boot/initrd-2.6.18-164.6.1.el5.centos.plus.img boot/initrd-2.6.18-164.15.1.el5xen.img
|
||
# ls boot/vmlinuz*
|
||
boot/vmlinuz-2.6.18-164.15.1.el5xen boot/vmlinuz-2.6.18-164.6.1.el5.centos.plus boot/vmlinuz-2.6.18-xenU-ec2-v1.0 boot/vmlinuz-2.6.21-2952.fc8xen
|
||
</pre><div class="para">
|
||
Xen kernels/ramdisk always end with "xen". For the kernel version you choose, there has to be an entry for that version under lib/modules, there has to be an initrd and vmlinuz corresponding to that. Above, the only kernel that satisfies this condition is 2.6.18-164.15.1.el5xen.
|
||
</div></li><li class="listitem"><div class="para">
|
||
Based on your findings, create an entry in the grub.conf file. Below is an example entry.
|
||
</div><pre class="programlisting">default=0
|
||
timeout=5
|
||
hiddenmenu
|
||
title CentOS (2.6.18-164.15.1.el5xen)
|
||
root (hd0,0)
|
||
kernel /boot/vmlinuz-2.6.18-164.15.1.el5xen ro root=/dev/xvda
|
||
initrd /boot/initrd-2.6.18-164.15.1.el5xen.img
|
||
</pre></li><li class="listitem"><div class="para">
|
||
Edit etc/fstab, changing “sda1” to “xvda” and changing “sdb” to “xvdb”.
|
||
</div><pre class="programlisting"># cat etc/fstab
|
||
/dev/xvda / ext3 defaults 1 1
|
||
/dev/xvdb /mnt ext3 defaults 0 0
|
||
none /dev/pts devpts gid=5,mode=620 0 0
|
||
none /proc proc defaults 0 0
|
||
none /sys sysfs defaults 0 0
|
||
</pre></li><li class="listitem"><div class="para">
|
||
Enable login via the console. The default console device in a XenServer system is xvc0. Ensure that etc/inittab and etc/securetty have the following lines respectively:
|
||
</div><pre class="programlisting"># grep xvc0 etc/inittab
|
||
co:2345:respawn:/sbin/agetty xvc0 9600 vt100-nav
|
||
# grep xvc0 etc/securetty
|
||
xvc0
|
||
</pre></li><li class="listitem"><div class="para">
|
||
Ensure the ramdisk supports PV disk and PV network. Customize this for the kernel version you have determined above.
|
||
</div><pre class="programlisting"># chroot /mnt/loop/centos54
|
||
# cd /boot/
|
||
# mv initrd-2.6.18-164.15.1.el5xen.img initrd-2.6.18-164.15.1.el5xen.img.bak
|
||
# mkinitrd -f /boot/initrd-2.6.18-164.15.1.el5xen.img --with=xennet --preload=xenblk --omit-scsi-modules 2.6.18-164.15.1.el5xen
|
||
</pre></li><li class="listitem"><div class="para">
|
||
Change the password.
|
||
</div><pre class="programlisting"># passwd
|
||
Changing password for user root.
|
||
New UNIX password:
|
||
Retype new UNIX password:
|
||
passwd: all authentication tokens updated successfully.
|
||
</pre></li><li class="listitem"><div class="para">
|
||
Exit out of chroot.
|
||
</div><pre class="programlisting"># exit</pre></li><li class="listitem"><div class="para">
|
||
Check etc/ssh/sshd_config for lines allowing ssh login using a password.
|
||
</div><pre class="programlisting"># egrep "PermitRootLogin|PasswordAuthentication" /mnt/loop/centos54/etc/ssh/sshd_config
|
||
PermitRootLogin yes
|
||
PasswordAuthentication yes
|
||
</pre></li><li class="listitem"><div class="para">
|
||
If you need the template to be enabled to reset passwords from the CloudStack UI or API, install the password change script into the image at this point. See <a class="xref" href="add-password-management-to-templates.html">Section 12.13, “Adding Password Management to Your Templates”</a>.
|
||
</div></li><li class="listitem"><div class="para">
|
||
Unmount and delete loopback mount.
|
||
</div><pre class="programlisting"># umount /mnt/loop/centos54
|
||
# losetup -d /dev/loop0
|
||
</pre></li><li class="listitem"><div class="para">
|
||
Copy the image file to your XenServer host's file-based storage repository. In the example below, the Xenserver is "xenhost". This XenServer has an NFS repository whose uuid is a9c5b8c8-536b-a193-a6dc-51af3e5ff799.
|
||
</div><pre class="programlisting"># scp CentOS_6.2_x64 xenhost:/var/run/sr-mount/a9c5b8c8-536b-a193-a6dc-51af3e5ff799/</pre></li><li class="listitem"><div class="para">
|
||
Log in to the Xenserver and create a VDI the same size as the image.
|
||
</div><pre class="programlisting">[root@xenhost ~]# cd /var/run/sr-mount/a9c5b8c8-536b-a193-a6dc-51af3e5ff799
|
||
[root@xenhost a9c5b8c8-536b-a193-a6dc-51af3e5ff799]# ls -lh CentOS_6.2_x64
|
||
-rw-r--r-- 1 root root 10G Mar 16 16:49 CentOS_6.2_x64
|
||
[root@xenhost a9c5b8c8-536b-a193-a6dc-51af3e5ff799]# xe vdi-create virtual-size=10GiB sr-uuid=a9c5b8c8-536b-a193-a6dc-51af3e5ff799 type=user name-label="Centos 6.2 x86_64"
|
||
cad7317c-258b-4ef7-b207-cdf0283a7923
|
||
</pre></li><li class="listitem"><div class="para">
|
||
Import the image file into the VDI. This may take 10–20 minutes.
|
||
</div><pre class="programlisting">[root@xenhost a9c5b8c8-536b-a193-a6dc-51af3e5ff799]# xe vdi-import filename=CentOS_6.2_x64 uuid=cad7317c-258b-4ef7-b207-cdf0283a7923</pre></li><li class="listitem"><div class="para">
|
||
Locate a the VHD file. This is the file with the VDI’s UUID as its name. Compress it and upload it to your web server.
|
||
</div><pre class="programlisting">[root@xenhost a9c5b8c8-536b-a193-a6dc-51af3e5ff799]# bzip2 -c cad7317c-258b-4ef7-b207-cdf0283a7923.vhd > CentOS_6.2_x64.vhd.bz2
|
||
[root@xenhost a9c5b8c8-536b-a193-a6dc-51af3e5ff799]# scp CentOS_6.2_x64.vhd.bz2 webserver:/var/www/html/templates/
|
||
</pre></li></ol></div></div><ul class="docnav"><li class="previous"><a accesskey="p" href="create-windows-template.html"><strong>Prev</strong>12.10. Creating a Windows Template</a></li><li class="up"><a accesskey="u" href="#"><strong>Up</strong></a></li><li class="home"><a accesskey="h" href="index.html"><strong>Home</strong></a></li><li class="next"><a accesskey="n" href="convert-hyperv-vm-to-template.html"><strong>Next</strong>12.12. Converting a Hyper-V VM to a Template</a></li></ul></body></html>
|