mirror of
https://git.launchpad.net/livecd-rootfs
synced 2025-02-13 22:28:27 +00:00
When trying to debug an issue on ARM64 it was reported that it was quite difficult to debug because of control codes on the console from the splash. For cloud image there is a chroot customization the drops 'quiet splash' but this is only applied to amd64. It hasn't made it into other architectures because they don't have grub by default in the chroot. However, when we get into binary hook for the uefi disk image and it's derivatives grub is installed and this includes architectures that were skipped in the chroot hook. This patch changes the cpc-fixes chroot hook to add a cloud-images grub config with basic overrides, including dropping the boot splash, for all architectures. For images that never get grub installed this addition is harmless and small while ensuring that the grub experience is consistent for images that have grub. The configuration of console devices as hard-coded remains arch specific.
266 lines
8.2 KiB
Bash
Executable File
266 lines
8.2 KiB
Bash
Executable File
#!/bin/bash -x
|
|
rootd="${1:-/}"
|
|
root_fs_label=cloudimg-rootfs
|
|
set -ex
|
|
|
|
. /root/config/chroot
|
|
|
|
CLOUD_IMG_STR="# CLOUD_IMG: This file was created/modified by the Cloud Image build process"
|
|
|
|
LANG=C
|
|
|
|
_xchroot() {
|
|
# Prevent multiple chroots
|
|
if [ "$1" = "/" ]; then
|
|
shift;
|
|
"$@"
|
|
else
|
|
chroot "$@"
|
|
fi
|
|
}
|
|
|
|
#### COMMON architecture independent functions
|
|
arch=$(_xchroot "${rootd}" dpkg --print-architecture)
|
|
|
|
## --------------
|
|
# remove 127.0.1.1 entry (LP: #440757)
|
|
_xchroot "${rootd}" sh -c 'sed -i "/^127.0.1.1/d" /etc/hosts'
|
|
|
|
## --------------
|
|
# remove ssh pregenerated keys (LP: #512377)
|
|
|
|
_xchroot "${rootd}" sh -c 'rm -f /etc/ssh/ssh_host_[rd]sa_key*'
|
|
|
|
## --------------
|
|
if [ "${SUBPROJECT:-}" != minimized ]; then
|
|
_xchroot "${rootd}" locale-gen en_US.utf8
|
|
fi
|
|
|
|
## --------------
|
|
# We continue to pre-generate en_US.UTF-8 locale above, but the default locale
|
|
# should be C.UTF-8 for 17.10 and later. For earlier releases, cloud-init may
|
|
# override this.
|
|
echo LANG="C.UTF-8" > "${rootd}/etc/default/locale"
|
|
|
|
## --------------
|
|
# set cloud-init to be on
|
|
values="NoCloud, ConfigDrive, AltCloud, OVF, MAAS, Ec2, None"
|
|
printf "%s\t%s\t%s\t%s\n" \
|
|
cloud-init cloud-init/datasources multiselect "$values" |
|
|
_xchroot "${rootd}" debconf-set-selections
|
|
_xchroot "${rootd}" dpkg-reconfigure --frontend=noninteractive cloud-init
|
|
|
|
## --------------
|
|
# write some build information to the guest
|
|
# the idea is that given runtime info and this info, the instance
|
|
# can at least determine if there is a newer build available
|
|
# these variables are passed in in environment from cloudimg-build-launcher
|
|
if [ -n "${build_name}" -o -n "${serial}" ]; then
|
|
d="${rootd}/etc/cloud"
|
|
[ -d "$d" ] || mkdir -p "${d}"
|
|
{
|
|
[ -n "${build_name}" ] && echo "build_name: ${build_name}"
|
|
[ -n "${serial}" ] && echo "serial: ${serial}"
|
|
} > "$d/build.info"
|
|
fi
|
|
|
|
## --------------
|
|
# for maverick and newer, use LABEL= for the '/' entry in fstab
|
|
if [ -n "${root_fs_label}" ]; then
|
|
bl="[:blank:]"
|
|
lstr="LABEL=${root_fs_label}"
|
|
sed -i "s,^[^#${bl}]*\([${bl}]*/[${bl}].*\),${lstr}\1," "${rootd}/etc/fstab"
|
|
fi
|
|
cat > /etc/fstab << EOM
|
|
LABEL=cloudimg-rootfs / ext4 defaults 0 0
|
|
EOM
|
|
|
|
# for quantal and newer, add /etc/overlayroot.local.conf
|
|
# but do not overwrite anything that somehow got there
|
|
if [ -f "${rootd}/etc/overlayroot.conf" ] &&
|
|
[ ! -f "${rootd}/etc/overlayroot.local.conf" ]; then
|
|
{
|
|
echo "${CLOUD_IMG_STR}"
|
|
echo "overlayroot_cfgdisk=LABEL=OROOTCFG"
|
|
} > "${rootd}/etc/overlayroot.local.conf"
|
|
fi
|
|
|
|
# previous steps may have left a dangling symlink here with
|
|
# SUBPROJECT=minimized and that breaks lb_chroot_hacks step
|
|
if [ -L "${rootd}/boot/initrd.img" ] && [ ! -e "${rootd}/boot/initrd.img" ]; then
|
|
rm "${rootd}/boot/initrd.img"
|
|
fi
|
|
|
|
if [ "${SUBPROJECT:-}" = minimized ]; then
|
|
# Remove various packages that we don't want in the minimized images.
|
|
# Some of these are tools that don't make sense by default
|
|
# non-interactively; some are libraries whose reverse-dependencies
|
|
# will have already been removed; open-vm-tools, it's a bug that this
|
|
# is in the common cloud seed because this should only be included
|
|
# in VMWare guest images, and we know none of the minimized images
|
|
# are targeted at VMWare.
|
|
_xchroot "${rootd}" env DEBIAN_FRONTEND=noninteractive \
|
|
apt-mark auto '^lib.*' '^python*' vim-runtime 2>/dev/null
|
|
# FIXME: iso-codes is a dep of software-properties and shouldn't be
|
|
_xchroot "${rootd}" env DEBIAN_FRONTEND=noninteractive \
|
|
apt-get -y autoremove --purge iso-codes xauth pastebinit \
|
|
plymouth open-vm-tools git git-man shared-mime-info vim vim-common \
|
|
console-setup ncurses-term tmux screen policykit-1 \
|
|
xdg-user-dirs less publicsuffix run-one apport-symptoms \
|
|
ubuntu-cloudimage-keyring file
|
|
|
|
_xchroot "${rootd}" apt clean
|
|
fi
|
|
|
|
# for Quantal and later, use /etc/default/grub.d functionality
|
|
# rather than modifying the grub configuration itself.
|
|
# This avoids the mess of having to do dpkg stuff
|
|
# LP: 1179940
|
|
mkdir -p "${rootd}/etc/default/grub.d"
|
|
cat << EOF > "${rootd}/etc/default/grub.d/50-cloudimg-settings.cfg"
|
|
# Cloud Image specific Grub settings for Generic Cloud Images
|
|
${CLOUD_IMG_STR}
|
|
|
|
# Set the recordfail timeout
|
|
GRUB_RECORDFAIL_TIMEOUT=0
|
|
|
|
# Do not wait on grub prompt
|
|
GRUB_TIMEOUT=0
|
|
|
|
# Drop 'quiet' and 'splash' for cloud images
|
|
GRUB_CMDLINE_LINUX_DEFAULT=""
|
|
EOF
|
|
|
|
#### END COMMON ARCH FUNCTIONS
|
|
|
|
case $arch in
|
|
# ARM, ppc, riscv64 and s390x images are special
|
|
armhf|arm64|powerpc|ppc64el|s390x|riscv64)
|
|
exit 0
|
|
;;
|
|
esac
|
|
|
|
psuedo_grub_probe() {
|
|
cat <<"PSUEDO_GRUB_PROBE"
|
|
#!/bin/sh
|
|
Usage() {
|
|
cat <<EOF
|
|
Usage: euca-psuedo-grub-probe
|
|
this is a wrapper around grub-probe to provide the answers for an ec2 guest
|
|
EOF
|
|
}
|
|
bad_Usage() { Usage 1>&2; fail "$@"; }
|
|
|
|
short_opts=""
|
|
long_opts="device-map:,target:,device"
|
|
getopt_out=$(getopt --name "${0##*/}" \
|
|
--options "${short_opts}" --long "${long_opts}" -- "$@") &&
|
|
eval set -- "${getopt_out}" ||
|
|
bad_Usage
|
|
|
|
device_map=""
|
|
target=""
|
|
device=0
|
|
arg=""
|
|
|
|
while [ $# -ne 0 ]; do
|
|
cur=${1}; next=${2};
|
|
case "$cur" in
|
|
--device-map) device_map=${next}; shift;;
|
|
--device) device=1;;
|
|
--target) target=${next}; shift;;
|
|
--) shift; break;;
|
|
esac
|
|
shift;
|
|
done
|
|
arg=${1}
|
|
|
|
case "${target}:${device}:${arg}" in
|
|
device:*:/*) echo "/dev/sda1"; exit 0;;
|
|
fs:*:*) echo "ext2"; exit 0;;
|
|
partmap:*:*)
|
|
# older versions of grub (lucid) want 'part_msdos' written
|
|
# rather than 'msdos'
|
|
legacy_pre=""
|
|
grubver=$(dpkg-query --show --showformat '${Version}\n' grub-pc 2>/dev/null) &&
|
|
dpkg --compare-versions "${grubver}" lt 1.98+20100804-5ubuntu3 &&
|
|
legacy_pre="part_"
|
|
echo "${legacy_pre}msdos";
|
|
exit 0;;
|
|
abstraction:*:*) echo ""; exit 0;;
|
|
drive:*:/dev/sda) echo "(hd0)";;
|
|
drive:*:/dev/sda*) echo "(hd0,1)";;
|
|
fs_uuid:*:*) exit 1;;
|
|
esac
|
|
PSUEDO_GRUB_PROBE
|
|
}
|
|
|
|
## install / setup grub2
|
|
gprobe="${rootd}/usr/sbin/grub-probe"
|
|
moved=0
|
|
if [ -f "${gprobe}" ]; then
|
|
mv "${gprobe}" "${gprobe}.dist"
|
|
moved=1
|
|
fi
|
|
psuedo_grub_probe > "${gprobe}"
|
|
chmod 755 "${gprobe}"
|
|
|
|
|
|
# Set the consoles on the default grub commandline
|
|
CONSOLES="console=tty1 console=ttyS0"
|
|
# Append to the existing GRUB_CMDLINE_LINUX_DEFAULT line
|
|
sed -e "/^\s*GRUB_CMDLINE_LINUX_DEFAULT=/{s/=\"\"/=\"$CONSOLES$itemNum\"/;t;s/\"$/ $CONSOLES$itemNum&/;}" \
|
|
"${rootd}/etc/default/grub.d/50-cloudimg-settings.cfg"
|
|
|
|
# Append the terminal console setting to the cloud grub config
|
|
cat << EOF >> "${rootd}/etc/default/grub.d/50-cloudimg-settings.cfg"
|
|
|
|
# Set the grub console type
|
|
GRUB_TERMINAL=console
|
|
EOF
|
|
_xchroot "${rootd}" update-grub2
|
|
|
|
# since this is a disk image, we technically don't need to install all the
|
|
# grub modules, as the image itself is not bootable. This makes for a small
|
|
# disk image
|
|
_xchroot "${rootd}" update-grub
|
|
|
|
# reconfigure grub so that upgrades to grub-pc do not force a debconf config
|
|
# changed prompt (LP: #1009294). This re-runs update-grub
|
|
_xchroot "${rootd}" env DEBIAN_FRONTEND=noninteractive \
|
|
dpkg-reconfigure grub-pc
|
|
|
|
grub2cfg="${rootd}/boot/grub/grub.cfg"
|
|
[ ! -f "${grub2cfg}" ] ||
|
|
sed -i -e "s,root=/dev/[hs]da1,root=LABEL=${root_fs_label}," "${grub2cfg}"
|
|
|
|
[ ${moved} -eq 0 ] || mv "${gprobe}.dist" "${gprobe}"
|
|
|
|
## modify /boot/grub/menu.lst if it exists
|
|
## this is generated at install time by grub-legacy-ec2, but will have
|
|
## devices as found from the _xchroot. Here we write what it will be on ec2
|
|
if [ -f "${rootd}/boot/grub/menu.lst" ]; then
|
|
grub_root="(hd0)"
|
|
linux_root=/dev/sda1
|
|
[ -n "${root_fs_label}" ] && linux_root="LABEL=${root_fs_label}"
|
|
# the sed code below basically fixes/sets the following lines in a
|
|
# /boot/grub/menu.lst file:
|
|
# # kopt=root=xxxxxxx ro
|
|
# kernel /boot/vmlinuz-... root=xxxxxx ....
|
|
# # groot=xxxxx
|
|
# root xxxxx
|
|
# uuuid xxxxx
|
|
sed -i "${rootd}/boot/grub/menu.lst" \
|
|
-e "s|^\(# kopt=root=\)[^ ]*|\1${linux_root}|" \
|
|
-e "s|^\(kernel.*root=\)[^ ]*|\1${linux_root}|" \
|
|
-e "s|^\(# groot=\)[^ ]*|\1${grub_root}|" \
|
|
-e "s|^\(root\|uuid\)\([[:space:]]*\).*|root\2${grub_root}|"
|
|
|
|
# grub-legacy-ec2 writes this ucf entry. since we've modified
|
|
# /boot/grub/menu.lst, we have to remove it, or the user will
|
|
# get prompted for a 3 way merge of the changes the first time this runs
|
|
_xchroot "${rootd}" /usr/bin/ucfr --purge grub /var/run/grub/menu.lst
|
|
fi
|
|
|
|
# vi: ts=3 expandtab
|