diskimage-builder/elements/debian/root.d/08-debootstrap
Ben Nemec dde3d24213 Allow custom rootfs labels
Per [1], our current root label of cloudimg-root does not work with
XFS because XFS only allows 12 character labels.  This change
addresses that by allowing a custom rootfs label to be specified
in the call to disk-image-create.  There should be no backwards
compatibility concerns as the default label is unchanged.  Any
external elements dealing with the label would need to be updated
to support this new feature, but should continue to work as before
as long as a custom label is not specified.

[1]: https://bugzilla.redhat.com/show_bug.cgi?id=1139584

Change-Id: I596104d1a63b5dc6549e8460a1ae3da00165ef04
2014-09-26 17:44:08 -05:00

105 lines
4.6 KiB
Bash
Executable File

#!/bin/bash
#
# Copyright 2014 Hewlett-Packard Development Company, L.P.
#
# 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.
#
set -eu
set -o pipefail
if [ -f ${TARGET_ROOT}/.extra_settings ] ; then
. ${TARGET_ROOT}/.extra_settings
fi
DISTRO_NAME=${DISTRO_NAME:-debian}
DIB_RELEASE=${DIB_RELEASE:-unstable}
DIB_DEBIAN_ALT_INIT_PACKAGE=${DIB_DEBIAN_ALT_INIT_PACKAGE:-sysvinit}
DEBOOTSTRAP_TARBALL=$DIB_IMAGE_CACHE/debootstrap-${DISTRO_NAME}-${DIB_DEBIAN_ALT_INIT_PACKAGE}-${DIB_RELEASE}-${ARCH}.tar.gz
if [ -n "${DIB_DEBIAN_MIRROR:-}" ]; then
echo "Use of DIB_DEBIAN_MIRROR environment variable to configure mirror is deprecated."
echo "Please use DIB_DISTRIBUTION_MIRROR instead."
DIB_DISTRIBUTION_MIRROR=$DIB_DEBIAN_MIRROR
fi
DIB_DISTRIBUTION_MIRROR=${DIB_DISTRIBUTION_MIRROR:-http://http.debian.net/debian}
http_proxy=${http_proxy:-}
set -x
if [ -n "$DIB_OFFLINE" -o -n "${DIB_DEBIAN_USE_DEBOOTSTRAP_CACHE:-}" ] && [ -f $DEBOOTSTRAP_TARBALL ] ; then
echo $DEBOOTSTRAP_TARBALL found in cache. Using.
sudo tar -C $TARGET_ROOT --numeric-owner -xzf $DEBOOTSTRAP_TARBALL
else
echo Building new tarball for Debian $DIB_RELEASE ARCH=$ARCH
ADD_PACKAGES=sudo,adduser,locales,openssh-server,file,less,kbd,curl,rsync,bash-completion,linux-image-amd64
KEYRING_OPT=
if [ -n "${DIB_DEBIAN_KEYRING:-}" ] ; then
KEYRING_OPT="--keyring=${DIB_DEBIAN_KEYRING}"
fi
sudo sh -c "http_proxy=$http_proxy debootstrap --verbose \
--arch=${ARCH} \
--include=${ADD_PACKAGES} \
$KEYRING_OPT \
$DIB_RELEASE \
$TARGET_ROOT \
$DIB_DISTRIBUTION_MIRROR \
${DIB_DEBIAN_DEBOOTSTRAP_SCRIPT:-}"
echo "Customizing result for cloud use"
apt_get_bp_extra_opts=
if [ "$DIB_RELEASE" = "wheezy" ]; then
sudo sh -c "echo deb $DIB_DISTRIBUTION_MIRROR wheezy-backports main >> ${TARGET_ROOT}/etc/apt/sources.list"
sudo chroot ${TARGET_ROOT} apt-get update
cat << EOF | sudo tee -a ${TARGET_ROOT}/etc/network/interfaces
source /etc/network/interfaces.d/*
EOF
apt_get_bp_extra_opts="-t wheezy-backports"
fi
CLOUD_INIT_PACKAGES="cloud-init cloud-utils cloud-initramfs-growroot"
sudo sh -c "http_proxy=$http_proxy chroot ${TARGET_ROOT} apt-get install -y $apt_get_bp_extra_opts $CLOUD_INIT_PACKAGES"
if [ "$DIB_DEBIAN_ALT_INIT_PACKAGE" != "sysvinit" ]; then
# To avoid a conflict against an essential package, we need to remove sysvinit first
sudo chroot ${TARGET_ROOT} dpkg --purge --force remove-essential sysvinit
sudo sh -c "http_proxy=$http_proxy chroot ${TARGET_ROOT} apt-get install -y $apt_get_bp_extra_opts $DIB_DEBIAN_ALT_INIT_PACKAGE"
sudo sh -c "printf \"Package: sysvinit\nPin: origin ""\nPin-Priority: -1\n\" > \
${TARGET_ROOT}/etc/apt/preferences.d/sysvinit > ${TARGET_ROOT}/etc/apt/preferences.d/sysvinit"
fi
sudo sed -i "s/PermitRootLogin yes/PermitRootLogin without-password/" $TARGET_ROOT/etc/ssh/sshd_config
sudo chroot ${TARGET_ROOT} adduser --gecos Debian-cloud-init-user --disabled-password --quiet debian
sudo install -d -m 0755 -o root -g root ${TARGET_ROOT}/etc/sudoers.d
sudo sh -c "echo 'debian ALL=(ALL) NOPASSWD:ALL' > ${TARGET_ROOT}/etc/sudoers.d/debian-cloud-init"
sudo chmod 0440 ${TARGET_ROOT}/etc/sudoers.d/debian-cloud-init
sudo sh -c "echo \"proc /proc proc nodev,noexec,nosuid 0 0
LABEL=${DIB_ROOT_LABEL} / ext4 errors=remount-ro 0 1
\" > ${TARGET_ROOT}/etc/fstab"
sudo sh -c "echo 'blacklist pcspkr' > ${TARGET_ROOT}/etc/modprobe.d/blacklist.conf"
sudo sh -c "echo 'debian' > ${TARGET_ROOT}/etc/hostname"
# specify a hostname so that cloud-init does not default to (None)
sudo sh -c "echo 'hostname: debian' > ${TARGET_ROOT}/etc/cloud/cloud.cfg.d/01_hostname.cfg"
# cloud images expect eth0 to use dhcp.
sudo mkdir -p ${TARGET_ROOT}/etc/network/interfaces.d
cat << EOF | sudo tee ${TARGET_ROOT}/etc/network/interfaces.d/eth0
# The primary network interface
auto eth0
iface eth0 inet dhcp
EOF
echo Caching debootstrap result in $DEBOOTSTRAP_TARBALL
sudo tar -C $TARGET_ROOT -zcf $DEBOOTSTRAP_TARBALL --exclude='./tmp/*' .
fi
sudo rm -f ${TARGET_ROOT}/.extra_settings