livecd-rootfs/live-build/ubuntu-cpc/hooks/032-disk-image.binary
Dimitri John Ledkov 8cc7060c24 Import patches-unapplied version 2.408.20 to ubuntu/xenial-proposed
Imported using git-ubuntu import.

Changelog parent: d59199fe59fa2649ca5dccd2bc03df6de64d7274

New changelog entries:
  * Now that grub-related diversions have been factored out in 2.466
    instead of having bogus root=stuff arg generated in grub.cfg, it is
    actually empty. Therefore update the sed command to make the arg in
    the root= token optional. This should resolve non-booting livecd cpc
    images.
  [ Nishanth Aravamudan ]
  * live-build/ubuntu-cpc/hooks/061-open-iscsi.chroot: generate iSCSI
    Initiator Name at first iscsid run for cloud images to ensure it is
    unique (LP: #1444992).
  [ Steve Langasek ]
  * Improve teardown_mountpoint to recursively find all submounts and
    unmount them, instead of working from a hard-coded list.  This makes
    the code resilient against other submounts being added later, including
    downstream.  LP: #1721279.
  * Also nuke the sleep / udevadm settle calls in the process, which should
    never be required and slow down the builds.
  * Fix a reference to an undefined variable in a script that's set -u.
  * Use /bin/sh, not /bin/bash, for autopkgtest.
  * debian/tests/default-bootstraps: minor adjustments to shell syntax,
    syncing with artful where this originated.
  [ Steve Langasek, Balint Reczey ]
  * Introduce a new project-independent 'minimized' subproject
    (LP: #1721261):
    - omit ubuntu-minimal in favor of using only the minbase package set.
    - boot directly by partuuid, avoiding the use of an initramfs.
    - Bump needed live-build version which can build images without initrd
    - drop man pages and most of the documentation from minimized images
      (/usr/share/doc/*/copyright and changelog.Debian.gz files are still
      kept)
    - Add unminimize script for reverting minimization on a running system
    - Mention unminimize script in motd
    - Run autopkgtest for SUBPROJECT=minimized
    - If we're using SUBPROJECT=minimized, and tzdata is not installed,
      remove files that have been left behind.  This is a workaround for a
      bug that should be fixed in tzdata.
  * Factor out grub-related diversions and use them consistently, so we
    don't end up with wrong os-probe output in our grub.cfg.
  [ Balint Reczey ]
  * Mount using --make-rslave to ensure safe unmounts for rbind mounts
  * When SUBPROJECT environment variable is not set assume it to be ""
2017-10-19 23:03:14 +00:00

174 lines
4.1 KiB
Bash
Executable File

#!/bin/bash -ex
. config/functions
. config/binary
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"
partuuid=$(blkid -s PARTUUID -o value "$rootfs_dev_mapper")
# 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
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
if [ "${SUBPROJECT:-}" = minimized ] && [ -n "$partuuid" ]; then
echo "partuuid found for root device; forcing it in Grub"
mkdir -p mountpoint/etc/default/grub.d
echo "GRUB_FORCE_PARTUUID=$partuuid" >> mountpoint/etc/default/grub.d/40-force-partuuid.cfg
divert_grub mountpoint
chroot mountpoint update-grub
undivert_grub mountpoint
fi
fi
if [ "$ARCH" = "s390x" ]; then
# Do ZIPL install bits
chroot mountpoint apt-get -qqy install s390-tools sysconfig-hardware
# Write out cloudy zipl.conf for future kernel updates
cat << EOF > mountpoint/etc/zipl.conf
# This has been modified by the cloud image build process
[defaultboot]
default=ubuntu
[ubuntu]
target = /boot
image = /boot/vmlinuz
ramdisk = /boot/initrd.img
parameters = root=LABEL=cloudimg-rootfs
EOF
# Kernel initramfs hooks end up creating a copy
# rather than a symlink FIXME
pushd mountpoint/boot
ln -sf initrd.img-* initrd.img
popd
# Create bootmap file
chroot mountpoint /sbin/zipl -V \
--image=/boot/vmlinuz \
--ramdisk=/boot/initrd.img \
--parameters='root=LABEL=cloudimg-rootfs' \
--target=/boot/ \
--targetbase=$loop_device \
--targettype=SCSI \
--targetblocksize=512 \
--targetoffset=2048
fi
if [ -n "$BOOT_MOUNTPOINT" ]; then
umount "mountpoint/$BOOT_MOUNTPOINT"
fi
umount_partition mountpoint
rmdir mountpoint
clean_loops
trap - EXIT