You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
186 lines
4.5 KiB
186 lines
4.5 KiB
9 years ago
|
#!/bin/bash -ex
|
||
9 years ago
|
|
||
8 years ago
|
IMAGE_STR="# CLOUD_IMG: This file was created/modified by the Cloud Image build process"
|
||
|
FS_LABEL="cloudimg-rootfs"
|
||
|
|
||
7 years ago
|
. config/binary
|
||
7 years ago
|
|
||
7 years ago
|
. config/functions
|
||
|
|
||
9 years ago
|
BOOTPART_START=
|
||
|
BOOTPART_END=
|
||
|
BOOT_MOUNTPOINT=
|
||
9 years ago
|
ROOTPART_START=1
|
||
9 years ago
|
|
||
6 years ago
|
my_d=$(dirname $(readlink -f ${0}))
|
||
|
|
||
9 years ago
|
case $ARCH:$SUBARCH in
|
||
9 years ago
|
ppc64el:*|powerpc:*)
|
||
|
echo "POWER disk images are handled separately"
|
||
9 years ago
|
exit 0
|
||
|
;;
|
||
7 years ago
|
amd64|arm64|armhf)
|
||
9 years ago
|
echo "We only create EFI images for $ARCH."
|
||
|
exit 0
|
||
|
;;
|
||
9 years ago
|
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
|
||
|
;;
|
||
9 years ago
|
*)
|
||
|
;;
|
||
9 years ago
|
esac
|
||
9 years ago
|
|
||
9 years ago
|
create_empty_partition_table() {
|
||
|
parted "$1" --script -- mklabel msdos
|
||
|
}
|
||
|
|
||
|
create_empty_partition() {
|
||
|
local disk="$1"
|
||
|
local part="$2"
|
||
|
local start="$3"
|
||
|
local end="$4"
|
||
9 years ago
|
local type="$5"
|
||
|
local bootable="$6"
|
||
9 years ago
|
|
||
|
parted_prefix="parted $disk --script --"
|
||
9 years ago
|
${parted_prefix} mkpart primary "$type" "$start" "$end"
|
||
9 years ago
|
if [ -n "$bootable" ]; then
|
||
|
${parted_prefix} set "$part" B
|
||
|
fi
|
||
9 years ago
|
${parted_prefix} print
|
||
9 years ago
|
${parted_prefix} align-check opt "$part"
|
||
9 years ago
|
}
|
||
|
|
||
|
disk_image=binary/boot/disk.ext4
|
||
|
|
||
|
create_empty_disk_image "${disk_image}"
|
||
9 years ago
|
create_empty_partition_table "${disk_image}"
|
||
9 years ago
|
|
||
|
ROOTPART=1
|
||
9 years ago
|
ROOT_BOOTABLE=1
|
||
9 years ago
|
if [ -n "$BOOTPART_START" ]; then
|
||
9 years ago
|
ROOTPART=2
|
||
|
ROOTPART_START="$BOOTPART_END"
|
||
9 years ago
|
ROOT_BOOTABLE=
|
||
9 years ago
|
create_empty_partition "$disk_image" 1 "$BOOTPART_START" "$BOOTPART_END" fat32 1
|
||
9 years ago
|
fi
|
||
9 years ago
|
create_empty_partition "${disk_image}" "$ROOTPART" "$ROOTPART_START" -1 ext2 "$ROOT_BOOTABLE"
|
||
9 years ago
|
|
||
9 years ago
|
mount_image "${disk_image}" "$ROOTPART"
|
||
9 years ago
|
|
||
7 years ago
|
partuuid=$(blkid -s PARTUUID -o value "$rootfs_dev_mapper")
|
||
|
|
||
9 years ago
|
# Copy the chroot in to the disk
|
||
|
make_ext4_partition "${rootfs_dev_mapper}"
|
||
|
mkdir mountpoint
|
||
|
mount "${rootfs_dev_mapper}" mountpoint
|
||
9 years ago
|
|
||
|
if [ -n "$BOOT_MOUNTPOINT" ]; then
|
||
9 years ago
|
boot_dev_mapper="${rootfs_dev_mapper%%[0-9]}1"
|
||
9 years ago
|
# 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
|
||
|
|
||
9 years ago
|
cp -a chroot/* mountpoint/
|
||
|
|
||
9 years ago
|
setup_mountpoint mountpoint
|
||
|
|
||
9 years ago
|
case $ARCH:$SUBARCH in
|
||
|
armhf:raspi2)
|
||
|
chroot mountpoint flash-kernel \
|
||
|
--machine "Raspberry Pi 2 Model B"
|
||
9 years ago
|
# not the best place for this, but neither flash-kernel nor
|
||
|
# u-boot have provisions for installing u-boot via maintainer
|
||
|
# script
|
||
6 years ago
|
${my_d}/raspi2/mkknlimg --dtok \
|
||
9 years ago
|
mountpoint/usr/lib/u-boot/rpi_2/u-boot.bin \
|
||
|
mountpoint/boot/firmware/uboot.bin
|
||
9 years ago
|
;;
|
||
|
*) ;;
|
||
|
esac
|
||
|
|
||
9 years ago
|
case $ARCH in
|
||
9 years ago
|
amd64|i386) should_install_grub=1;;
|
||
|
*) should_install_grub=0;;
|
||
|
esac
|
||
9 years ago
|
|
||
9 years ago
|
if [ "${should_install_grub}" -eq 1 ]; then
|
||
9 years ago
|
echo "(hd0) ${loop_device}" > mountpoint/tmp/device.map
|
||
|
chroot mountpoint grub-install ${loop_device}
|
||
9 years ago
|
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}
|
||
9 years ago
|
|
||
|
rm mountpoint/tmp/device.map
|
||
7 years ago
|
|
||
6 years ago
|
if [ -n "$partuuid" ]; then
|
||
7 years ago
|
echo "partuuid found for root device; forcing it in Grub"
|
||
7 years ago
|
mkdir -p mountpoint/etc/default/grub.d
|
||
7 years ago
|
echo "GRUB_FORCE_PARTUUID=$partuuid" >> mountpoint/etc/default/grub.d/40-force-partuuid.cfg
|
||
7 years ago
|
divert_grub mountpoint
|
||
7 years ago
|
chroot mountpoint update-grub
|
||
7 years ago
|
undivert_grub mountpoint
|
||
7 years ago
|
fi
|
||
9 years ago
|
fi
|
||
|
|
||
9 years ago
|
if [ "$ARCH" = "s390x" ]; then
|
||
9 years ago
|
# Do ZIPL install bits
|
||
9 years ago
|
chroot mountpoint apt-get -qqy install s390-tools sysconfig-hardware
|
||
9 years ago
|
|
||
|
# 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
|
||
|
parameters = root=LABEL=cloudimg-rootfs
|
||
|
EOF
|
||
|
|
||
7 years ago
|
ZIPL_EXTRA_PARAMS=
|
||
|
if [ -e mountpoint/boot/initrd.img-* ]; then
|
||
|
# Kernel initramfs hooks end up creating a copy
|
||
|
# rather than a symlink FIXME
|
||
|
pushd mountpoint/boot
|
||
|
ln -sf initrd.img-* initrd.img
|
||
|
popd
|
||
|
|
||
|
echo "ramdisk = /boot/initrd.img" >> mountpoint/etc/zipl.conf
|
||
7 years ago
|
|
||
|
ZIPL_EXTRA_PARAMS=--ramdisk=/boot/initrd.img
|
||
7 years ago
|
fi
|
||
|
|
||
9 years ago
|
# Create bootmap file
|
||
9 years ago
|
chroot mountpoint /sbin/zipl -V \
|
||
|
--image=/boot/vmlinuz \
|
||
9 years ago
|
--parameters='root=LABEL=cloudimg-rootfs' \
|
||
9 years ago
|
--target=/boot/ \
|
||
9 years ago
|
--targetbase=$loop_device \
|
||
9 years ago
|
--targettype=SCSI \
|
||
|
--targetblocksize=512 \
|
||
7 years ago
|
--targetoffset=2048 \
|
||
|
$ZIPL_EXTRA_PARAMS
|
||
9 years ago
|
fi
|
||
|
|
||
9 years ago
|
if [ -n "$BOOT_MOUNTPOINT" ]; then
|
||
|
umount "mountpoint/$BOOT_MOUNTPOINT"
|
||
|
fi
|
||
|
|
||
9 years ago
|
umount_partition mountpoint
|
||
|
rmdir mountpoint
|
||
|
|
||
9 years ago
|
clean_loops
|
||
|
trap - EXIT
|