2012-11-09 11:04:13 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
2013-02-13 22:16:00 +00:00
|
|
|
# Configure grub. Note that the various conditionals here are to handle
|
|
|
|
# different distributions gracefully.
|
2012-11-09 11:04:13 +00:00
|
|
|
|
|
|
|
set -e
|
2013-04-02 00:25:25 +00:00
|
|
|
set -x
|
2012-11-09 11:04:13 +00:00
|
|
|
|
2013-04-02 00:25:25 +00:00
|
|
|
install-packages grub-pc
|
|
|
|
|
|
|
|
# XXX: grub-probe on the nbd0/loop0 device returns nothing - workaround, manually
|
2012-11-09 11:04:13 +00:00
|
|
|
# specify modules. https://bugs.launchpad.net/ubuntu/+source/grub2/+bug/1073731
|
2013-02-13 22:16:00 +00:00
|
|
|
GRUBNAME=`which grub-install` || echo "trying grub2-install"
|
|
|
|
if [ -z "$GRUBNAME" ]; then
|
2013-04-02 00:25:25 +00:00
|
|
|
GRUBNAME="bash -x `which grub2-install`"
|
2013-02-13 22:16:00 +00:00
|
|
|
fi
|
|
|
|
if [ -z "$GRUBNAME" ]; then
|
|
|
|
echo "NO grub-install or grub2-install found"
|
|
|
|
exit 1
|
|
|
|
fi
|
2013-04-02 00:25:25 +00:00
|
|
|
# FIXME:
|
|
|
|
[ -n "$IMAGE_BLOCK_DEVICE" ]
|
|
|
|
PART_DEV=$IMAGE_BLOCK_DEVICE
|
|
|
|
BOOT_DEV=$(echo $IMAGE_BLOCK_DEVICE | sed -e 's/p1//')
|
2013-05-02 01:56:01 +00:00
|
|
|
GRUB_OPTS=${GRUB_OPTS:""}
|
|
|
|
# XXX: This is buggy:
|
|
|
|
# - --target=i386-pc is invalid for non-i386/amd64 architectures
|
|
|
|
# - and for UEFI too.
|
|
|
|
# GRUB_OPTS="$GRUB_OPTS --target=i386-pc"
|
|
|
|
$GRUBNAME --modules="biosdisk part_msdos" $GRUB_OPTS $BOOT_DEV
|
2013-02-13 22:16:00 +00:00
|
|
|
# This might be better factored out into a per-distro 'install-bootblock'
|
|
|
|
# helper.
|
|
|
|
if [ -f "/boot/grub/grub.cfg" ] ; then
|
|
|
|
GRUB_CFG=/boot/grub/grub.cfg
|
|
|
|
elif [ -f "/boot/grub2/grub.cfg" ] ; then
|
|
|
|
GRUB_CFG=/boot/grub2/grub.cfg
|
|
|
|
fi
|
2013-05-10 02:59:35 +00:00
|
|
|
DIST=`lsb_release -is`
|
|
|
|
[ -n "$DIST" ]
|
2013-05-02 01:56:01 +00:00
|
|
|
RELEASE=`lsb_release -cs`
|
|
|
|
[ -n "$RELEASE" ]
|
2013-02-13 22:16:00 +00:00
|
|
|
# grub-mkconfig generates a config with the device in it,
|
2013-05-02 01:56:01 +00:00
|
|
|
# This shouldn't be needed, but old code has bugs
|
|
|
|
if [ $RELEASE = 'precise' ] ; then
|
|
|
|
# Replace the search attempt with a hardcoded root as the Ubuntu reference
|
|
|
|
# images use.
|
|
|
|
sed -i "s%search --no.*%%" $GRUB_CFG
|
|
|
|
sed -i "s%set root=.*%set root=(hd0,1)%" $GRUB_CFG
|
|
|
|
fi
|
2013-02-13 22:16:00 +00:00
|
|
|
# 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
|
2013-04-02 00:25:25 +00:00
|
|
|
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
|
2013-05-10 07:05:56 +00:00
|
|
|
# Fedora sets up for root to have a label of "_/"
|
|
|
|
sed -i "s%LABEL=_/%LABEL=cloudimg-rootfs%" /etc/fstab
|
2013-05-10 02:59:35 +00:00
|
|
|
if [ $DIST = 'Fedora' ] ; then
|
|
|
|
# enable serial console
|
|
|
|
sed -i "s%LABEL=cloudimg-rootfs%LABEL=cloudimg-rootfs console=tty0 console=ttyS0,115200%" $GRUB_CFG
|
|
|
|
fi
|