diff --git a/bin/disk-image-create b/bin/disk-image-create index 85b119f3b..7ea65c4dc 100755 --- a/bin/disk-image-create +++ b/bin/disk-image-create @@ -62,6 +62,7 @@ function show_options () { echo " --offline -- do not update cached resources" 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 " --root-label label -- label for the root filesystem. Defaults to 'cloudimg-rootfs'." if [ "$IS_RAMDISK" == "0" ]; then echo " -n skip the default inclusion of the 'base' element" echo " -p package[,package,package] -- list of packages to install in the image" @@ -85,7 +86,8 @@ function show_options () { INSTALL_PACKAGES="" 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 # Note the quotes around `$TEMP': they are essential! @@ -109,6 +111,7 @@ while true ; do --no-tmpfs) shift; export DIB_NO_TMPFS=1;; --offline) shift; export DIB_OFFLINE=1;; --qemu-img-options) QEMU_IMG_OPTIONS=$2; shift 2;; + --root-label) export DIB_ROOT_LABEL=$2; shift 2;; --) shift ; break ;; *) echo "Internal error!" ; exit 1 ;; esac @@ -135,9 +138,21 @@ fi arg_to_elements "$@" 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 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 pre-install scripts. These do things that prepare the chroot for package installs 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 IMAGE_BLOCK_DEVICE=$LOOPDEV 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 sudo mount ${IMAGE_BLOCK_DEVICE} $TMP_BUILD_DIR/mnt sudo mv -t $TMP_BUILD_DIR/mnt ${TMP_BUILD_DIR}/built/* diff --git a/elements/debian/root.d/08-debootstrap b/elements/debian/root.d/08-debootstrap index fc1a49116..723002b75 100755 --- a/elements/debian/root.d/08-debootstrap +++ b/elements/debian/root.d/08-debootstrap @@ -80,9 +80,9 @@ EOF 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=cloudimg-rootfs / ext4 errors=remount-ro 0 1 -' > ${TARGET_ROOT}/etc/fstab" + 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" diff --git a/elements/rpm-distro/post-install.d/05-fstab-rootfs-label b/elements/rpm-distro/post-install.d/05-fstab-rootfs-label index 959af3fec..8ab4e03e8 100755 --- a/elements/rpm-distro/post-install.d/05-fstab-rootfs-label +++ b/elements/rpm-distro/post-install.d/05-fstab-rootfs-label @@ -6,4 +6,4 @@ set -o pipefail # Fedora 18 sets up for root to have a label of "_/" # Fedora 19 sets up for root to have a UUID # 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 diff --git a/elements/vm/cleanup.d/51-bootloader b/elements/vm/cleanup.d/51-bootloader index beb480fa8..ece373666 100755 --- a/elements/vm/cleanup.d/51-bootloader +++ b/elements/vm/cleanup.d/51-bootloader @@ -38,6 +38,6 @@ DEFAULT linux LABEL linux 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 _EOF_" diff --git a/elements/vm/finalise.d/51-bootloader b/elements/vm/finalise.d/51-bootloader index 54b9c765f..31f62cbe0 100755 --- a/elements/vm/finalise.d/51-bootloader +++ b/elements/vm/finalise.d/51-bootloader @@ -166,12 +166,12 @@ function install_grub2 { # force use of a LABEL: # NOTE: Updating the grub config by hand once deployed should work, its just # prepping it in a different environment that needs fiddling. - sed -i "s%$PART_DEV%LABEL=cloudimg-rootfs%" $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%root=UUID=[A-Za-z0-9\-]*%root=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 ${DIB_ROOT_LABEL}%" $GRUB_CFG + sed -i "s%root=UUID=[A-Za-z0-9\-]*%root=LABEL=${DIB_ROOT_LABEL}%" $GRUB_CFG if [ "$DIST" = 'Fedora' ] ; 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 # Fix efi specific instructions in grub config file if [ -d /sys/firmware/efi ]; then