#!/bin/bash -eux . /build/config/functions BOOTPART_START= BOOTPART_END= BOOT_MOUNTPOINT= ROOTPART_START=1 case $ARCH in ppc64el) echo "ppc64el disk images are handled separately" exit 0 ;; *) ;; 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 bootable="$5" parted_prefix="parted $disk --script --" ${parted_prefix} mkpart primary "$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" 1 "$ROOT_BOOTABLE" fi create_empty_partition "${disk_image}" "$ROOTPART" "$ROOTPART_START" -1 $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 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 [ "$ARCH" = "s390x" ]; then # Do ZIPL install bits # 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 # Create bootmap file mountpoint/sbin/zipl -V \ --image=mountpoint/boot/vmlinuz \ --ramdisk=mountpoint/boot/initrd.img \ --parameters='root=LABEL=cloudimg-rootfs' \ --target=mountpoint/boot/ \ --targetbase=/dev/loop0 \ --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