Initial centos7 support

Initial support for a centos7 image.

This is separate to rhel7 because the major differences are things
like repo and image locations, which are always going to be different.
We should merge any real changes into the redhat-common layers.

Apart from the added support files in centos7/*, the other change is
mostly modifications to redhat-common's extract-image to handle
different partition layouts of the centos7 image.

Change-Id: I943abe5ff0a803f36eda266a79af0d9220edcae7
This commit is contained in:
Ian Wienand 2014-07-03 11:49:38 +10:00
parent 13eaa40e5e
commit 5abb4a4f12
11 changed files with 99 additions and 16 deletions

View File

@ -0,0 +1,3 @@
Use Centos 7 cloud images as the baseline for built disk images.
For further details see the redhat-common README.

View File

@ -0,0 +1,6 @@
cache-url
dib-run-parts
redhat-common
rpm-distro
source-repositories
yum

View File

@ -0,0 +1 @@
operating-system

View File

@ -0,0 +1 @@
export DISTRO_NAME=centos7

View File

@ -0,0 +1,6 @@
#!/bin/bash
set -eu
set -o pipefail
install-packages cloud-init

View File

@ -0,0 +1,22 @@
#!/bin/bash
set -eu
set -o pipefail
cat << EOF > /etc/yum.repos.d/centos7-latest.repo
[rhel7]
name=centos7
baseurl=http://buildlogs.centos.org/centos/7/os/x86_64-latest/
enabled=1
metadata_expire=7d
gpgcheck=0
EOF
cat << EOF > /etc/yum.repos.d/epel.repo
[epel]
name=Extra Packages for Enterprise Linux 7 - \$basearch
mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-7&arch=\$basearch
failovermethod=priority
enabled=1
gpgcheck=0
EOF

View File

@ -0,0 +1,31 @@
#!/bin/bash
set -eu
set -o pipefail
[ -n "$ARCH" ]
[ -n "$TARGET_ROOT" ]
if [ 'amd64' = "$ARCH" ] ; then
ARCH="x86_64"
fi
DIB_LOCAL_IMAGE=${DIB_LOCAL_IMAGE:-}
if [ -n "$DIB_LOCAL_IMAGE" ]; then
IMAGE_LOCATION=$DIB_LOCAL_IMAGE
# No need to copy a local image into the cache directory, so just specify
# the cached path as the original path.
CACHED_IMAGE=$IMAGE_LOCATION
BASE_IMAGE_FILE=$(basename $DIB_LOCAL_IMAGE)
BASE_IMAGE_TAR=$BASE_IMAGE_FILE.tgz
else
DIB_RELEASE=${DIB_RELEASE:-Broken-20140620-Nightly}
DIB_CLOUD_IMAGES=${DIB_CLOUD_IMAGES:-http://buildlogs.centos.org/centos/7/cloud}
BASE_IMAGE_FILE=${BASE_IMAGE_FILE:-CentOS-7-$DIB_RELEASE.qcow2}
BASE_IMAGE_TAR=$BASE_IMAGE_FILE.tgz
IMAGE_LOCATION=$DIB_CLOUD_IMAGES/$BASE_IMAGE_FILE
CACHED_IMAGE=$DIB_IMAGE_CACHE/$BASE_IMAGE_FILE
fi
$TMP_HOOKS_PATH/bin/extract-image $BASE_IMAGE_FILE $BASE_IMAGE_TAR $IMAGE_LOCATION $CACHED_IMAGE

View File

@ -0,0 +1 @@
lsb-release file /opt/stack/lsb-release/lsb_release https://bzr.linuxfoundation.org/loggerhead/lsb/devel/si/download/head:/lsb_release-20060624065236-gakl5b7e37gwk5mg-12/lsb_release

View File

@ -22,7 +22,7 @@ import sys
def os_family(distro):
family = None
if distro in ['centos', 'fedora', 'rhel', 'rhel7']:
if distro in ['centos', 'fedora', 'rhel', 'rhel7', 'centos7']:
family = 'redhat'
elif distro in ['debian', 'ubuntu']:
family = 'debian'

View File

@ -46,31 +46,43 @@ else
RAW_FILE=$(basename $BASE_IMAGE_FILE)
RAW_FILE=${RAW_FILE#.qcow2}.raw
qemu-img convert -f qcow2 -O raw $CACHED_IMAGE $WORKING/$RAW_FILE
# WARNING: The mattdm image has the root filesystem on the second
# partition (p2). If he changes the image the MAGIC_BIT
# might also need to change.
# UPDATE to above warning alluding to Fedora18:
# F19 images have the rootfs partition on p1
MAGIC_BIT=p1
# Centos7 images on p3 (p1 boot, p2 swap)
if [[ $DISTRO_NAME = "centos7" ]]; then
ROOT_PARTITON=p3
else
ROOT_PARTITON=p1
fi
# kpartx fails if no /dev/loop* exists, "losetup -f" prints first unused
# loop device and creates it if it doesn't exist
sudo losetup -f
# XXX: Parsing stdout is dangerous, would like a better way to discover
# the device used for the image.
# NOTE: On F17 (parted-3.0-10.fc17.x86_64), partprobe of
# /dev/loop0 does not create /dev/loop0p2, while kpartx at
# least creates /dev/mapper/loop0p2.
LOOPDEV=$(sudo kpartx -av $WORKING/$RAW_FILE | awk "/loop[0-9]+$MAGIC_BIT/ {print \$3}")
if ! timeout 5 sh -c "while ! [ -e /dev/mapper/$LOOPDEV ]; do sleep 1; done"; then
echo "Error: Could not find /dev/mapper/$LOOPDEV"
ROOT_LOOPDEV=$(sudo kpartx -av $WORKING/$RAW_FILE | \
awk "/loop[0-9]+$ROOT_PARTITON/ {print \$3}")
if ! timeout 5 sh -c "while ! [ -e /dev/mapper/$ROOT_LOOPDEV ]; do sleep 1; done"; then
echo "Error: Could not find /dev/mapper/$ROOT_LOOPDEV"
exit 1
fi
EACTION="sudo kpartx -d $WORKING/$RAW_FILE;$EACTION"
EACTION="sudo kpartx -d $WORKING/$RAW_FILE ; $EACTION"
trap "$EACTION" EXIT
mkdir $WORKING/mnt
sudo mount /dev/mapper/$LOOPDEV $WORKING/mnt
EACTION="sudo umount -f $WORKING/mnt;$EACTION"
sudo mount /dev/mapper/$ROOT_LOOPDEV $WORKING/mnt
EACTION="sudo umount -f $WORKING/mnt ; $EACTION"
trap "$EACTION" EXIT
# need to copy the contents of /boot into the image too, so
# mount it
if [[ $DISTRO_NAME = "centos7" ]]; then
BOOT_LOOPDEV=${ROOT_LOOPDEV/p3/p1}
sudo mount /dev/mapper/$BOOT_LOOPDEV $WORKING/mnt/boot
EACTION="sudo umount -f $WORKING/mnt/boot ; $EACTION"
trap "$EACTION" EXIT
fi
# Chroot in so that we get the correct uid/gid
sudo chroot $WORKING/mnt bin/tar -cz . > $WORKING/tmp.tar
mv $WORKING/tmp.tar $CACHED_TAR

View File

@ -113,7 +113,7 @@ function install_grub2 {
sed -i -e 's/\(^GRUB_CMDLINE_LINUX.*\)"$/\1 nofb nomodeset vga=normal"/' /etc/default/grub
GRUB_MKCONFIG=update-grub
;;
'Fedora')
'Fedora'|'CentOS')
echo 'GRUB_CMDLINE_LINUX="nofb nomodeset vga=normal"' >>/etc/default/grub
;;
'openSUSE project')