openstack-debian-images-0.7/0000755000000000000000000000000012263263004012716 5ustar openstack-debian-images-0.7/debian/0000755000000000000000000000000012263263004014140 5ustar openstack-debian-images-0.7/debian/manpages0000644000000000000000000000003712263263004015656 0ustar build-openstack-debian-image.1 openstack-debian-images-0.7/debian/source/0000755000000000000000000000000012263263004015440 5ustar openstack-debian-images-0.7/debian/source/format0000644000000000000000000000001512263263004016647 0ustar 3.0 (native) openstack-debian-images-0.7/debian/install0000644000000000000000000000004712263263004015532 0ustar build-openstack-debian-image /usr/sbin openstack-debian-images-0.7/debian/examples0000644000000000000000000000001312263263004015673 0ustar examples/* openstack-debian-images-0.7/debian/gbp.conf0000644000000000000000000000013212263263004015553 0ustar [DEFAULT] debian-branch = debian/unstable [git-buildpackage] export-dir = ../build-area/ openstack-debian-images-0.7/debian/copyright0000644000000000000000000000164612263263004016102 0ustar Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ Upstream-Name: openstack-debian-images Source: git://anonscm.debian.org/openstack/openstack-debian-images.git Files: * Copyright: (c) 2013, Thomas Goirand License: Apache-2 Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at . http://www.apache.org/licenses/LICENSE-2.0 . Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. . On Debian-based systems the full text of the Apache version 2.0 license can be found at: /usr/share/common-licenses/Apache-2.0 openstack-debian-images-0.7/debian/rules0000755000000000000000000000101012263263004015210 0ustar #!/usr/bin/make -f -include /usr/share/openstack-pkg-tools/pkgos.make build-arch: build build-indep: build build: clean: dh_testdir dh_clean install: dh_testdir dh_testroot dh_prep binary-indep: install dh_testdir dh_testroot dh_installdocs dh_installexamples dh_installchangelogs dh_installman dh_install dh_compress dh_fixperms dh_installdeb dh_gencontrol dh_md5sums dh_builddeb binary-arch: install binary: binary-indep binary-arch .PHONY: build clean binary-indep binary-arch binary install openstack-debian-images-0.7/debian/changelog0000644000000000000000000000565412263263004016024 0ustar openstack-debian-images (0.7) unstable; urgency=high * Adds echo "mount_default_fields:" in /etc/cloud/cloud.cfg to allow the automatic mount of /dev/vdb ephemeral disk. * Standards-Version: is now 3.9.5. * Removes openstack-pkg-tools build-dependency, and made the include in debian/rules not mandatory. -- Thomas Goirand Wed, 08 Jan 2014 20:00:15 +0800 openstack-debian-images (0.6) unstable; urgency=medium * Fixes the console so that it works with both SPICE & horizon logs, thanks to Jordan Pittier for reporting and finding the solution (Closes: #726619). -- Thomas Goirand Sat, 07 Dec 2013 00:01:07 +0800 openstack-debian-images (0.5) unstable; urgency=medium [ Mehdi Abaakouk ] * Restore the default sshd configuration to allow authorized_keys and authorized_keys2 files [ Thomas Goirand ] * Added a new example folder showing how to create a NFS cinder VM using a static IP in Quantum. * Correctly writes in ${MOUNT_DIR}/etc/modules and not in the /etc/modules of the computer creating the image (Closes: #728943). * Corrects "Using the -ar option truncates 5% off the end of the resized filesystem." by using Mi instead of M when using parted (Closes: #728939). -- Thomas Goirand Fri, 25 Oct 2013 20:46:15 +0800 openstack-debian-images (0.4) unstable; urgency=low * Fixed a typo in package description (Closes: #718363). -- Thomas Goirand Mon, 29 Jul 2013 19:11:27 +0800 openstack-debian-images (0.3) unstable; urgency=low [ Thomas Goirand ] * Added a hook script. * Installs cloud-init, cloud-utils and cloud-initramfs-growroot from backports in Wheezy, since they are now available from there. * Added a --source-list-mirror option to fill the sources.list with custom mirror addresses. * Added an option to choose the initial image size. * Made Mehdi's feature to automatically shrink images to a minimal size as optional, since it doesn't entirely work and is very slow. * Added an option to set a default root password. [ Mehdi Abaakouk ] * Shrink image to a minimal size * Umount chroot and delete devmapper stuff on error/interruption -- Thomas Goirand Tue, 02 Jul 2013 17:56:22 +0800 openstack-debian-images (0.2) unstable; urgency=low * Also unmount the /proc of the image folder in /tmp in case we abort due to the .deb files missing if building a Wheezy image. * Review the script man page. * Adds the installation of the kbd package, and disabling of consol blanking. * Don't setup a password for root. * Fixes the sources.list which had whatever was used for the debootstrap. -- Thomas Goirand Tue, 11 Jun 2013 16:47:18 +0800 openstack-debian-images (0.1) unstable; urgency=low * Initial release. (Closes: #710273). -- Thomas Goirand Wed, 22 May 2013 16:39:47 +0800 openstack-debian-images-0.7/debian/control0000644000000000000000000000170412263263004015545 0ustar Source: openstack-debian-images Section: web Priority: extra Maintainer: PKG OpenStack Uploaders: Julien Danjou , Thomas Goirand , Mehdi Abaakouk Build-Depends: debhelper (>= 9) Standards-Version: 3.9.5 Vcs-Browser: http://anonscm.debian.org/gitweb/?p=openstack/openstack-debian-images.git;a=summary Vcs-Git: git://anonscm.debian.org/openstack/openstack-debian-images.git Package: openstack-debian-images Architecture: all Pre-Depends: dpkg (>= 1.15.6~) Depends: debootstrap, extlinux, initramfs-tools, kpartx, mbr, parted, qemu-utils, ${misc:Depends} Description: script to build a Debian image for OpenStack This package contains a script which is helpful for creating images to be used with the OpenStack IaaS cloud software suite. It uses only tools available within Debian. openstack-debian-images-0.7/debian/compat0000644000000000000000000000000212263263004015336 0ustar 9 openstack-debian-images-0.7/examples/0000755000000000000000000000000012263263004014534 5ustar openstack-debian-images-0.7/examples/nfs-server/0000755000000000000000000000000012263263004016626 5ustar openstack-debian-images-0.7/examples/nfs-server/customize0000755000000000000000000000272612263263004020605 0ustar #!/bin/sh set -e echo "################################" echo "### SETTING UP CUSTOMIZATION ###" echo "################################" set -x # Fill this with for example: 10.0.0.0/255.255.255.0 # Until you write something in, the script will fail. AUTHORIZED_NETWORK="" if [ -z "${AUTHORIZED_NETWORK}" ] ; then exit 1 fi mkdir ${BODI_CHROOT_PATH}/nfs echo "# Number of servers to start up RPCNFSDCOUNT=8 # Options for rpc.mountd RPCMOUNTDOPTS=\"-p 2048\"" >${BODI_CHROOT_PATH}/etc/default/nfs-kernel-server echo "/nfs ${AUTHORIZED_NETWORK}(rw,no_root_squash,subtree_check)" >>${BODI_CHROOT_PATH}/etc/exports echo "# If you do not set values for the NEED_ options, they will be attempted # autodetected; this should be sufficient for most people. Valid alternatives # for the NEED_ options are "yes" and "no". # Do you want to start the statd daemon? It is not needed for NFSv4. NEED_STATD=yes # Options for rpc.statd. # Should rpc.statd listen on a specific port? This is especially useful # when you have a port-based firewall. To use a fixed port, set this # this variable to a statd argument like: \"--port 4000 --outgoing-port 4001\". # For more information, see rpc.statd(8) or http://wiki.debian.org/SecuringNFS STATDOPTS=\"-p 2046 -o 2047\" # Do you want to start the idmapd daemon? It is only needed for NFSv4. NEED_IDMAPD= # Do you want to start the gssd daemon? It is required for Kerberos mounts. NEED_GSSD=yes " >${BODI_CHROOT_PATH}/etc/default/nfs-common openstack-debian-images-0.7/examples/nfs-server/build0000755000000000000000000000517012263263004017656 0ustar #!/bin/sh set -e # Image size in GB IMAGE_SIZE=150 # Fill this with for example: 10.0.0.0/24 YOUR_NETWORK_IP="" # Fill this with for example: 10.0.0.151 NFS_SERVER_IP="" # Fill in your key name in Nova SSH_KEY_NAME="" # Fill in the hostname you wish to use for this NFS server MY_HOSTNAME="" # Name of your local lan as returned by "quantum net-list" LOCAL_LAN_NAME="" if [ -z "${YOUR_NETWORK_IP}" ] || [ -z "${NFS_SERVER_IP}" ] || [ -z "${SSH_KEY_NAME}" ] || [ -z "${MY_HOSTNAME}" ] || [ -z "${LOCAL_LAN_NAME}" ] ; then echo "parameters not configured in the script $0" exit 1 fi NEUTRON=`which neutron` if [ -z "${NEUTRON}" ] ; then NEUTRON=`which quantum` fi if [ -z "${NEUTRON}" ] ; then echo "Please install neutron (or quantum) client" exit 1 fi build-openstack-debian-image -r wheezy \ -e nfs-kernel-server,nfs-common \ -hs ./customize if ! [ -e version ] ; then echo 0 > version fi VERSION=`cat version` VERSION=$(( ${VERSION} + 1 )) echo ${VERSION} >version # rm debian-wheezy-7.0.0-3-amd64.raw mv debian-wheezy-7.0.0-3-amd64.qcow2 wheezy-nfs-${VERSION}.qcow2 echo "Uploading image to Glance..." glance image-create --name="Wheezy NFS ${VERSION}" --disk-format=qcow2 --container-format=bare --file wheezy-nfs-${VERSION}.qcow2 echo "Creating cinder disk out of the Glance image..." IMAGE_ID=`glance image-list | grep "Wheezy NFS ${VERSION}" | awk '{print $2}'` cinder create --image-id ${IMAGE_ID} --display-name "Wheezy NFS ${VERSION}" ${IMAGE_SIZE} echo "Deleting Glance image..." glance image-delete ${IMAGE_ID} echo -n "Waiting for Cinder image to become bootable." CINDER_IMAGE_BOOTABLE=`cinder list | grep "Wheezy NFS 4" | awk '{print $14}'` while [ "${CINDER_IMAGE_BOOTABLE}" != "true" ] ; do sleep 2 echo -n "." done echo " done!" # Creates a static (fixed) IP ${NFS_SERVER_IP} in the quantum setup echo "Creating quantum static IP..." SUBNET_ID=`quantum subnet-list | grep ${YOUR_NETWORK_IP} | awk '{print $2}'` NET_ID=`quantum net-list | grep ${LOCAL_LAN_NAME} | awk '{print $2}'` quantum port-create --fixed-ip subnet_id=${SUBNET_ID},ip_address=${NFS_SERVER_IP} ${NET_ID} # Create a new VM using the "boot from volume" option echo "Booting instance..." IP_ONE=`quantum port-list | grep ${NFS_SERVER_IP} | awk '{print $2}'` BLOCK_DEV_ID=`nova volume-list | grep "Wheezy NFS ${VERSION}" | awk '{print $2}'` nova boot --block_device_mapping vda=${BLOCK_DEV_ID}::5:False --flavor 3 --nic port-id=${IP_ONE} --key-name ${SSH_KEY_NAME} ${MY_HOSTNAME} echo "All done. You can now wait until your NFS server becomes" echo "available. Note that it may take a lot of time, since its" echo "HDD image in Cinder will be resized at the first boot." openstack-debian-images-0.7/build-openstack-debian-image.10000644000000000000000000001202012263263004020357 0ustar .TH build\-openstack\-debian\-image 1 .SH NAME build\-openstack\-debian\-image \- build a Debian image to be used with OpenStack .SH SYNOPSIS .B build\-openstack\-debian\-image .B \-\-release|\-r [ OPTIONS ] .SH DESCRIPTION .LP The .I build\-openstack\-debian\-image shell script will build a Debian image which can be used in an OpenStack IaaS cloud. The resulting (Qcow2 and raw images) contains initramfs\-growroot so that the root partition will be resized (during the initramfs phase, before mouting anything) to match the flavor selected when using "nova boot". Later on during the boot process, cloud\-init will resize the root partition on the fly (resize is performed when the partition is already mounted read\-write, since recent kernel allow that for ext3). Cloud\-init is setup to use an Ec2 metadata server, which is what OpenStack is compatible with. A "debian" user will be used to receive the ssh key from the user data blob. This user is setup without a password (eg: adduser \-\-disabled\-password). Once logged as this "debian" user in your new virtual machine, you can "sudo" to root from that user, without needing a password. The root password is "password" by default, and ssh into the root user without using an ssh keypair is disabled by default (PermitRootLogin without-password is set in /etc/ssh/sshd_config). .SH "PARAMETERS" .LP .B \-\-release|\-r .I wheezy|jessie .IP Sets the .I release name to be installed. Currently only 2 values a possible: .I wheezy and .I jessie. .SH "OPTIONS" .LP .B \-\-extra\-packages|\-e .I PACKAGE,PACKAGE,... .IP Select the .I PACKAGE you want to add to the image .I default is: bash-completion,joe,most,screen,less,vim,bzip2 Note that this list of extra packages isn't used if you use the .B --minimal option. .LP .B \-\-debootstrap\-url|\-u .I .IP Select the .I URL of the Debian mirror to use to perform the debootstrap. For example: .I http://ftp.fr.debian.org/debian .LP .B \-\-sources.list\-mirror|\-s .I .IP URL to use when building the sources.list inside the chroot. If this option is ommited, then the global http.debian.net redirector is used. For example, you can use: .I http://ftp.fr.debian.org/debian .LP .B \-\-minimal .IP Without this option, the following packages will also be installed: bash\-completion (and /etc/bash.bashrc will be setup to use bash\-completion), joe (the text editor), most, GNU screen, less and vim. If you believe that more things should be added in the non\-minimal image, suggestions are welcome. .LP .B \-\-image-size|\-is .I .IP Select the image size (default to 1 GBytes if this option is ommited). Only useful if you need to use a custom script hook (see below). .LP .B \-\-automatic-resize|\-ar .IP Reduce the image to the minimum HDD size possible. The partition of the image will be first shrinked with resize2fs \-M, then the space it takes will be used to do a 2nd resize2fs adding a bit of extra space for the operating system to write runtime data (see below). Since this option takes a lot of time, it is disabled by default. .LP .B \-\-automatic\-resize\-space|\-ars .I .IP Size of the suplementary space added to the partition after it is resized to the minimum. If this option is ommited, then 50G is used. If .B \-\-automatic-resize isn't used, then it is useless to set this option, which will be ignored. .LP .B \-\-password|\-p .I .IP Defines a default root password for your image. This option is dangerous, first because it will show the root password to the user of the computer building the image if using "ps", then also because it is best to not set a default root password at all if possible. However, this option is still there, because sometimes, you need to be able to debug your image, and login through the web console of horizon. In a production environment, do not use this option. .LP .B \-\-hook\-script|\-hs .I .IP If you wish to further customize the generated cloud image, you can use a hook script. When called, build-openstack-debian-image will fill up some BODI_* environment variable for the hook script to use as per below: .B BODI_CHROOT_PATH path where the image is mounted .B BODI_RELEASE name of the Debian release that is being bootstraped .SH EXAMPLE .IP .IP Here is an example with the short parameter names: .LP .I build\-openstack\-debian\-image \-u http://ftp.fr.debian.org/debian \-s \ http://ftp.fr.debian.org/debian \-is 5 \-e libapache2\-mod\-php5 \-hs \ ~/customize\-my\-image \-ar \-ars 100 .IP And the same but with long names for options: .LP .I build-openstack-debian-image \-\-debootstrap\-url http://ftp.fr.debian.org/debian \ \-\-sources.list\-mirror http://ftp.fr.debian.org/debian \-\-image-size 5 \ \-\-extra\-packages libapache2-mod-php5 \-\-hook\-script ~/customize\-my\-image \ \-\-automatic-resize \-\-automatic\-resize\-space 100 .SH AUTHORS build\-openstack\-debian\-image has been written by Thomas Goirand , with contributions from Mehdi Abaakouk . openstack-debian-images-0.7/build-openstack-debian-image0000755000000000000000000002665212263263004020243 0ustar #!/bin/sh set -e # Parse input parameters usage() { echo "Usage: $0 --release|-r [options] Options are: --minimal|-m --debootstrap-url|-u (default: http://http.debian.net/debian) --sources.list-mirror|-s (default: http://http.debian.net/debian) --extra-packages|-e ,,... --hook-script|-hs --image-size|-is (default: 1G) --automatic-resize|-ar --automatic-resize-space|-ars (default: 50M) --password|-p (dangerous option: avoid it if possible) For more info: man $0" exit 1 } EXTRA=yes for i in $@ ; do case "${1}" in "--extra-packages"|"-e") if [ -z "${2}" ] ; then echo "No parameter defining the extra packages" usage fi EXTRA_PACKAGES=${2} shift shift ;; "--debootstrap-url"|"-u") if [ -z "${2}" ] ; then echo "No parameter defining the debootstrap URL" usage fi DEB_MIRROR=${2} shift shift ;; "--minimal"|"-m") EXTRA=no shift ;; "--automatic-resize"|"-ar") AUTOMATIC_RESIZE=yes shift ;; "--automatic-resize-space"|"-ars") if [ -z "${2}" ] ; then echo "No parameter defining the suplementary space" usage fi AUTOMATIC_RESIZE_SPACE=${2} shift shift ;; "--image-size"|"-is") if [ -z "${2}" ] ; then echo "No parameter defining the image size" usage fi IMAGE_SIZE=${2} shift shift ;; "--hook-script"|"-hs") if [ -z "${2}" ] ; then echo "No parameter defining the hook script" usage fi if ! [ -x "${2}" ] ; then echo "Hook script not executable" fi HOOK_SCRIPT=${2} shift shift ;; "--sources.list-mirror"|"-s") if [ -z "${2}" ] ; then echo "No parameter defining the hook script" usage fi SOURCE_LIST_MIRROR=${2} shift shift ;; "--release"|"-r") if [ "${2}" = "wheezy" ] || [ "${2}" = "jessie" ] ; then RELEASE=${2} shift shift else echo "Release not recognized." usage fi ;; "--password"|"-p") if [ -z "${2}" ] ; then echo "No parameter defining the root password" fi ROOT_PASSWORD=${2} shift shift ;; *) ;; esac done if [ -z "${RELEASE}" ] ; then echo "Release not recognized: please specify the -r parameter." usage fi if [ -z "${DEB_MIRROR}" ] ; then DEB_MIRROR=http://http.debian.net/debian fi if [ -z "${EXTRA_PACKAGES}" ] ; then EXTRA_PACKAGES=bash-completion,joe,most,screen,less,vim,bzip2 fi if [ -z "${SOURCE_LIST_MIRROR}" ] ; then SOURCE_LIST_MIRROR=http://http.debian.net/debian fi if [ -z "${IMAGE_SIZE}" ] ; then IMAGE_SIZE=1 fi if [ -z "${AUTOMATIC_RESIZE_SPACE}" ] ; then AUTOMATIC_RESIZE_SPACE=50 fi NEEDED_PACKAGES=sudo,adduser,locales,extlinux,openssh-server,linux-image-amd64,euca2ools,file,kbd if [ "${RELEASE}" = "jessie" ] ; then NEEDED_PACKAGES=${NEEDED_PACKAGES},cloud-init,cloud-utils,cloud-initramfs-growroot else # These are needed by cloud-init and friends, and since we don't want backports of them, # but just normal packages from Wheezy, we resolve dependencies by hand, prior to using # apt-get -t wheezy-backports install cloud-init cloud-utils cloud-initramfs-growroot NEEDED_PACKAGES=${NEEDED_PACKAGES},python,python-paramiko,python-argparse,python-cheetah,python-configobj,python-oauth,python-software-properties,python-yaml,python-boto,python-prettytable,initramfs-tools,python-requests fi if [ ${EXTRA} = "no" ] ; then PKG_LIST=${NEEDED_PACKAGES} else PKG_LIST=${NEEDED_PACKAGES},${EXTRA_PACKAGES} fi if ! [ `whoami` = "root" ] ; then echo "You have to be root to run this script" exit 1 fi FILE_NAME=debian-${RELEASE}-7.0.0-3-amd64 AMI_NAME=${FILE_NAME}.raw QCOW2_NAME=${FILE_NAME}.qcow2 rm -f ${AMI_NAME} set -x ###################################### ### Prepare the HDD (format, ext.) ### ###################################### PARTED=/sbin/parted rm -f $AMI_NAME qemu-img create ${AMI_NAME} ${IMAGE_SIZE}G #dd if=/dev/null bs=1M seek=1024 of=${AMI_NAME} ${PARTED} -s ${AMI_NAME} mktable msdos ${PARTED} -s -a optimal ${AMI_NAME} mkpart primary ext3 1Mi 100% ${PARTED} -s ${AMI_NAME} set 1 boot on install-mbr ${AMI_NAME} RESULT_KPARTX=`kpartx -av ${AMI_NAME} 2>&1` if echo "${RESULT_KPARTX}" | grep "^add map" ; then LOOP_DEVICE=`echo ${RESULT_KPARTX} | cut -d" " -f3` echo "kpartx mounted using: ${LOOP_DEVICE}" else echo "It seems kpartx didn't mount the image correctly: exiting." exit 1 fi cleanup(){ [ ! -d "${MOUNT_DIR}" ] && return echo echo "error, umounting $MOUNT_DIR" chroot ${MOUNT_DIR} umount /proc || true chroot ${MOUNT_DIR} umount /sys || true umount ${MOUNT_DIR} rmdir ${MOUNT_DIR} kpartx -d ${AMI_NAME} } trap "cleanup" EXIT TERM INT # We first use ext2, THEN convert to ext3, because that's so much faster this way. mkfs.ext2 /dev/mapper/${LOOP_DEVICE} # No fsck because of X days without checks tune2fs -i 0 /dev/mapper/${LOOP_DEVICE} MOUNT_DIR=`mktemp -d -t build-debimg.XXXXXX` mount -o loop /dev/mapper/${LOOP_DEVICE} ${MOUNT_DIR} debootstrap --verbose \ --include=${PKG_LIST} \ ${RELEASE} ${MOUNT_DIR} ${DEB_MIRROR} ############################ ### Customize the distro ### ############################ ### Customize: access to the VM ### # # # # # # # # # # # # # # # # # # # Setup default root password to what has been set on the command line if [ -n "${ROOT_PASSWORD}" ] ; then chroot ${MOUNT_DIR} sh -c "echo root:${ROOT_PASSWORD} | chpasswd" fi # Otherwise, we have a huge backdoor, since the root password # is always the same. sed -i "s/PermitRootLogin yes/PermitRootLogin without-password/" ${MOUNT_DIR}/etc/ssh/sshd_config # Add a default "debian" user which is used by cloud-init by default chroot ${MOUNT_DIR} adduser --gecos Debian-cloud-init-user --disabled-password --quiet debian # Adds the "debian" user to sudoers, since that is the way # cloud-init grant access mkdir -p ${MOUNT_DIR}/etc/sudoers.d echo "debian ALL = NOPASSWD: ALL" >${MOUNT_DIR}/etc/sudoers.d/debian-cloud-init chmod 0440 ${MOUNT_DIR}/etc/sudoers.d/debian-cloud-init ### Customize: misc stuff ### # # # # # # # # # # # # # # # # Setup fstab echo "# /etc/fstab: static file system information. proc /proc proc nodev,noexec,nosuid 0 0 /dev/vda1 / ext3 errors=remount-ro 0 1 " > ${MOUNT_DIR}/etc/fstab chroot ${MOUNT_DIR} mount /proc || true echo "# disable pc speaker blacklist pcspkr" >${MOUNT_DIR}/etc/modprobe.d/blacklist.conf echo "# Required for cinder hotplug acpiphp pci_hotplug " >>${MOUNT_DIR}/etc/modules # Enable bash-completion by default if [ ${EXTRA} = "yes" ] ; then echo "# enable bash completion in interactive shells if ! shopt -oq posix; then if [ -f /usr/share/bash-completion/bash_completion ]; then . /usr/share/bash-completion/bash_completion elif [ -f /etc/bash_completion ]; then . /etc/bash_completion fi fi" >>${MOUNT_DIR}/etc/bash.bashrc # No clear for the tty1 console sed -i "s#1:2345:respawn:/sbin/getty 38400 tty1#1:2345:respawn:/sbin/getty --noclear 38400 tty1#" ${MOUNT_DIR}/etc/inittab chroot ${MOUNT_DIR} apt-get install -y locales-all fi # Turn off console blanking which is *very* annoying # and increase KEYBOARD_DELAY because it can be annoying # over network. sed -i s/^BLANK_TIME=.*/BLANK_TIME=0/ ${MOUNT_DIR}/etc/kbd/config sed -i s/^POWERDOWN_TIME=.*/POWERDOWN_TIME=0/ ${MOUNT_DIR}/etc/kbd/config sed -i 's/^[ \t#]KEYBOARD_DELAY=.*/KEYBOARD_DELAY=1000/' ${MOUNT_DIR}/etc/kbd/config rm -f ${MOUNT_DIR}/etc/ssh/ssh_host_* rm -f ${MOUNT_DIR}/etc/udev/rules.d/70-persistent-net.rules rm -f ${MOUNT_DIR}/lib/udev/write_net_rules # Setup networking (eg: DHCP by default) echo "# This file describes the network interfaces available on your system # and how to activate them. For more information, see interfaces(5). # The loopback network interface auto lo iface lo inet loopback # The normal eth0 auto eth0 iface eth0 inet dhcp # Maybe the VM has 2 NICs? allow-hotplug eth1 iface eth1 inet dhcp # Maybe the VM has 3 NICs? allow-hotplug eth2 iface eth2 inet dhcp " > ${MOUNT_DIR}/etc/network/interfaces # Setup the default hostname (will be set by cloud-init # at boot time anyway) echo "debian.example.com" >${MOUNT_DIR}/etc/hostname # This should be a correct default everywhere echo "deb ${SOURCE_LIST_MIRROR} ${RELEASE} main deb-src ${SOURCE_LIST_MIRROR} ${RELEASE} main" >${MOUNT_DIR}/etc/apt/sources.list if [ "${RELEASE}" = "wheezy" ] ; then echo "deb ${SOURCE_LIST_MIRROR} wheezy-updates main deb-src ${SOURCE_LIST_MIRROR} wheezy-updates main deb http://security.debian.org/ wheezy/updates main deb-src http://security.debian.org/ wheezy/updates main deb ${SOURCE_LIST_MIRROR} wheezy-backports main deb-src ${SOURCE_LIST_MIRROR} wheezy-backports main " >>${MOUNT_DIR}/etc/apt/sources.list fi chroot ${MOUNT_DIR} apt-get update # Setup cloud-init, cloud-utils and cloud-initramfs-growroot # These are only available from backports in Wheezy if [ "${RELEASE}" = "wheezy" ] ; then chroot ${MOUNT_DIR} apt-get -t wheezy-backports install cloud-init cloud-utils cloud-initramfs-growroot -y fi # For OpenStack, we would like to use Ec2 and no other API echo "# to update this file, run dpkg-reconfigure cloud-init datasource_list: [ Ec2 ]" >${MOUNT_DIR}/etc/cloud/cloud.cfg.d/90_dpkg.cfg # Needed to have automatic mounts of /dev/vdb echo "mount_default_fields: [~, ~, 'auto', 'defaults,nofail', '0', '2']" >>${MOUNT_DIR}/etc/cloud/cloud.cfg # Setting-up initramfs chroot ${MOUNT_DIR} update-initramfs -u rm ${MOUNT_DIR}/var/cache/apt/archives/*.deb ########################### ### Setting-up extlinux ### ########################### KERNEL=`chroot ${MOUNT_DIR} find boot -name 'vmlinuz-*'` RAMDISK=`chroot ${MOUNT_DIR} find boot -name 'initrd.img-*'` UUID=`blkid -o value -s UUID /dev/mapper/${LOOP_DEVICE}` echo "default linux timeout 1 label linux kernel ${KERNEL} append initrd=${RAMDISK} root=/dev/vda1 ro quiet console=ttyS0" > ${MOUNT_DIR}/boot/extlinux/extlinux.conf #append initrd=${RAMDISK} root=/dev/vda1 console=tty0 console=ttyS0,115200 ro quiet" > ${MOUNT_DIR}/boot/extlinux/extlinux.conf cp ${MOUNT_DIR}/boot/extlinux/extlinux.conf ${MOUNT_DIR}/extlinux.conf extlinux --install ${MOUNT_DIR} #chroot ${MOUNT_DIR} extlinux-update ################### ### HOOK SCRIPT ### ################### if [ -x ${HOOK_SCRIPT} ] ; then export BODI_CHROOT_PATH=${MOUNT_DIR} export BODI_RELEASE=${RELEASE} ${HOOK_SCRIPT} fi ########################## ### Unmount everything ### ########################## cleanup(){ # refine cleanup everything was ok echo "Finished." } chroot ${MOUNT_DIR} umount /proc || true umount ${MOUNT_DIR} # Run FSCK so that resize can work tune2fs -j /dev/mapper/${LOOP_DEVICE} fsck.ext3 -f /dev/mapper/${LOOP_DEVICE} || true if [ "${AUTOMATIC_RESIZE}" = "yes" ] ; then resize2fs -M /dev/mapper/${LOOP_DEVICE} FS_BLOCKS=`tune2fs -l /dev/mapper/${LOOP_DEVICE} | awk '/Block count/{print $3}'` WANTED_SIZE=`expr $FS_BLOCKS '*' 4 '/' 1024 + ${AUTOMATIC_RESIZE_SPACE}` # Add ${AUTOMATIC_RESIZE_SPACE}M resize2fs /dev/mapper/${LOOP_DEVICE} ${WANTED_SIZE}M FINAL_FS_BLOCKS=`tune2fs -l /dev/mapper/${LOOP_DEVICE} | awk '/Block count/{print $3}'` FINAL_IMG_SIZE=`expr '(' $FINAL_FS_BLOCKS + 258 ')' '*' 4 '/' 1024` # some blocks for mbr and multiple block size (4k) fi kpartx -d ${AMI_NAME} rmdir ${MOUNT_DIR} if [ "${AUTOMATIC_RESIZE}" = "yes" ] ; then # Rebuild a smaller partition table parted -s ${AMI_NAME} rm 1 parted -s ${AMI_NAME} mkpart primary ext3 1Mi ${FINAL_IMG_SIZE}Mi parted -s ${AMI_NAME} set 1 boot on # Add 2M for the 1M at the beginning of the partition and some additionnal space truncate -s `expr 3 + ${FINAL_IMG_SIZE}`M ${AMI_NAME} install-mbr ${AMI_NAME} fi qemu-img convert -c -f raw ${AMI_NAME} -O qcow2 ${QCOW2_NAME}