$ cat << 'TEMPLATE' | sudo tee /etc/oz/f16-jeos.tdl > /dev/null
<template>
<name>fedora16_x86_64</name>
<description>My Fedora 16 x86_64 template</description>
<os>
<name>Fedora</name>
<version>16</version>
<arch>x86_64</arch>
<install type='url'>
<url>http://download.fedoraproject.org/pub/fedora/linux/releases/16/Fedora/x86_64/os/</url>
</install>
<rootpw>password</rootpw>
</os>
<packages>
<package name="httpd"><file>httpd</file></package>
<package name="vim"><file>vim</file></package>
</packages>
<commands>
<command name='setup-rc-local'>
sed -i 's/rhgb quiet/console=ttyS0/' /boot/grub/grub.conf
cat >> /etc/rc.local << EOF
if [ ! -d /root/.ssh ]; then
mkdir -p /root/.ssh
chmod 700 /root/.ssh
fi
# Fetch public key using HTTP
ATTEMPTS=10
while [ ! -f /root/.ssh/authorized_keys ]; do
curl -f http://169.254.169.254/latest/meta-data/public-keys/0/openssh-key > /tmp/aws-key 2>/dev/null
if [ \$? -eq 0 ]; then
cat /tmp/aws-key >> /root/.ssh/authorized_keys
chmod 0600 /root/.ssh/authorized_keys
restorecon /root/.ssh/authorized_keys
rm -f /tmp/aws-key
echo "Successfully retrieved AWS public key from instance metadata"
else
FAILED=\$((\$FAILED + 1))
if [ \$FAILED -ge \$ATTEMPTS ]; then
echo "Failed to retrieve AWS public key after \$FAILED attempts, quitting"
break
fi
echo "Could not retrieve AWS public key (attempt #\$FAILED/\$ATTEMPTS), retrying in 5 seconds..."
sleep 5
fi
done
EOF
</command>
</commands>
</template>
TEMPLATE
$ glance add name=f16-jeos is_public=true container_format=bare disk_format=raw < /var/lib/libvirt/images/fedora16_x86_64.dsk
ディスクフォーマットをqcow2にして更に圧縮する場合は以下のコマンドで行います。約30分の1のサイズになりました。
$ sudo qemu-img convert -O qcow2 -c /var/lib/libvirt/images/fedora16_x86_64.dsk /var/lib/libvirt/images/fedora16_x86_64.qcow2
$ ls -lh /var/lib/libvirt/images/fedora16_x86_64.dsk
-rw-r--r-- 1 root root 10G 5月 15 00:40 2012 /var/lib/libvirt/images/fedora16_x86_64.dsk
$ ls -lh /var/lib/libvirt/images/fedora16_x86_64.qcow2
-rw-r--r-- 1 root root 310M 5月 15 01:06 2012 /var/lib/libvirt/images/fedora16_x86_64.qcow2
圧縮した場合はcontainer_formatをovf、disk_formatはqcow2を設定して行います。
$ glance add name=f16-jeos is_public=true container_format=ovf disk_format=qcow2 < /var/lib/libvirt/images/fedora16_x86_64.qcow2