diff --git a/debian/changelog b/debian/changelog index 2d6c19ca..14e76a96 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,5 +1,144 @@ livecd-rootfs (2.208.14) UNRELEASED; urgency=medium + [ Robert C. Jennings ] + * Add ubuntu-cpc project (LP: #1693018) + + [ Daniel Watkins ] + * Move building of all architecture-specific CPC artifacts into Launchpad + - Fixup virtual FLAVOUR kernel name + + [ Oliver Grawert ] + * added additional CPC build targets: + - added manifest generation for squashfs and root.tar.gz + - added VMDK generation + - added OVA generation from VMDK's + - added generic Vagrant image generation + + [ Ben Howard ] + * Fix typo in ubuntu-cpc preventing non-intel builds. + * add devpts-live to hook builds + * add logic to settle the disks after UEFI builds + * extended hooks/functions to support creation of derivative images + * including mounting images. + * added the ability to create qcow2 images in hooks/functions + * simplified loop clean-up in hooks/functions + * removed assumption that disk1.img would be built + * switched qcow2 generation to use hooks/functions function + + [ Daniel Watkins ] + * Produce OVA files for i386 cloud builds. + + [ Ben Howard ] + * Remove unneeded packages from the root.tar.{gz,xz} cloud image targets + + [ Daniel Watkins ] + * Install grub in ppc64el cloud images so they are bootable + + [ Daniel Watkins ] + * Set timeout options so ppc64el cloud images don't display a grub boot + menu (matching the behaviour of other cloud images). + * Specify a regex to run-parts so that cloud image extra scripts are found + and executed. + + [ Steve Langasek ] + * Refactor/reorder ubuntu-cpc support for consistency with other flavors, + so that subarch overrides can be applied correctly. + + [ Ben Howard ] + * fixed loop setup due to change of kpartx output + * only use grub-install logic for Intel architectures + + [ Steve Langasek ] + * Refactor some non-idiomatic architecture handling in + live-build/ubuntu-cpc/hooks/999-cpc-fixes.chroot that also misidentifies + the architecture name for armhf. + + [ Steve Langasek ] + * Add hooks to ubuntu-cpc to divert /bin/sync in the chroot and undivert it + at the end. This is a general-purpose change that should be applied to + all flavors and archs, but at the moment it's only needed on armhf+raspi2 + to work around the raspberrypi2-firmware postinst calling sync, which is + actually warranted in the normal case. + * If a subarch is specified for a cloud image build, don't build rootfs + artifacts; these should come from the 'generic' build. + * Fix architecture handling in hooks. We know we're always being invoked + from a launchpad-buildd-like setup, which passes ARCH and SUBARCH in the + environment, because auto/config and auto/build both rely on this. So + don't scatter dpkg --print-architecture calls throughout, especially + when many of these are not cross-build-aware. + * Refactor ubuntu-cpc hooks to allow us to handle images where the root + partition should not be partition 1. + + [ Ben Howard ] + * ubuntu-cpc: fix hooks/032-disk-image.binary call to + create_empty_partition, which requires five args due to "-u" + * ubuntu-cpc: in hooks/030-root-tarball.binary create /lib/modules to fix + + [ Steve Langasek ] + * Refactor ubuntu-cpc hooks to always produce a 'plain' rootfs via + live-build and reuse this for the tarball, instead of lb_binary_rootfs + creating some artifact that we ignore / throw away. + * Initial support for raspi2 subarch. + * Import live-build/ubuntu-cpc/hooks/raspi2/mkknlimg from + https://github.com/raspberrypi/linux/blob/rpi-4.1.y/scripts/mkknlimg + and use it to install a bootable uboot.bin. + + [ Adam Conrad ] + * live-build/ubuntu-cpc/hooks/999-cpc-fixes.chroot: Add fake_cloud_init + function to create a nocloud data source for cloud images that aren't + meant to be used on real clouds and use it by default on armhf+raspi2 + + [ Ben Howard ] + * live-build/ubuntu-cpc/hooks/042-vagrant.binary: add serial device for + Vagrant images + + [ Daniel Watkins ] + * Refactor ubuntu-cpc hooks to hard-code producing an 'ext4' rootfs, which + is used outside of the livecd-rootfs build process (specifically for EC2 + publication). + + [ Ben Howard ] + * live-build/ubuntu-cpc/hooks/042-vagrant.binary: scope serial device for + Virtualbox only. + + [ Daniel Watkins ] + * Enable building of powerpc cloud images. + + [ Louis Zuckerman ] + * Fixes for vagrant box builder in ubuntu-cpc + - Install virtualbox-guest-utils + - Don't disable default synced folder + - Don't set vm name + - Add cloud-init config to manage /etc/hosts + + [ Steve Langasek ] + * live-build/ubuntu-cpc/hooks/042-vagrant.binary: fix unmount handling + so that the teardown is done properly /before/ we try to make an + image from our filesystem, since otherwise /etc/resolv.conf is broken. + + [ Daniel Watkins ] + * Don't overwrite the default sources.list in cloud images. + * Replace sources.list generated using COMPONENTS with the sources.list from + an Ubuntu Server installation (i.e. with all components enabled, and all + deb-src lines commented). + + [ Chris Glass ] + * Fix the manifest generation in OVA files so that ovf files don't have + double extensions. + * Fix the OVF's metadata to include Ubuntu specific identifiers and + descriptions instead of the generic Linux ones. + + [ Daniel Watkins ] + * Add replace_grub_root_with_label function thereby consolidating multiple + uses of the same calls to sed. + + [ Robert C Jennings ] + * ubuntu-cpc: Remove redundant copy of grub files. + + [ Daniel Watkins ] + * Add `apt-get update` to ubuntu-cpc ppc64el builds so they use the new + sources. + [ Balint Reczey ] * Add basic but configurable autopkgtest @@ -7,7 +146,7 @@ livecd-rootfs (2.208.14) UNRELEASED; urgency=medium * Mark autopkgtests isolation-machine since debootstrap won't work in a container. - -- Balint Reczey Thu, 11 May 2017 16:18:20 +0200 + -- Robert C Jennings Mon, 08 May 2017 17:07:02 -0500 livecd-rootfs (2.208.13) trusty; urgency=medium diff --git a/debian/copyright b/debian/copyright index 0a2a7189..3d267162 100644 --- a/debian/copyright +++ b/debian/copyright @@ -1,4 +1,4 @@ -live-build/* is copyright (c) 2004-2013 by Canonical Ltd. +live-build/* is copyright (c) 2004-2016 by Canonical Ltd. These programs are free software; you can redistribute and/or modify them under the terms of the GNU General Public License as published by @@ -16,3 +16,7 @@ livecd-rootfs source package as the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +Files: live-build/ubuntu-cpc/hooks/raspi2/mkknlimg +Copyright: 2009,2010 Dick Streefland + 2014,2015 Raspberry Pi (Trading) Limited +License: GPL-2+ diff --git a/live-build/auto/build b/live-build/auto/build index 74b702c9..dcfcc8cf 100755 --- a/live-build/auto/build +++ b/live-build/auto/build @@ -55,116 +55,56 @@ EOF # preinstalled being slightly different in what it doesn't ask) from # debian-installer's apt-setup: -codename=$LB_DISTRIBUTION -file="chroot/etc/apt/sources.list" -dists="main" -alldists="main" -if echo "$LB_PARENT_ARCHIVE_AREAS" | grep -q restricted; then - dists="$dists restricted" - alldists="$alldists restricted" -fi -if echo "$LB_PARENT_ARCHIVE_AREAS" | grep -q universe; then - UNIVERSE=true -else - UNIVERSE=false -fi -if echo "$LB_PARENT_ARCHIVE_AREAS" | grep -q multiverse; then - MULTIVERSE=true -else - MULTIVERSE=false -fi - -cat > $file < chroot/etc/apt/sources.list << EOF # See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to # newer versions of the distribution. - -deb $LB_PARENT_MIRROR_BINARY $codename $dists -deb-src $LB_PARENT_MIRROR_BINARY $codename $dists +deb $LB_PARENT_MIRROR_BINARY $LB_DISTRIBUTION main restricted +# deb-src $LB_PARENT_MIRROR_BINARY $LB_DISTRIBUTION main restricted ## Major bug fix updates produced after the final release of the ## distribution. -deb $LB_PARENT_MIRROR_BINARY $codename-updates $dists -deb-src $LB_PARENT_MIRROR_BINARY $codename-updates $dists -EOF +deb $LB_PARENT_MIRROR_BINARY $LB_DISTRIBUTION-updates main restricted +# deb-src $LB_PARENT_MIRROR_BINARY $LB_DISTRIBUTION-updates main restricted -# Even if universe isn't enabled, we write example lines for it. -echo >> $file -if [ "$UNIVERSE" = true ]; then - alldists="$alldists universe" - COMMENT= -else - cat >> $file <> $file <> $file <> $file <> $file <> $file <> $file < chroot/etc/cloud/build.info << EOF +build_name: server +serial: $BUILDSTAMP +EOF + fi echo "===== Checking size of /usr/share/doc =====" echo BEGIN docdirs @@ -329,6 +275,10 @@ for FLAVOUR in $LB_LINUX_FLAVOURS; do continue fi FLAVOUR=${FLAVOUR%%-lts-*} + if [ "$FLAVOUR" = "virtual" ]; then + # The virtual kernel is named generic in /boot + FLAVOUR="generic" + fi KVERS="$( (cd "binary/$INITFS"; ls vmlinu?-* 2>/dev/null || true) | (fgrep -v .efi || true) | sed -n "s/^vmlinu.-\\([^-]*-[^-]*-$FLAVOUR\\)$/\\1/p" )" if [ -z "$KVERS" ]; then if [ -e "binary/$INITFS/vmlinuz" ]; then diff --git a/live-build/auto/config b/live-build/auto/config index dacc156c..3889e49d 100755 --- a/live-build/auto/config +++ b/live-build/auto/config @@ -111,6 +111,12 @@ add_binary_hook () BINARY_HOOKS="${BINARY_HOOKS:+$BINARY_HOOKS }$1" } +case $PROJECT in + ubuntu-cpc) + IMAGEFORMAT=ext4 + ;; +esac + case $IMAGEFORMAT in ext2|ext3|ext4) OPTS="${OPTS:+$OPTS }--initramfs none --chroot-filesystem $IMAGEFORMAT" @@ -121,9 +127,15 @@ case $IMAGEFORMAT in COMPONENTS='main restricted universe multiverse' ;; *) - add_package live jasper - OPTS="${OPTS:+$OPTS }--swap-file-path SWAP.swap" - OPTS="${OPTS:+$OPTS }--swap-file-size 512" + case $PROJECT in + ubuntu-cpc) + ;; + *) + add_package live jasper + OPTS="${OPTS:+$OPTS }--swap-file-path SWAP.swap" + OPTS="${OPTS:+$OPTS }--swap-file-size 512" + ;; + esac ;; esac ;; @@ -164,7 +176,7 @@ if [ "$PREINSTALLED" = "true" ] && [ "$SUBPROJECT" != "wubi" ]; then ubuntu-server) add_package live oem-config-debconf ubiquity-frontend-debconf ;; - ubuntu-core|ubuntu-base|base|ubuntu-touch) + ubuntu-core|ubuntu-base|base|ubuntu-touch|ubuntu-cpc) ;; *) add_package live oem-config-gtk ubiquity-frontend-gtk @@ -381,6 +393,38 @@ case $PROJECT in OPTS="${OPTS:+$OPTS }--zsync false" ;; + ubuntu-cpc) + add_task install minimal standard cloud-image + add_package install ubuntu-minimal + + BINARY_REMOVE_LINUX=false + OPTS="${OPTS:+$OPTS }--initramfs=none" + KERNEL_FLAVOURS=virtual + case $ARCH in + armhf) + KERNEL_FLAVOURS=generic-lpae + add_package install flash-kernel + add_task install server + ;; + arm64) + KERNEL_FLAVOURS=generic + add_package install flash-kernel + add_task install server + ;; + ppc64el) + add_task install server + ;; + powerpc) + KERNEL_FLAVOURS=powerpc64-smp + add_task install server + ;; + esac + OPTS="${OPTS:+$OPTS }--system=normal" + OPTS="${OPTS:+$OPTS }--hdd-label=cloudimg-rootfs" + OPTS="${OPTS:+$OPTS }--ext-resize-blocks=536870912 --ext-block-size=4096" + OPTS="${OPTS:+$OPTS }--ext-fudge-factor=15" + ;; + *) echo "unknown project $PROJECT" >&2 exit 2 @@ -446,6 +490,11 @@ case $ARCH in echo "linux-firmware-nexus7 shared/nexus7_notice_accepted boolean true" >config/preseed/linux-firmware-nexus7.preseed.chroot echo "d-i passwd/auto-login boolean true" >config/preseed/autologin.preseed.chroot ;; + raspi2) + COMPONENTS='main restricted universe' + add_package install raspberrypi2-firmware u-boot-rpi flash-kernel u-boot-tools + BINARY_REMOVE_LINUX=false + ;; esac ;; esac @@ -466,7 +515,7 @@ add_chroot_hook remove-openssh-server-host-keys add_chroot_hook remove-udev-persistent-rules case $PROJECT in - ubuntu-server) + ubuntu-server|ubuntu-cpc) ;; *) @@ -502,6 +551,80 @@ echo "LB_CHROOT_HOOKS=\"$CHROOT_HOOKS\"" >> config/chroot echo "LB_BINARY_HOOKS=\"$BINARY_HOOKS\"" >> config/binary echo "BUILDSTAMP=\"$NOW\"" >> config/binary +case $ARCH+$SUBARCH in + armhf+raspi2) + cat > config/hooks/01-firmware-directory.chroot_early < config/hooks/999-raspi2-fixes.chroot <> /etc/fstab << EOM +LABEL=system-boot /boot/firmware vfat defaults 0 1 +EOM + +cat > /boot/firmware/cmdline.txt << EOM +dwc_otg.lpm_enable=0 console=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait +EOM + +cat > /boot/firmware/config.txt << EOM +# For more options and information see +# http://www.raspberrypi.org/documentation/configuration/config-txt.md +# Some settings may impact device functionality. See link above for details + +kernel=uboot.bin + +# enable i2c +dtparam=i2c_arm=on +dtparam=spi=on + +# uncomment if you get no picture on HDMI for a default "safe" mode +#hdmi_safe=1 + +# uncomment this if your display has a black border of unused pixels visible +# and your display can output without overscan +#disable_overscan=1 + +# uncomment the following to adjust overscan. Use positive numbers if console +# goes off screen, and negative if there is too much border +#overscan_left=16 +#overscan_right=16 +#overscan_top=16 +#overscan_bottom=16 + +# uncomment to force a console size. By default it will be display's size minus +# overscan. +#framebuffer_width=1280 +#framebuffer_height=720 + +# uncomment if hdmi display is not detected and composite is being output +#hdmi_force_hotplug=1 + +# uncomment to force a specific HDMI mode (this will force VGA) +#hdmi_group=1 +#hdmi_mode=1 + +# uncomment to force a HDMI mode rather than DVI. This can make audio work in +# DMT (computer monitor) modes +#hdmi_drive=2 + +# uncomment to increase signal to HDMI, if you have interference, blanking, or +# no display +#config_hdmi_boost=4 + +# uncomment for composite PAL +#sdtv_mode=2 + +#uncomment to overclock the arm. 700 MHz is the default. +#arm_freq=800 + +EOM +EOF + ;; + *) + ;; +esac + case $PROJECT in ubuntu-server) cat > config/hooks/100-remove-fstab.chroot < $mountpoint/usr/sbin/policy-rc.d << EOF +#!/bin/sh +# ${CLOUD_IMG_STR} +echo "All runlevel operations denied by policy" >&2 +exit 101 +EOF + chmod 0755 $mountpoint/usr/sbin/policy-rc.d + +} + +umount_settle() { + # Unmount device, and let it settle + umount $1 + udevadm settle + sleep 3 +} + +umount_partition() { + local mountpoint=${1} + mv resolv.conf.tmp "$mountpoint/etc/resolv.conf" + for submnt in proc sys dev/pts dev tmp; + do + umount_settle $mountpoint/$submnt + done + umount_settle $mountpoint + + if [ -n "${rootfs_dev_mapper}" -a -b "${rootfs_dev_mapper}" ]; then + # buildd's don't have /etc/mtab symlinked + # /etc/mtab is needed in order zerofree space for ext4 filesystems + [ -e /etc/mtab ] || ln -s /proc/mounts /etc/mtab + + # both of these are likely overkill, but it does result in slightly + # smaller ext4 filesystem + apt-get -qqy install zerofree + e2fsck -y -E discard ${rootfs_dev_mapper} + zerofree ${rootfs_dev_mapper} + fi +} + +umount_disk_image() { + mountpoint="$1" + + local uefi_dev="/dev/mapper${loop_device///dev/}p15" + if [ -e "$mountpoint/boot/efi" -a -b "$uefi_dev" ]; then + umount --detach-loop "$mountpoint/boot/efi" + fi + + if [ -e $mountpoint/usr/sbin/policy-rc.d ]; then + rm $mountpoint/usr/sbin/policy-rc.d + fi + umount_partition $mountpoint + clean_loops +} + +modify_vmdk_header() { + # Modify the VMDK headers so that both VirtualBox _and_ VMware can + # read the vmdk and import them. The vodoo here is _not_ documented + # anywhere....so this will have to do. This is undocumented vodoo + # that has been learned by the Cloud Image team. + + vmdk_name="${1}" + descriptor=$(mktemp) + newdescriptor=$(mktemp) + + # Extract the vmdk header for manipulation + dd if="${vmdk_name}" of="${descriptor}" bs=1 skip=512 count=1024 + + # The sed lines below is where the magic is. Specifically: + # ddb.toolsVersion: sets the open-vm-tools so that VMware shows + # the tooling as current + # ddb.virtualHWVersion: set the version to 7, which covers most + # current versions of VMware + # createType: make sure its set to stream Optimized + # remove the vmdk-stream-converter comment and replace with + # # Disk DescriptorFile. This is needed for Virtualbox + # remove the comments from vmdk-stream-converter which causes + # VirtualBox and others to fail VMDK validation + + sed -e 's|# Description file.*|# Disk DescriptorFile|' \ + -e '/# Believe this is random*/d' \ + -e '/# Indicates no parent/d' \ + -e '/# The Disk Data Base/d' \ + -e 's|ddb.comment.*|ddb.toolsVersion = "2147483647"|' \ + "${descriptor}" > "${newdescriptor}" + + # The header is cannot be bigger than 1024 + expr $(stat --format=%s ${newdescriptor}) \< 1024 > /dev/null 2>&1 || { + echo "descriptor is too large, VMDK will be invalid!"; exit 1; } + + # Overwrite the vmdk header with our new, modified one + dd conv=notrunc,nocreat \ + if="${newdescriptor}" of="${vmdk_name}" \ + bs=1 seek=512 count=1024 + + rm ${descriptor} ${newdescriptor} +} + +create_vmdk() { + # There is no real good way to create a _compressed_ VMDK using open source + # tooling that works across multiple VMDK-capable platforms. This functions + # uses vmdk-stream-converter and then calls modify_vmdk_header to produce a + # compatible VMDK. + + src="$1" + destination="$2" + size="${3:-10240}" + + apt-get install -qqy qemu-utils vmdk-stream-converter + streamconverter="/usr/share/pyshared/VMDKstream.py" + scratch_d=$(mktemp -d) + cp ${src} ${scratch_d}/resize.img + + truncate --size=${size}M ${scratch_d}/resize.img + python ${streamconverter} ${scratch_d}/resize.img ${destination} + modify_vmdk_header ${destination} + + qemu-img info ${destination} + rm -rf ${scratch_d} +} + +create_derivative() { + # arg1 is the disk type + # arg2 is the new name + unset derivative_img + case ${1} in + uefi) disk_image="binary/boot/disk-uefi.ext4"; + dname="${disk_image//-uefi/-$2-uefi}";; + *) disk_image="binary/boot/disk.ext4"; + dname="${disk_image//.ext4/-$2.ext4}";; + esac + + if [ ! -e ${disk_image} ]; then + echo "Did not find ${disk_image}!"; exit 1; + fi + + cp ${disk_image} ${dname} + export derivative_img=${dname} +} + +convert_to_qcow2() { + apt-get install -qqy qemu-utils + + src="$1" + destination="$2" + qemu-img convert -c -O qcow2 -o compat=0.10 "$src" "$destination" + qemu-img info "$destination" +} + +replace_grub_root_with_label() { + # When update-grub is run, it will detect the disks in the build system. + # Instead, we want grub to use the cloudimg-rootfs labelled disk + CHROOT_ROOT="$1" + + sed -i -e "s,root=[^ ]\+,root=LABEL=cloudimg-rootfs," \ + "$CHROOT_ROOT/boot/grub/grub.cfg" +} diff --git a/live-build/ubuntu-cpc/hooks/001-divert-sync.chroot_early b/live-build/ubuntu-cpc/hooks/001-divert-sync.chroot_early new file mode 100644 index 00000000..1ec152cf --- /dev/null +++ b/live-build/ubuntu-cpc/hooks/001-divert-sync.chroot_early @@ -0,0 +1,11 @@ +#!/bin/sh +set -e + +dpkg-divert --quiet --add --divert /bin/sync.REAL --rename /bin/sync +cat > /bin/sync <<'EOF' +#! /bin/sh +echo "$0: diverted by livecd-rootfs" >&2 +exit 0 +EOF + +chmod +x /bin/sync diff --git a/live-build/ubuntu-cpc/hooks/010-write-etc-ec2-version.chroot b/live-build/ubuntu-cpc/hooks/010-write-etc-ec2-version.chroot new file mode 100644 index 00000000..daa18de7 --- /dev/null +++ b/live-build/ubuntu-cpc/hooks/010-write-etc-ec2-version.chroot @@ -0,0 +1,4 @@ +#!/bin/bash -eux + +. /etc/os-release +echo "Ubuntu $VERSION" > /etc/ec2_version diff --git a/live-build/ubuntu-cpc/hooks/020-pkg-configure.chroot b/live-build/ubuntu-cpc/hooks/020-pkg-configure.chroot new file mode 100644 index 00000000..5aee6ae5 --- /dev/null +++ b/live-build/ubuntu-cpc/hooks/020-pkg-configure.chroot @@ -0,0 +1,28 @@ +#!/bin/bash +# Configure certain packages + +## console-setup + +# Select the fontface +printf "%s\t%s\t%s\t%s\n" \ + console-setup console-setup/console-setup/fontface47 string "Fixed" debconf-set-selections || + { echo "FAILED to setup console fontface"; exit 1; } + +# Select the code page for font +printf "%s\t%s\t%s\t%s\n" \ + console-setup console-setup/codesetcode string "Uni2" | debconf-set-selections || + { echo "FAILED to setup console code page to Uni2"; exit 1; } + +# Set Language string for codepage 47 +printf "%s\t%s\t%s\t%s\n" \ + console-setup console-setup/codeset47 string ". Combined - Latin; Slavic Cyrillic; Greek" | debconf-set-selections || + { echo "FAILED to setup codeset47 to proper string"; exti 1; } + +# Replace the console font and typ ein /etc/default/console-setup +sed -i -e 's,^CODESET.*,CODESET="Uni2",g' \ + -e 's,^FONTFACE.*,FONTFACE="Fixed",g' \ + /etc/default/console-setup + +# Configure the console-setup +dpkg-reconfigure --frontend=noninteractive console-setup || + { echo "FAILED to recofigure console-setup"; exit 1; } diff --git a/live-build/ubuntu-cpc/hooks/025-create-groups.chroot b/live-build/ubuntu-cpc/hooks/025-create-groups.chroot new file mode 100644 index 00000000..031cbfef --- /dev/null +++ b/live-build/ubuntu-cpc/hooks/025-create-groups.chroot @@ -0,0 +1,14 @@ +#!/bin/bash +# +# Create the necessary users and set their passwords. If needed, +# make sure they belong to the proper groups +# +# Author: Ben Howard +# Date: 29 Jun 2011 +# + +echo "Adding admin group..." +addgroup --system --quiet admin + +echo "Adding netdev group..." +addgroup --system --quiet netdev diff --git a/live-build/ubuntu-cpc/hooks/030-root-tarball.binary b/live-build/ubuntu-cpc/hooks/030-root-tarball.binary new file mode 100644 index 00000000..8856cf56 --- /dev/null +++ b/live-build/ubuntu-cpc/hooks/030-root-tarball.binary @@ -0,0 +1,32 @@ +#!/bin/bash -ex + +if [ -n "$SUBARCH" ]; then + echo "Skipping rootfs build for subarch flavor build" + exit 0 +fi + +. /build/config/functions + +mkdir binary/boot/filesystem.dir +cp -a chroot/* binary/boot/filesystem.dir + +setup_mountpoint binary/boot/filesystem.dir + +chroot binary/boot/filesystem.dir dpkg-divert --local --rename /usr/sbin/grub-probe +chroot binary/boot/filesystem.dir touch /usr/sbin/grub-probe +chroot binary/boot/filesystem.dir chmod +x /usr/sbin/grub-probe + +env DEBIAN_FRONTEND=noninteractive chroot binary/boot/filesystem.dir apt-get --purge remove --assume-yes '^linux-.*' +env DEBIAN_FRONTEND=noninteractive chroot binary/boot/filesystem.dir apt-get --purge remove --assume-yes '^grub-.*' +env DEBIAN_FRONTEND=noninteractive chroot binary/boot/filesystem.dir apt-get autoremove --purge --assume-yes +chroot binary/boot/filesystem.dir mkdir /lib/modules + +chroot binary/boot/filesystem.dir rm /usr/sbin/grub-probe +chroot binary/boot/filesystem.dir dpkg-divert --remove --local --rename /usr/sbin/grub-probe + +mv resolv.conf.tmp "binary/boot/filesystem.dir/etc/resolv.conf" +umount "binary/boot/filesystem.dir/proc" +umount "binary/boot/filesystem.dir/sys" +umount "binary/boot/filesystem.dir/dev/pts" +umount "binary/boot/filesystem.dir/dev" +umount "binary/boot/filesystem.dir/tmp" diff --git a/live-build/ubuntu-cpc/hooks/031-root-xz.binary b/live-build/ubuntu-cpc/hooks/031-root-xz.binary new file mode 100644 index 00000000..33489e92 --- /dev/null +++ b/live-build/ubuntu-cpc/hooks/031-root-xz.binary @@ -0,0 +1,13 @@ +#!/bin/bash -ex +# vi: ts=4 noexpandtab +# +# Generate the rootfs.tar.gz and manifest + +if [ -n "$SUBARCH" ]; then + exit 0 +fi + +dpkg-query --admindir=binary/boot/filesystem.dir/var/lib/dpkg -W > livecd.ubuntu-cpc.rootfs.manifest + +(cd "binary/boot/filesystem.dir/" && tar -c *) | \ + xz > "livecd.ubuntu-cpc.rootfs.tar.xz" diff --git a/live-build/ubuntu-cpc/hooks/032-disk-image.binary b/live-build/ubuntu-cpc/hooks/032-disk-image.binary new file mode 100644 index 00000000..a17f5631 --- /dev/null +++ b/live-build/ubuntu-cpc/hooks/032-disk-image.binary @@ -0,0 +1,124 @@ +#!/bin/bash -ex + +. /build/config/functions + +BOOTPART_START= +BOOTPART_END= +BOOT_MOUNTPOINT= +ROOTPART_START=1 + +case $ARCH:$SUBARCH in + ppc64el:*|powerpc:*) + echo "POWER disk images are handled separately" + exit 0 + ;; + armhf:raspi2) + # matches the size of the snappy image + IMAGE_SIZE=$((4*1000*1000*1000)) + + BOOTPART_START=8192s + BOOTPART_END=138M + BOOT_MOUNTPOINT=/boot/firmware + ;; + *) + ;; +esac + +create_empty_partition_table() { + apt-get install -qqy parted + + parted "$1" --script -- mklabel msdos +} + +create_empty_partition() { + local disk="$1" + local part="$2" + local start="$3" + local end="$4" + local type="$5" + local bootable="$6" + + parted_prefix="parted $disk --script --" + ${parted_prefix} mkpart primary "$type" "$start" "$end" + if [ -n "$bootable" ]; then + ${parted_prefix} set "$part" B + fi + ${parted_prefix} print + ${parted_prefix} align-check opt "$part" +} + +disk_image=binary/boot/disk.ext4 + +create_empty_disk_image "${disk_image}" +create_empty_partition_table "${disk_image}" + +ROOTPART=1 +ROOT_BOOTABLE=1 +if [ -n "$BOOTPART_START" ]; then + ROOTPART=2 + ROOTPART_START="$BOOTPART_END" + ROOT_BOOTABLE= + create_empty_partition "$disk_image" 1 "$BOOTPART_START" "$BOOTPART_END" fat32 1 +fi +create_empty_partition "${disk_image}" "$ROOTPART" "$ROOTPART_START" -1 ext2 "$ROOT_BOOTABLE" + +mount_image "${disk_image}" "$ROOTPART" + +# Copy the chroot in to the disk +make_ext4_partition "${rootfs_dev_mapper}" +mkdir mountpoint +mount "${rootfs_dev_mapper}" mountpoint + +if [ -n "$BOOT_MOUNTPOINT" ]; then + boot_dev_mapper="${rootfs_dev_mapper%%[0-9]}1" + # assume fat32 for now + mkfs.vfat -n system-boot "$boot_dev_mapper" + mkdir -p "mountpoint/$BOOT_MOUNTPOINT" + mount "$boot_dev_mapper" "mountpoint/$BOOT_MOUNTPOINT" +fi + +cp -a chroot/* mountpoint/ + +setup_mountpoint mountpoint + +case $ARCH:$SUBARCH in + armhf:raspi2) + chroot mountpoint flash-kernel \ + --machine "Raspberry Pi 2 Model B" + # not the best place for this, but neither flash-kernel nor + # u-boot have provisions for installing u-boot via maintainer + # script + /build/config/hooks/raspi2/mkknlimg --dtok \ + mountpoint/usr/lib/u-boot/rpi_2/u-boot.bin \ + mountpoint/boot/firmware/uboot.bin + ;; + *) ;; +esac + +case $ARCH in + amd64|i386) should_install_grub=1;; + *) should_install_grub=0;; +esac + +if [ "${should_install_grub}" -eq 1 ]; then + echo "(hd0) ${loop_device}" > mountpoint/tmp/device.map + chroot mountpoint grub-install ${loop_device} + chroot mountpoint grub-bios-setup \ + --boot-image=i386-pc/boot.img \ + --core-image=i386-pc/core.img \ + --skip-fs-probe \ + --device-map=/tmp/device.map \ + ${loop_device} + + rm mountpoint/tmp/device.map +fi + +if [ -n "$BOOT_MOUNTPOINT" ]; then + umount "mountpoint/$BOOT_MOUNTPOINT" +fi + +umount_partition mountpoint +rmdir mountpoint + +clean_loops +trap - EXIT diff --git a/live-build/ubuntu-cpc/hooks/032-root-squashfs.binary b/live-build/ubuntu-cpc/hooks/032-root-squashfs.binary new file mode 100644 index 00000000..9e3bb61e --- /dev/null +++ b/live-build/ubuntu-cpc/hooks/032-root-squashfs.binary @@ -0,0 +1,19 @@ +#!/bin/bash -ex +# vi: ts=4 noexpandtab +# +# Generate a squashfs root and manifest + +if [ -n "$SUBARCH" ]; then + exit 0 +fi + +apt-get -qqy install squashfs-tools + +squashfs_f="${PWD}/livecd.ubuntu-cpc.squashfs" +squashfs_f_manifest="${squashfs_f}.manifest" + +dpkg-query --admindir=binary/boot/filesystem.dir/var/lib/dpkg -W > ${squashfs_f_manifest} + +(cd "binary/boot/filesystem.dir/" && + mksquashfs . ${squashfs_f} \ + -no-progress -xattrs -comp xz ) diff --git a/live-build/ubuntu-cpc/hooks/033-disk-image-uefi.binary b/live-build/ubuntu-cpc/hooks/033-disk-image-uefi.binary new file mode 100644 index 00000000..04a3c7df --- /dev/null +++ b/live-build/ubuntu-cpc/hooks/033-disk-image-uefi.binary @@ -0,0 +1,141 @@ +#!/bin/bash -eux + +case $ARCH in + amd64|arm64) + ;; + *) + echo "We don't create EFI images for $ARCH." + exit 0 + ;; +esac + +. /build/config/functions + +apt-get -qqy install dosfstools gdisk + +create_partitions() { + disk_image="$1" + sgdisk "${disk_image}" --zap-all + case $ARCH in + arm64) + sgdisk "${disk_image}" \ + --new=15:0:204800 \ + --typecode=15:ef00 \ + --new=1: + ;; + amd64) + sgdisk "${disk_image}" \ + --new=14::+4M \ + --new=15::+106M \ + --new=1:: + sgdisk "${disk_image}" \ + -t 14:ef02 \ + -t 15:ef00 + ;; + esac + sgdisk "${disk_image}" \ + --print +} + +create_and_mount_uefi_partition() { + uefi_dev="/dev/mapper${loop_device///dev/}p15" + mountpoint="$1" + mkfs.vfat -F 32 -n UEFI "${uefi_dev}" + + mkdir -p "${mountpoint}"/boot/efi + mount "${uefi_dev}" "$mountpoint"/boot/efi + + cat << EOF >> "mountpoint/etc/fstab" +LABEL=UEFI /boot/efi vfat defaults 0 0 +EOF +} + +install_grub() { + mkdir mountpoint + mount_partition "${rootfs_dev_mapper}" mountpoint + + create_and_mount_uefi_partition mountpoint + + echo "(hd0) ${loop_device}" > mountpoint/tmp/device.map + mkdir -p mountpoint/etc/default/grub.d + efi_boot_dir="/boot/efi/EFI/BOOT" + chroot mountpoint mkdir -p "${efi_boot_dir}" + + case $ARCH in + arm64) + chroot mountpoint apt-get -qqy install --no-install-recommends grub-efi-arm64 grub-efi-arm64-bin + grub_modules="part_gpt fat gzio ext2 normal chain boot configfile linux search_fs_uuid search_label terminal serial video video_fb efi_gop" + efi_target=arm64-efi + ;; + amd64) + chroot mountpoint apt-get install -qqy grub-efi-amd64-signed grub-efi-amd64 shim-signed + grub_modules="part_gpt fat ext2 normal chain boot configfile linux multiboot search_fs_uuid search_label terminal serial video video_fb video_bochs usb usb_keyboard efi_gop efi_uga" + efi_target=x86_64-efi + ;; + esac + + cat << EOF >> mountpoint/etc/default/grub.d/50-cloudimg-settings.cfg +${CLOUD_IMG_STR} +# For Cloud Image compatability +GRUB_PRELOAD_MODULES="${grub_modules}" +EOF + chroot mountpoint grub-install "${loop_device}" \ + --boot-directory=/boot \ + --efi-directory=/boot/efi \ + --target=${efi_target} \ + --removable \ + --uefi-secure-boot \ + --no-nvram \ + --modules="${grub_modules}" + + if [ -f mountpoint/boot/efi/EFI/BOOT/grub.cfg ]; then + sed -i "s| root| root hd0,gpt1|" mountpoint/boot/efi/EFI/BOOT/grub.cfg + sed -i "1i${CLOUD_IMG_STR}" mountpoint/boot/efi/EFI/BOOT/grub.cfg + # For some reason the grub disk is looking for /boot/grub/grub.cfg on + # part 15.... + chroot mountpoint mkdir -p /boot/efi/boot/grub + chroot mountpoint cp /boot/efi/EFI/BOOT/grub.cfg /boot/efi/boot/grub + fi + + if [ "$ARCH" = "amd64" ]; then + # Install the BIOS/GPT bits. Since GPT boots from the ESP partition, + # it means that we just run this simple command and we're done + chroot mountpoint grub-install --target=i386-pc "${loop_device}" + fi + + chroot mountpoint dpkg-divert --local --rename /etc/grub.d/30_os-prober + chroot mountpoint update-grub + replace_grub_root_with_label mountpoint + chroot mountpoint dpkg-divert --remove --local --rename /etc/grub.d/30_os-prober + + chroot mountpoint apt-get -y clean + chroot mountpoint apt-get -y update + + rm mountpoint/tmp/device.map + sync + umount mountpoint/boot/efi + sleep 5 + udevadm settle + mount + umount_partition mountpoint + rmdir mountpoint +} + +disk_image=binary/boot/disk-uefi.ext4 + +create_empty_disk_image "${disk_image}" +create_partitions "${disk_image}" +mount_image "${disk_image}" 1 + +# Copy the chroot in to the disk +make_ext4_partition "${rootfs_dev_mapper}" +mkdir mountpoint +mount "${rootfs_dev_mapper}" mountpoint +cp -a chroot/* mountpoint/ +umount mountpoint +rmdir mountpoint + +install_grub + +clean_loops +trap - EXIT diff --git a/live-build/ubuntu-cpc/hooks/034-disk-image-ppc64el.binary b/live-build/ubuntu-cpc/hooks/034-disk-image-ppc64el.binary new file mode 100644 index 00000000..1f6b35a7 --- /dev/null +++ b/live-build/ubuntu-cpc/hooks/034-disk-image-ppc64el.binary @@ -0,0 +1,79 @@ +#!/bin/bash -eux +case $ARCH in + ppc64el|powerpc) + ;; + *) + exit 0 + ;; +esac + +. /build/config/functions + +create_partitions() { + disk_image="$1" + apt-get install -qqy gdisk + sgdisk "${disk_image}" \ + --zap-all + sgdisk "${disk_image}" \ + --new=2::+8M \ + --new=1: + sgdisk "${disk_image}" -t 2:4100 + sgdisk "${disk_image}" \ + --print +} + +install_grub() { + mkdir mountpoint + mount_partition "${rootfs_dev_mapper}" mountpoint + + chroot mountpoint apt-get -qqy update + chroot mountpoint apt-get -qqy install grub2 + chroot mountpoint apt-get -qqy remove --purge grub-legacy-ec2 + + # set the kernel commandline to use hvc0 + mkdir -p mountpoint/etc/default/grub.d + cat << EOF > mountpoint/etc/default/grub.d/50-cloudimg-settings.cfg +${CLOUD_IMG_STR} + +# Set the recordfail timeout +GRUB_RECORDFAIL_TIMEOUT=0 + +# Do not wait on grub prompt +GRUB_TIMEOUT=0 + +# Set the default commandline +GRUB_CMDLINE_LINUX_DEFAULT="console=hvc0 earlyprintk" +EOF + prep_partition="/dev/mapper${loop_device///dev/}p2" + chroot mountpoint grub-install "${prep_partition}" \ + --no-nvram \ + --boot-directory=/boot \ + --target=powerpc-ieee1275 + + chroot mountpoint dpkg-divert --local --rename /etc/grub.d/30_os-prober + chroot mountpoint update-grub + replace_grub_root_with_label mountpoint + chroot mountpoint dpkg-divert --remove --local --rename /etc/grub.d/30_os-prober + + umount_partition mountpoint + rmdir mountpoint +} + +disk_image=binary/boot/disk.ext4 + +create_empty_disk_image "${disk_image}" +create_partitions "${disk_image}" +mount_image "${disk_image}" 1 + +# Copy the chroot in to the disk +make_ext4_partition "${rootfs_dev_mapper}" +mkdir mountpoint +mount "${rootfs_dev_mapper}" mountpoint +cp -a chroot/* mountpoint/ +umount mountpoint +rmdir mountpoint + +install_grub + +clean_loops +trap - EXIT diff --git a/live-build/ubuntu-cpc/hooks/040-qcow2-image.binary b/live-build/ubuntu-cpc/hooks/040-qcow2-image.binary new file mode 100644 index 00000000..602d871e --- /dev/null +++ b/live-build/ubuntu-cpc/hooks/040-qcow2-image.binary @@ -0,0 +1,23 @@ +#!/bin/bash -ex + +case $ARCH:$SUBARCH in + # Not sure if any other cloud images use subarch for something that + # should take qcow2 format, so only skipping this on raspi2 for now. + armhf:raspi2) + apt-get install -qqy pxz + pxz -T4 -c binary/boot/disk.ext4 > livecd.ubuntu-cpc.disk1.img.xz + exit 0 + ;; +esac + +apt-get install -qqy qemu-utils + +. /build/config/functions + +if [ -f binary/boot/disk.ext4 ]; then + convert_to_qcow2 binary/boot/disk.ext4 livecd.ubuntu-cpc.disk1.img +fi + +if [ -f binary/boot/disk-uefi.ext4 ]; then + convert_to_qcow2 binary/boot/disk-uefi.ext4 livecd.ubuntu-cpc.uefi1.img +fi diff --git a/live-build/ubuntu-cpc/hooks/040-vmdk-image.binary b/live-build/ubuntu-cpc/hooks/040-vmdk-image.binary new file mode 100644 index 00000000..80e4142c --- /dev/null +++ b/live-build/ubuntu-cpc/hooks/040-vmdk-image.binary @@ -0,0 +1,22 @@ +#!/bin/bash -eux +# vi: ts=4 expandtab +# +# Generate VMDK files + +extension="disk1.vmdk" + +case $ARCH in + i386|amd64) ;; + *) echo "VMDK images are not supported for $ARCH yet."; + exit 0;; +esac + +. /build/config/functions + +if [ -e binary/boot/disk.ext4 ]; then + create_vmdk binary/boot/disk.ext4 livecd.ubuntu-cpc.disk1.vmdk +fi + +if [ -e binary/boot/disk-uefi.ext4 ]; then + create_vmdk binary/boot/disk-uefi.ext4 livecd.ubuntu-cpc.uefi.vmdk +fi diff --git a/live-build/ubuntu-cpc/hooks/041-vmdk-ova-image.binary b/live-build/ubuntu-cpc/hooks/041-vmdk-ova-image.binary new file mode 100644 index 00000000..cc8ed5d3 --- /dev/null +++ b/live-build/ubuntu-cpc/hooks/041-vmdk-ova-image.binary @@ -0,0 +1,105 @@ +#!/bin/bash -eux +# vi: ts=4 expandtab +# +# Generate OVA images +# +# OVA images are, by defintiion a tarball consisting of a disk image, OVF file +# and checksums. This step produces an OVA that is suitable for use with +# Cloud's that support the OVF specification. +# +# For this step, we re-use the VMDK's made in 040-vmdk-image.binary + + +# Switch on $ARCH to determine which ID and description to use in the produced +# OVF. We have fancy Ubuntu-specific IDs in the OVF specification, we might as +# well use them. +case $ARCH in + amd64) + ovf_id=94 + ovf_os_type="ubuntu64Guest" + ovf_desc_bits=64 ;; + i386) + ovf_id=93 + ovf_os_type="ubuntu32Guest" + ovf_desc_bits=32 ;; + *) + echo "OVA images are not supported for $ARCH yet."; + exit 0;; +esac + +cur_d=${PWD} +my_d=$(dirname $(readlink -f ${0})) + +base_vmdk="livecd.ubuntu-cpc.disk1.vmdk" +if [ "$ARCH" = "amd64" ]; then + base_vmdk="livecd.ubuntu-cpc.uefi.vmdk" +fi + +if [ ! -e ${base_vmdk} ]; then + find . | grep vmdk + exit 0 +fi + +# Lets be safe about this +scratch_d=$(mktemp -d) +trap "rm -rf ${scratch_d}" EXIT + +# Used to identify bits +suite=$(chroot chroot lsb_release -c -s) +version=$(chroot chroot lsb_release --release --short) +distro=$(chroot chroot lsb_release --id --short | tr [:upper:] [:lower:]) + +# Put our vmdk in place for OVA conversion +prefix="${distro}-${suite}-${version}-cloudimg" +vmdk_f="${scratch_d}/${prefix}.vmdk" +cp ${base_vmdk} ${vmdk_f} + +# Get information about the VMDK +vmdk_size=$(du -b "${vmdk_f}" | cut -f1) +vmdk_capacity=$(qemu-img info "${vmdk_f}" | awk '-F[\( ]' '$1 ~ /virtual/ && $NF ~ /bytes.*/ {print$(NF-1)}') + +# Populate the OVF template +ovf="${scratch_d}/${prefix}.ovf" +cp ${my_d}/ovf/ubuntu-ova-v1-vmdk.tmpl ${ovf} +serial_stamp=$(date +%Y%m%d) +sed -i "${ovf}" \ + -e "s/@@NAME@@/${prefix}-${serial_stamp}/g" \ + -e "s/@@FILENAME@@/${vmdk_f##*/}/g" \ + -e "s/@@VMDK_FILE_SIZE@@/${vmdk_size}/g" \ + -e "s/@@VMDK_CAPACITY@@/${vmdk_capacity}/g" \ + -e "s/@@NUM_CPUS@@/2/g" \ + -e "s/@@VERSION@@/${version}/g" \ + -e "s/@@DATE@@/${serial_stamp}/g" \ + -e "s/@@MEM_SIZE@@/1024/g" \ + -e "s/@@OVF_ID@@/${ovf_id}/g" \ + -e "s/@@OVF_OS_TYPE@@/${ovf_os_type}/g" \ + -e "s/@@OVF_DESC_BITS@@/${ovf_desc_bits}/g" + +# Get the checksums +vmdk_sha256=$(sha256sum ${vmdk_f} | cut -d' ' -f1) +ovf_sha256=$(sha256sum ${ovf} | cut -d' ' -f1) + +# Generate the manifest +manifest="${scratch_d}/${prefix}.mf" +cat > "${manifest}" < ${seed_d}/user-data < ${seed_d}/meta-data < ${box_d}/Vagrantfile < ${box_d}/metadata.json < "${manifest}" <> /etc/default/rcS diff --git a/live-build/ubuntu-cpc/hooks/052-ssh_authentication.chroot b/live-build/ubuntu-cpc/hooks/052-ssh_authentication.chroot new file mode 100644 index 00000000..6b0a34ea --- /dev/null +++ b/live-build/ubuntu-cpc/hooks/052-ssh_authentication.chroot @@ -0,0 +1,3 @@ +#!/bin/bash + +sed -i "s|#PasswordAuthentication yes|PasswordAuthentication no|g" /etc/ssh/sshd_config diff --git a/live-build/ubuntu-cpc/hooks/060-ipv6.chroot b/live-build/ubuntu-cpc/hooks/060-ipv6.chroot new file mode 100644 index 00000000..3d4a0be2 --- /dev/null +++ b/live-build/ubuntu-cpc/hooks/060-ipv6.chroot @@ -0,0 +1,18 @@ +#!/bin/bash +# +# Disable IPv6 privacy extensions on Utopic and later +# + +codename=$(sh -c 'lsb_release --short --codename') +dist_ge() { [[ "$1" > "$2" || "$1" == "$2" ]]; } + +if ! dist_ge "${codename}" "trusty"; then + exit 0 +fi + +cat << EOF > /etc/sysctl.d/99-cloudimg-ipv6.conf +# Written by the Cloud Image build process +# See https://bugs.launchpad.net/ubuntu/+source/procps/+bug/1068756 +net.ipv6.conf.all.use_tempaddr = 0 +net.ipv6.conf.default.use_tempaddr = 0 +EOF diff --git a/live-build/ubuntu-cpc/hooks/099-cleanup.chroot b/live-build/ubuntu-cpc/hooks/099-cleanup.chroot new file mode 100644 index 00000000..cf2b7dd1 --- /dev/null +++ b/live-build/ubuntu-cpc/hooks/099-cleanup.chroot @@ -0,0 +1,57 @@ +#!/bin/bash + +# Clean up extraneous log files that may be left around +rm /etc/ssh/ssh_host*key* || echo "No SSH keys to remove" + +# Fix LP: #1047707, 1019338 +# Truncate logs that are owned, otherwise remove +whitelisted_logs=(/var/log/btmp /var/log/lastlog /var/log/wtmp /var/log/fsck/checkfs /var/log/fsck/checkroot) + +for log in $(find /var/log -type f) +do + whitelisted=$(echo "${whitelisted_logs[@]}" | grep -o ${log}) + + if [ -n "${whitelisted}" ]; then + : > ${log} && + echo "Truncated whitelisted log ${log}" || + echo "Failed to truncate whitelisted log ${log}" + else + + dpkg -S ${log} > /dev/null 2>&1 && + { : > ${log} || + echo "Failed to truncate $f"; } || + { rm ${log} && + echo "Removed ${log} as an orphaned log file" || + echo "Failed to remove unnecessary log $f"; } + fi +done + +# Remove un-owned log directories +whitelisted_dirs=(/var/log/fsck) + +for log_d in $(find /var/log/* -type d) +do + whitelisted=$(echo "${whitelisted_dirs[@]}" | grep -o "${log_d}") + if [ -z "${whitelisted}" ]; then + dpkg -S ${log_d} > /dev/null 2>&1 && + echo "Preserving log directory ${log_d}" || + { rm -rf ${log_d} && + echo "Removed log directory ${log_d} as orphaned log dir" || + echo "Failed to remove unnessasary log dir ${log_d}"; } + + else + echo "Preserving whitelisted directory ${log_d}" + fi + +done + + +rm -rf /var/run/* || echo "Failed to clean /var/run/*" +rm /etc/passwd- || echo "No spare passwd file to cleanup" +rm /etc/shadow- || echo "No spare shadow file to cleanup" +rm /etc/gshadow- || echo "No spare gshadow file to cleanup" +rm /etc/group- || echo "No spare group file to clenaup" +rm -f /etc/apt/conf.d/00secure || echo "No apt cache to cleanup" + +# Truncate instead of delete, LP: #707311 +truncate --size=0 -c /etc/popularity-contest.conf diff --git a/live-build/ubuntu-cpc/hooks/999-cpc-fixes.chroot b/live-build/ubuntu-cpc/hooks/999-cpc-fixes.chroot new file mode 100644 index 00000000..815d946d --- /dev/null +++ b/live-build/ubuntu-cpc/hooks/999-cpc-fixes.chroot @@ -0,0 +1,312 @@ +#!/bin/bash -x +rootd="${1:-/}" +root_fs_label=cloudimg-rootfs +set -ex + +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) + +add_serial_console() { + condev=$1 + idir="$rootd/etc/init" + cat << EOF > "${idir}/${condev}.conf" +# CONDEV - getty +# +# This service maintains a getty on CONDEV from the point the system is +# started until it is shut down again. + +start on stopped rc RUNLEVEL=[2345] and ( + not-container or + container CONTAINER=lxc or + container CONTAINER=lxc-libvirt) + +stop on runlevel [!2345] + +pre-start script + # getty will not be started if the serial console is not present + stty -F /dev/CONDEV -a 2> /dev/null > /dev/null || { stop ; exit 0; } +end script + +respawn +script + exec /sbin/getty -L CONDEV 115200 vt102 +end script +${CLOUD_IMG_STR} +EOF + sed -i "s/CONDEV/${condev}/g" "$idir/${condev}.conf" +} + +fake_cloud_init() { + # If the cloud does not provide a meta-data service this should be run + # This will setup a nocloud datasource. + + seed_d="${rootd}/var/lib/cloud/seed/nocloud-net" + mkdir -p "${seed_d}" + + # fake instance-id + cat << EOF > "${seed_d}/meta-data" +instance_id: cloud-image +EOF + + # fake user-data to create the default user/password + cat << EOF > "${seed_d}/user-data" +#cloud-config +password: ubuntu +chpasswd: ubuntu +ssh_pwauth: True +EOF + + # tell cloud-init not to look for meta-data sources + cat << EOF > ${rootd}/etc/cloud/cloud.cfg.d/99-fake_cloud.cfg +# configure cloud-init for NoCloud +datasource_list: [ NoCloud, None ] +EOF +} + +## -------------- +# 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*' + +## -------------- +_xchroot "${rootd}" locale-gen en_US.utf8 + +## -------------- +# 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 + +## Make sure that the update-motd.d directory exists +[ ! -e "${rootd}/etc/update-motd.d" ] && + mkdir -p "${rootd}/etc/update-motd.d" + +## write a MOTD file advertising support for images +cat > "${rootd}/etc/update-motd.d/51-cloudguest" << EOF +#!/bin/sh +# +${CLOUD_IMG_STR} +# This file is not managed by a package. If you no longer want to +# see this message you can safely remove the file. +echo "" +echo " Get cloud support with Ubuntu Advantage Cloud Guest:" +echo " http://www.ubuntu.com/business/services/cloud" +EOF + +chmod +x "${rootd}/etc/update-motd.d/51-cloudguest" + +# 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 + + +#### END COMMON ARCH FUNCTIONS + + +case $arch in + # ARM images are special + armhf|arm64) + echo "Configuring ARM Serial Port" + add_serial_console ttyAMA0 + # Dirty hack because SUBARCH doesn't exist when running chroot hooks, + # and we don't want raspi2 images to depend on a cloud data source: + if _xchroot "${rootd}" dpkg -l linux-image-raspi2 2>/dev/null | grep -q '^.i'; then + fake_cloud_init + fi + + echo "Image architecture is ARM. Existing vmbuilder-fixups" + + exit 0 + ;; + ## Add ttyS0 for i386/amd64 for Trusty and newer + i386|amd64) + add_serial_console ttyS0 + ;; + powerpc|ppc64el) + add_serial_console hvc0 + exit 0 + ;; +esac + +psuedo_grub_probe() { + cat <<"PSUEDO_GRUB_PROBE" +#!/bin/sh +Usage() { + cat <&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}" + +# 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 + +# Set the default commandline +GRUB_CMDLINE_LINUX_DEFAULT="console=tty1 console=ttyS0" + +# 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 diff --git a/live-build/ubuntu-cpc/hooks/999-extras.binary b/live-build/ubuntu-cpc/hooks/999-extras.binary new file mode 100644 index 00000000..ffc7c691 --- /dev/null +++ b/live-build/ubuntu-cpc/hooks/999-extras.binary @@ -0,0 +1,15 @@ +#!/bin/bash +# Execute extra binary hooks. + +my_dir=$(dirname $(readlink -f ${0})) +extra_d=${my_dir}/extra + +if [ ! -d ${my_dir}/extra ]; then + exit 0 +fi + +# Export the common functions to the extras +. /build/config/functions + +# Cleaner execution +/bin/run-parts --regex ".*\.binary" "${extra_d}" diff --git a/live-build/ubuntu-cpc/hooks/999-undivert-sync.chroot b/live-build/ubuntu-cpc/hooks/999-undivert-sync.chroot new file mode 100644 index 00000000..8a97432d --- /dev/null +++ b/live-build/ubuntu-cpc/hooks/999-undivert-sync.chroot @@ -0,0 +1,5 @@ +#! /bin/sh +set -e + +rm -f /bin/sync +dpkg-divert --quiet --remove --rename /bin/sync diff --git a/live-build/ubuntu-cpc/hooks/ovf/ubuntu-ova-v1-cloudcfg-vmdk.tmpl b/live-build/ubuntu-cpc/hooks/ovf/ubuntu-ova-v1-cloudcfg-vmdk.tmpl new file mode 100644 index 00000000..f2975610 --- /dev/null +++ b/live-build/ubuntu-cpc/hooks/ovf/ubuntu-ova-v1-cloudcfg-vmdk.tmpl @@ -0,0 +1,180 @@ + + + + + + + + Virtual disk information + + + + + The list of logical networks + + The VM Network network + + + + A virtual machine + @@NAME@@ + + The kind of installed guest operating system + Ubuntu Linux (@@OVF_DESC_BITS@@-bit) + + + + Cloud-Init customization + Ubuntu @@VERSION@@ Server (@@DATE@@) + + + Specifies the instance id. This is required and used to determine if the machine should take "first boot" actions + + + Specifies the hostname for the appliance + + + + This field is optional, but indicates that the instance should 'seed' user-data and meta-data from the given url. If set to 'http://tinyurl.com/sm-' is given, meta-data will be pulled from http://tinyurl.com/sm-meta-data and user-data from http://tinyurl.com/sm-user-data. Leave this empty if you do not want to seed from a url. + + + + This field is optional, but indicates that the instance should populate the default user's 'authorized_keys' with this value + + + + In order to fit into a xml attribute, this value is base64 encoded . It will be decoded, and then processed normally as user-data. + + + + + If set, the default user's password will be set to this value to allow password based login. The password will be good for only a single login. If set to the string 'RANDOM' then a random password will be generated, and written to the console. + + + + + Virtual hardware requirements + + Virtual Hardware Family + 0 + @@NAME@@ + vmx-10 + + + hertz * 10^6 + Number of Virtual CPUs + @@NUM_CPUS@@ virtual CPU(s) + 1 + 3 + @@NUM_CPUS@@ + + + byte * 2^20 + Memory Size + @@MEM_SIZE@@MB of memory + 2 + 4 + @@MEM_SIZE@@ + + + 0 + SCSI Controller + SCSI Controller 0 + 3 + VirtualSCSI + 6 + + + 1 + IDE Controller + VirtualIDEController 1 + 4 + 5 + + + 0 + IDE Controller + VirtualIDEController 0 + 5 + 5 + + + false + VirtualVideoCard + 6 + 24 + + + + + + + + false + VirtualVMCIDevice + 7 + vmware.vmci + 1 + + + + 0 + false + CD-ROM 1 + 8 + 4 + vmware.cdrom.remotepassthrough + 15 + + + + 0 + Hard Disk 1 + ovf:/disk/vmdisk1 + 9 + 3 + 17 + + + + 1 + ConfigDriveDisk + ovf:/disk/vmdisk2 + 10 + 3 + 17 + + + + 7 + true + VM Network + VmxNet3 ethernet adapter on "VM Network" + Ethernet 1 + 11 + VmxNet3 + 10 + + + + + + + + + + + + + + + + + + + + + + diff --git a/live-build/ubuntu-cpc/hooks/ovf/ubuntu-ova-v1-vmdk.tmpl b/live-build/ubuntu-cpc/hooks/ovf/ubuntu-ova-v1-vmdk.tmpl new file mode 100644 index 00000000..7f0b85e0 --- /dev/null +++ b/live-build/ubuntu-cpc/hooks/ovf/ubuntu-ova-v1-vmdk.tmpl @@ -0,0 +1,178 @@ + + + + + + + Virtual disk information + + + + The list of logical networks + + The VM Network network + + + + A virtual machine + @@NAME@@ + + The kind of installed guest operating system + Ubuntu Linux (@@OVF_DESC_BITS@@-bit) + + + + Cloud-Init customization + Ubuntu @@VERSION@@ Server (@@DATE@@) + + + Specifies the instance id. This is required and used to determine if the machine should take "first boot" actions + + + Specifies the hostname for the appliance + + + + This field is optional, but indicates that the instance should 'seed' user-data and meta-data from the given url. If set to 'http://tinyurl.com/sm-' is given, meta-data will be pulled from http://tinyurl.com/sm-meta-data and user-data from http://tinyurl.com/sm-user-data. Leave this empty if you do not want to seed from a url. + + + + This field is optional, but indicates that the instance should populate the default user's 'authorized_keys' with this value + + + + In order to fit into a xml attribute, this value is base64 encoded . It will be decoded, and then processed normally as user-data. + + + + + If set, the default user's password will be set to this value to allow password based login. The password will be good for only a single login. If set to the string 'RANDOM' then a random password will be generated, and written to the console. + + + + + Virtual hardware requirements + + Virtual Hardware Family + 0 + @@NAME@@ + vmx-10 + + + hertz * 10^6 + Number of Virtual CPUs + @@NUM_CPUS@@ virtual CPU(s) + 1 + 3 + @@NUM_CPUS@@ + + + byte * 2^20 + Memory Size + @@MEM_SIZE@@MB of memory + 2 + 4 + @@MEM_SIZE@@ + + + 0 + SCSI Controller + SCSI Controller 0 + 3 + VirtualSCSI + 6 + + + 1 + IDE Controller + VirtualIDEController 1 + 4 + 5 + + + 0 + IDE Controller + VirtualIDEController 0 + 5 + 5 + + + false + VirtualVideoCard + 6 + 24 + + + + + + + + false + VirtualVMCIDevice + 7 + vmware.vmci + 1 + + + + 0 + false + CD-ROM 1 + 8 + 4 + vmware.cdrom.remotepassthrough + 15 + + + + 0 + Hard Disk 1 + ovf:/disk/vmdisk1 + 9 + 3 + 17 + + + + 0 + false + Floppy Drive + Floppy 1 + 10 + vmware.floppy.remotedevice + 14 + + + 7 + true + VM Network + VmxNet3 ethernet adapter on "VM Network" + Ethernet 1 + 11 + VmxNet3 + 10 + + + + + + + + + + + + + + + + + + + + + + diff --git a/live-build/ubuntu-cpc/hooks/ovf/ubuntu-ovf-v1-img.tmpl b/live-build/ubuntu-cpc/hooks/ovf/ubuntu-ovf-v1-img.tmpl new file mode 100644 index 00000000..161b8f61 --- /dev/null +++ b/live-build/ubuntu-cpc/hooks/ovf/ubuntu-ovf-v1-img.tmpl @@ -0,0 +1,130 @@ + + + + + + + Virtual disk information + + + + The list of logical networks + + The bridged network + + + + A virtual machine + $VIRTUAL_SYSTEM_NAME + + $VIRTUAL_SYSTEM_OS_INFO + + + Cloud-Init customization + $VIRTUAL_SYSTEM_OS_INFO + + + Specifies the instance id. This is required and used to determine if the machine should take "first boot" actions + + + Specifies the hostname for the appliance + + + + This field is optional, but indicates that the instance should 'seed' user-data and meta-data from the given url. If set to 'http://tinyurl.com/sm-' is given, meta-data will be pulled from http://tinyurl.com/sm-meta-data and user-data from http://tinyurl.com/sm-user-data. Leave this empty if you do not want to seed from a url. + + + + This field is optional, but indicates that the instance should populate the default user's 'authorized_keys' with this value + + + + In order to fit into a xml attribute, this value is base64 encoded . It will be decoded, and then processed normally as user-data. + + + + + If set, the default user's password will be set to this value to allow password based login. The password will be good for only a single login. If set to the string 'RANDOM' then a random password will be generated, and written to the console. + + + + Virtual hardware requirements + + Virtual Hardware Family + 0 + $VIRTUAL_SYSTEM_IDENTIFIER + $VIRTUAL_SYSTEM_TYPES + + + hertz * 10^6 + Number of Virtual CPUs + 1 virtual CPU(s) + 1 + 3 + 1 + + + byte * 2^20 + Memory Size + 256MB of memory + 2 + 4 + 256 + + + 0 + USB Controller + usb + 3 + 23 + + + 0 + SCSI Controller + scsiController0 + 4 + lsilogic + 6 + + + 1 + IDE Controller + ideController1 + 5 + 5 + + + 0 + false + cdrom1 + 6 + 5 + 15 + + + 0 + disk1 + ovf:/disk/vmdisk1 + 7 + 4 + 17 + + + 2 + true + bridged + ethernet adapter on "bridged" + ethernet0 + 8 + E1000 + 10 + + + + $ANNOTATION_INFO + $ANNOTATION + + + diff --git a/live-build/ubuntu-cpc/hooks/raspi2/mkknlimg b/live-build/ubuntu-cpc/hooks/raspi2/mkknlimg new file mode 100644 index 00000000..3998d43b --- /dev/null +++ b/live-build/ubuntu-cpc/hooks/raspi2/mkknlimg @@ -0,0 +1,244 @@ +#!/usr/bin/env perl +# ---------------------------------------------------------------------- +# mkknlimg by Phil Elwell for Raspberry Pi +# based on extract-ikconfig by Dick Streefland +# +# (c) 2009,2010 Dick Streefland +# (c) 2014,2015 Raspberry Pi (Trading) Limited +# +# Licensed under the terms of the GNU General Public License. +# ---------------------------------------------------------------------- + +use strict; +use warnings; +use integer; + +my $trailer_magic = 'RPTL'; + +my $tmpfile1 = "/tmp/mkknlimg_$$.1"; +my $tmpfile2 = "/tmp/mkknlimg_$$.2"; + +my $dtok = 0; +my $is_283x = 0; + +while (@ARGV && ($ARGV[0] =~ /^-/)) +{ + my $arg = shift(@ARGV); + if ($arg eq '--dtok') + { + $dtok = 1; + } + elsif ($arg eq '--283x') + { + $is_283x = 1; + } + else + { + print ("* Unknown option '$arg'\n"); + usage(); + } +} + +usage() if (@ARGV != 2); + +my $kernel_file = $ARGV[0]; +my $out_file = $ARGV[1]; + +if (! -r $kernel_file) +{ + print ("* File '$kernel_file' not found\n"); + usage(); +} + +my @wanted_strings = +( + 'bcm2708_fb', + 'brcm,bcm2835-mmc', + 'brcm,bcm2835-sdhost', + 'brcm,bcm2708-pinctrl', + 'brcm,bcm2835-gpio', + 'brcm,bcm2835', + 'brcm,bcm2836' +); + +my $res = try_extract($kernel_file, $tmpfile1); +$res = try_decompress('\037\213\010', 'xy', 'gunzip', 0, + $kernel_file, $tmpfile1, $tmpfile2) if (!$res); +$res = try_decompress('\3757zXZ\000', 'abcde', 'unxz --single-stream', -1, + $kernel_file, $tmpfile1, $tmpfile2) if (!$res); +$res = try_decompress('BZh', 'xy', 'bunzip2', 0, + $kernel_file, $tmpfile1, $tmpfile2) if (!$res); +$res = try_decompress('\135\0\0\0', 'xxx', 'unlzma', 0, + $kernel_file, $tmpfile1, $tmpfile2) if (!$res); +$res = try_decompress('\211\114\132', 'xy', 'lzop -d', 0, + $kernel_file, $tmpfile1, $tmpfile2) if (!$res); +$res = try_decompress('\002\041\114\030', 'xy', 'lz4 -d', 1, + $kernel_file, $tmpfile1, $tmpfile2) if (!$res); + +my $append_trailer; +my $trailer; +my $kver = '?'; + +$append_trailer = $dtok; + +if ($res) +{ + $kver = $res->{''} || '?'; + print("Version: $kver\n"); + + $append_trailer = $dtok; + if (!$dtok) + { + if (config_bool($res, 'bcm2708_fb') || + config_bool($res, 'brcm,bcm2835-mmc') || + config_bool($res, 'brcm,bcm2835-sdhost')) + { + $dtok ||= config_bool($res, 'brcm,bcm2708-pinctrl'); + $dtok ||= config_bool($res, 'brcm,bcm2835-gpio'); + $is_283x ||= config_bool($res, 'brcm,bcm2835'); + $is_283x ||= config_bool($res, 'brcm,bcm2836'); + $dtok ||= $is_283x; + $append_trailer = 1; + } + else + { + print ("* This doesn't look like a Raspberry Pi kernel. In pass-through mode.\n"); + } + } +} +elsif (!$dtok) +{ + print ("* Is this a valid kernel? In pass-through mode.\n"); +} + +if ($append_trailer) +{ + printf("DT: %s\n", $dtok ? "y" : "n"); + printf("283x: %s\n", $is_283x ? "y" : "n"); + + my @atoms; + + push @atoms, [ $trailer_magic, pack('V', 0) ]; + push @atoms, [ 'KVer', $kver ]; + push @atoms, [ 'DTOK', pack('V', $dtok) ]; + push @atoms, [ '283x', pack('V', $is_283x) ]; + + $trailer = pack_trailer(\@atoms); + $atoms[0]->[1] = pack('V', length($trailer)); + + $trailer = pack_trailer(\@atoms); +} + +my $ofh; +my $total_len = 0; + +if ($out_file eq $kernel_file) +{ + die "* Failed to open '$out_file' for append\n" + if (!open($ofh, '>>', $out_file)); + $total_len = tell($ofh); +} +else +{ + die "* Failed to open '$kernel_file'\n" + if (!open(my $ifh, '<', $kernel_file)); + die "* Failed to create '$out_file'\n" + if (!open($ofh, '>', $out_file)); + + my $copybuf; + while (1) + { + my $bytes = sysread($ifh, $copybuf, 64*1024); + last if (!$bytes); + syswrite($ofh, $copybuf, $bytes); + $total_len += $bytes; + } + close($ifh); +} + +if ($trailer) +{ + # Pad to word-alignment + syswrite($ofh, "\x000\x000\x000", (-$total_len & 0x3)); + syswrite($ofh, $trailer); +} + +close($ofh); + +exit($trailer ? 0 : 1); + +END { + unlink($tmpfile1) if ($tmpfile1); + unlink($tmpfile2) if ($tmpfile2); +} + + +sub usage +{ + print ("Usage: mkknlimg [--dtok] [--283x] \n"); + exit(1); +} + +sub try_extract +{ + my ($knl, $tmp) = @_; + + my $ver = `strings "$knl" | grep -a -E "^Linux version [1-9]"`; + + return undef if (!$ver); + + chomp($ver); + + my $res = { ''=>$ver }; + my $string_pattern = '^('.join('|', @wanted_strings).')$'; + + my @matches = `strings \"$knl\" | grep -E \"$string_pattern\"`; + foreach my $match (@matches) + { + chomp($match); + $res->{$match} = 1; + } + + return $res; +} + + +sub try_decompress +{ + my ($magic, $subst, $zcat, $idx, $knl, $tmp1, $tmp2) = @_; + + my $pos = `tr "$magic\n$subst" "\n$subst=" < "$knl" | grep -abo "^$subst"`; + if ($pos) + { + chomp($pos); + $pos = (split(/[\r\n]+/, $pos))[$idx]; + return undef if (!defined($pos)); + $pos =~ s/:.*[\r\n]*$//s; + my $cmd = "tail -c+$pos \"$knl\" | $zcat > $tmp2 2> /dev/null"; + my $err = (system($cmd) >> 8); + return undef if (($err != 0) && ($err != 2)); + + return try_extract($tmp2, $tmp1); + } + + return undef; +} + +sub pack_trailer +{ + my ($atoms) = @_; + my $trailer = pack('VV', 0, 0); + for (my $i = $#$atoms; $i>=0; $i--) + { + my $atom = $atoms->[$i]; + $trailer .= pack('a*x!4Va4', $atom->[1], length($atom->[1]), $atom->[0]); + } + return $trailer; +} + +sub config_bool +{ + my ($configs, $wanted) = @_; + my $val = $configs->{$wanted} || 'n'; + return (($val eq 'y') || ($val eq '1')); +} diff --git a/live-build/ubuntu-cpc/includes.chroot/etc/hostname b/live-build/ubuntu-cpc/includes.chroot/etc/hostname new file mode 100644 index 00000000..e9e5f7ce --- /dev/null +++ b/live-build/ubuntu-cpc/includes.chroot/etc/hostname @@ -0,0 +1 @@ +ubuntu diff --git a/live-build/ubuntu-cpc/includes.chroot/etc/hosts b/live-build/ubuntu-cpc/includes.chroot/etc/hosts new file mode 100644 index 00000000..56e7c15b --- /dev/null +++ b/live-build/ubuntu-cpc/includes.chroot/etc/hosts @@ -0,0 +1,9 @@ +127.0.0.1 localhost + +# The following lines are desirable for IPv6 capable hosts +::1 ip6-localhost ip6-loopback +fe00::0 ip6-localnet +ff00::0 ip6-mcastprefix +ff02::1 ip6-allnodes +ff02::2 ip6-allrouters +ff02::3 ip6-allhosts diff --git a/live-build/ubuntu-cpc/includes.chroot/etc/network/interfaces b/live-build/ubuntu-cpc/includes.chroot/etc/network/interfaces new file mode 100644 index 00000000..a3e1bad7 --- /dev/null +++ b/live-build/ubuntu-cpc/includes.chroot/etc/network/interfaces @@ -0,0 +1,15 @@ +# This file describes the network interfaces available on your system +# and how to activate them. For more information, see interfaces(5). + +# The loopback network interface +auto lo +iface lo inet loopback + +# Source interfaces +# Please check /etc/network/interfaces.d before changing this file +# as interfaces may have been defined in /etc/network/interfaces.d +# NOTE: the primary ethernet device is defined in +# /etc/network/interfaces.d/eth0 +# See LP: #1262951 +source /etc/network/interfaces.d/*.cfg + diff --git a/live-build/ubuntu-cpc/includes.chroot/etc/network/interfaces.d/eth0.cfg b/live-build/ubuntu-cpc/includes.chroot/etc/network/interfaces.d/eth0.cfg new file mode 100644 index 00000000..d117f4b2 --- /dev/null +++ b/live-build/ubuntu-cpc/includes.chroot/etc/network/interfaces.d/eth0.cfg @@ -0,0 +1,3 @@ +# The primary network interface +auto eth0 +iface eth0 inet dhcp