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
This commit is contained in:
Ben Nemec 2014-09-16 13:11:07 -05:00
parent 89356c6d34
commit dde3d24213
5 changed files with 26 additions and 11 deletions

View File

@ -62,6 +62,7 @@ function show_options () {
echo " --offline -- do not update cached resources" echo " --offline -- do not update cached resources"
echo " --qemu-img-options -- option flags to be passed directly to qemu-img." echo " --qemu-img-options -- option flags to be passed directly to qemu-img."
echo " Options need to be comma separated, and follow the key=value pattern." echo " Options need to be comma separated, and follow the key=value pattern."
echo " --root-label label -- label for the root filesystem. Defaults to 'cloudimg-rootfs'."
if [ "$IS_RAMDISK" == "0" ]; then if [ "$IS_RAMDISK" == "0" ]; then
echo " -n skip the default inclusion of the 'base' element" echo " -n skip the default inclusion of the 'base' element"
echo " -p package[,package,package] -- list of packages to install in the image" echo " -p package[,package,package] -- list of packages to install in the image"
@ -85,7 +86,8 @@ function show_options () {
INSTALL_PACKAGES="" INSTALL_PACKAGES=""
COMPRESS_IMAGE="true" COMPRESS_IMAGE="true"
TEMP=`getopt -o a:ho:t:xucnp: -l no-tmpfs,offline,help,min-tmpfs:,image-size:,image-cache:,max-online-resize:,qemu-img-options: -n $SCRIPTNAME -- "$@"` DIB_ROOT_LABEL=""
TEMP=`getopt -o a:ho:t:xucnp: -l no-tmpfs,offline,help,min-tmpfs:,image-size:,image-cache:,max-online-resize:,qemu-img-options:,root-label: -n $SCRIPTNAME -- "$@"`
if [ $? -ne 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi if [ $? -ne 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi
# Note the quotes around `$TEMP': they are essential! # Note the quotes around `$TEMP': they are essential!
@ -109,6 +111,7 @@ while true ; do
--no-tmpfs) shift; export DIB_NO_TMPFS=1;; --no-tmpfs) shift; export DIB_NO_TMPFS=1;;
--offline) shift; export DIB_OFFLINE=1;; --offline) shift; export DIB_OFFLINE=1;;
--qemu-img-options) QEMU_IMG_OPTIONS=$2; shift 2;; --qemu-img-options) QEMU_IMG_OPTIONS=$2; shift 2;;
--root-label) export DIB_ROOT_LABEL=$2; shift 2;;
--) shift ; break ;; --) shift ; break ;;
*) echo "Internal error!" ; exit 1 ;; *) echo "Internal error!" ; exit 1 ;;
esac esac
@ -135,9 +138,21 @@ fi
arg_to_elements "$@" arg_to_elements "$@"
export IMAGE_NAME=${IMAGE_NAME%%\.${IMAGE_TYPE}} export IMAGE_NAME=${IMAGE_NAME%%\.${IMAGE_TYPE}}
# FS_TYPE isn't available until after we source img-defaults
if [ -z "$DIB_ROOT_LABEL" ]; then
# NOTE(bnemec): XFS has a limit of 12 characters for filesystem labels
# Not changing the default for other filesystems to maintain backwards compatibility
if [ "$FS_TYPE" = "xfs" ]; then
DIB_ROOT_LABEL="img-rootfs"
else
DIB_ROOT_LABEL="cloudimg-rootfs"
fi
fi
mk_build_dir mk_build_dir
create_base create_base
# This variable needs to be propagated into the chroot
echo "export DIB_ROOT_LABEL=\"${DIB_ROOT_LABEL}\"" > $TMP_HOOKS_PATH/environment.d/10-dib-root-label.bash
run_d extra-data run_d extra-data
# Run pre-install scripts. These do things that prepare the chroot for package installs # Run pre-install scripts. These do things that prepare the chroot for package installs
run_d_in_target pre-install run_d_in_target pre-install
@ -184,7 +199,7 @@ LOOPDEV=$(sudo losetup --show -f $TMP_IMAGE_PATH)
export EXTRA_UNMOUNT="detach_loopback $LOOPDEV" export EXTRA_UNMOUNT="detach_loopback $LOOPDEV"
export IMAGE_BLOCK_DEVICE=$LOOPDEV export IMAGE_BLOCK_DEVICE=$LOOPDEV
eval_run_d block-device "IMAGE_BLOCK_DEVICE=" eval_run_d block-device "IMAGE_BLOCK_DEVICE="
sudo mkfs $MKFS_OPTS -t $FS_TYPE -L cloudimg-rootfs ${IMAGE_BLOCK_DEVICE} sudo mkfs $MKFS_OPTS -t $FS_TYPE -L ${DIB_ROOT_LABEL} ${IMAGE_BLOCK_DEVICE}
mkdir $TMP_BUILD_DIR/mnt mkdir $TMP_BUILD_DIR/mnt
sudo mount ${IMAGE_BLOCK_DEVICE} $TMP_BUILD_DIR/mnt sudo mount ${IMAGE_BLOCK_DEVICE} $TMP_BUILD_DIR/mnt
sudo mv -t $TMP_BUILD_DIR/mnt ${TMP_BUILD_DIR}/built/* sudo mv -t $TMP_BUILD_DIR/mnt ${TMP_BUILD_DIR}/built/*

View File

@ -80,9 +80,9 @@ EOF
sudo install -d -m 0755 -o root -g root ${TARGET_ROOT}/etc/sudoers.d 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 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 chmod 0440 ${TARGET_ROOT}/etc/sudoers.d/debian-cloud-init
sudo sh -c "echo 'proc /proc proc nodev,noexec,nosuid 0 0 sudo sh -c "echo \"proc /proc proc nodev,noexec,nosuid 0 0
LABEL=cloudimg-rootfs / ext4 errors=remount-ro 0 1 LABEL=${DIB_ROOT_LABEL} / ext4 errors=remount-ro 0 1
' > ${TARGET_ROOT}/etc/fstab" \" > ${TARGET_ROOT}/etc/fstab"
sudo sh -c "echo 'blacklist pcspkr' > ${TARGET_ROOT}/etc/modprobe.d/blacklist.conf" sudo sh -c "echo 'blacklist pcspkr' > ${TARGET_ROOT}/etc/modprobe.d/blacklist.conf"
sudo sh -c "echo 'debian' > ${TARGET_ROOT}/etc/hostname" sudo sh -c "echo 'debian' > ${TARGET_ROOT}/etc/hostname"

View File

@ -6,4 +6,4 @@ set -o pipefail
# Fedora 18 sets up for root to have a label of "_/" # Fedora 18 sets up for root to have a label of "_/"
# Fedora 19 sets up for root to have a UUID # Fedora 19 sets up for root to have a UUID
# This regex will catch both # This regex will catch both
sed -i "s%.*\s\/\s%LABEL=cloudimg-rootfs / %" /etc/fstab sed -i "s%.*\s\/\s%LABEL=${DIB_ROOT_LABEL} / %" /etc/fstab

View File

@ -38,6 +38,6 @@ DEFAULT linux
LABEL linux LABEL linux
KERNEL /boot/$KERNEL KERNEL /boot/$KERNEL
APPEND ro root=LABEL=cloudimg-rootfs console=tty0 console=ttyS0,115200 nofb nomodeset vga=normal APPEND ro root=LABEL=${DIB_ROOT_LABEL} console=tty0 console=ttyS0,115200 nofb nomodeset vga=normal
INITRD /boot/$RAMDISK INITRD /boot/$RAMDISK
_EOF_" _EOF_"

View File

@ -166,12 +166,12 @@ function install_grub2 {
# force use of a LABEL: # force use of a LABEL:
# NOTE: Updating the grub config by hand once deployed should work, its just # NOTE: Updating the grub config by hand once deployed should work, its just
# prepping it in a different environment that needs fiddling. # prepping it in a different environment that needs fiddling.
sed -i "s%$PART_DEV%LABEL=cloudimg-rootfs%" $GRUB_CFG sed -i "s%$PART_DEV%LABEL=${DIB_ROOT_LABEL}%" $GRUB_CFG
sed -i "s%search --no-floppy --fs-uuid --set=root .*$%search --no-floppy --set=root --label cloudimg-rootfs%" $GRUB_CFG sed -i "s%search --no-floppy --fs-uuid --set=root .*$%search --no-floppy --set=root --label ${DIB_ROOT_LABEL}%" $GRUB_CFG
sed -i "s%root=UUID=[A-Za-z0-9\-]*%root=LABEL=cloudimg-rootfs%" $GRUB_CFG sed -i "s%root=UUID=[A-Za-z0-9\-]*%root=LABEL=${DIB_ROOT_LABEL}%" $GRUB_CFG
if [ "$DIST" = 'Fedora' ] ; then if [ "$DIST" = 'Fedora' ] ; then
if [ $(lsb_release -rs) = '19' ]; then if [ $(lsb_release -rs) = '19' ]; then
sed -i "s%UUID=[A-Za-z0-9\-]*%LABEL=cloudimg-rootfs%" /etc/fstab sed -i "s%UUID=[A-Za-z0-9\-]*%LABEL=${DIB_ROOT_LABEL}%" /etc/fstab
fi fi
# Fix efi specific instructions in grub config file # Fix efi specific instructions in grub config file
if [ -d /sys/firmware/efi ]; then if [ -d /sys/firmware/efi ]; then