I finally manage to create an image of the Debian Installer automatically, with no key or password transiting on the Cloud or the network, and without using the ec2-api-tools
, which are non-Free. Thanks to Eucalyptus for implementing the attribute InstanceInitiatedShutdownBehavior
in euca2ools 2.1.2.
In brief, I start a micro-instance with an additional volume, and I pass it a script for cloud-init, which will download the Installer on the volume and shut down the instance. Then, I register the volume as a machine image.
Those machine images of the Installer are to be preseeded via instance metadata to install Debian on another volume. I am still struggling with the pre-configuration. More details will follow in the next article. In the meantime, here are the commands I a using.
On the local computer, start an instance on the Cloud. Until #696595 is fixed and cloud-init
is installed by default, I
use a Ubuntu image.
HELPER_AMI=ami-7609bb77 # Ubuntu 12.04 LTS Precise amd64 EBS (Asia North-East)
Start the instance with an extra volume of 1 GiB, which will persist after
termination (/dev/sdb=:1:false
). Pass the script
debigen-install-installer-cloud
(see below).
HELPER_INSTANCE=$( euca-run-instances \
--instance-initiated-shutdown-behavior terminate \
--instance-type t1.micro \
--block-device-mapping /dev/sdb=:1:false \
--user-data-file debigen-install-installer-cloud \
$HELPER_AMI |
tee /dev/stderr | grep INSTANCE | awk '{print $2}')
Wait that the boot finished.
while [ ! $(euca-describe-instances $HELPER_INSTANCE | grep INSTANCE | cut -f 6 | tee /dev/stderr) = "running" ]
do sleep 30
done
Get the volume's identifier
TARGET_VOLUME=$( euca-describe-volumes |
grep $HELPER_INSTANCE | grep '/dev/sdb' |
tee /dev/stderr | awk '{print $2}')
Wait that the scripts shuts down the instance.
while [ ! $(euca-describe-instances $HELPER_INSTANCE | grep INSTANCE | cut -f 6 | tee /dev/stderr) = "terminated" ]
do sleep 30
done
Snapshot the volume and register it as a machine image.
PV_KERNEL=aki-44992845 # Boot PV-Grub on hd0 (Asia North-East)
TARGET_SNAPSHOT=$( euca-create-snapshot $TARGET_VOLUME |
tee /dev/stderr | awk '{print $2}')
while euca-describe-snapshots $TARGET_SNAPSHOT | grep -q pending ; do sleep 30 ; done
euca-register \
--name test_di \
--description test_of_debian_installer \
--snapshot $TARGET_SNAPSHOT \
--kernel $PV_KERNEL \
--architecture x86_64
Here is the script called debigen-install-installer-cloud
, used above.
#!/bin/sh -ex
mke2fs -L debian-installer /dev/xvdb -F
mount LABEL=debian-installer /mnt/
cd /mnt
ARCH=amd64
DIST=squeeze
DI_VERSION=20110106+squeeze4+b2
MIRROR=jp
BASEURL=http://ftp.$MIRROR.debian.org/debian/dists/$DIST/main/installer-$ARCH/$DI_VERSION/images/netboot/xen
wget $BASEURL/initrd.gz $BASEURL/vmlinuz
mkdir -p boot/grub
cat > boot/grub/menu.lst <<__END__
default 0
timeout 3
title Debian Installer ($DI_VERSION $ARCH)
root (hd0)
kernel /vmlinuz root=LABEL=debian-installer ro console=hvc0 auto=true priority=critical url=http://169.254.169.254/latest/user-data DEBIAN_FRONTEND=text
initrd /initrd.gz
__END__
sleep 30
halt