#!/bin/bash -eux # vi: ts=4 noexpandtab # # Generate a squashfs root and manifest echo "033-kernel-bits.binary" case ${IMAGE_TARGETS-} in ""|*squashfs*) ;; *) echo "Skipping squashfs build" exit 0 ;; esac if [ -n "${SUBARCH-}" && "$SUBARCH" != "intel-iot" ]; then echo "Skipping rootfs build for subarch flavor build" exit 0 fi . config/functions . config/common INSTALLER_ROOT=binary/boot/installer.squashfs.dir KERNEL_BITS_ROOT=binary/boot/kernel-bits.dir KERNEL_BITS_OVERLAY=binary/boot/overlay-kernel-bits PROJECT=$PROJECT${SUBARCH:+-$SUBARCH} case ${SUBARCH-} in intel-iot) variants='intel' ;; *) variants='ga hwe' ;; esac for variant in $variants; do if [ "$variant" = "ga" ]; then kernel_metapkg=linux-generic flavor=generic elif [ "$variant" = "hwe" ]; then kernel_metapkg=linux-generic-hwe-$(lsb_release -sr) flavor=generic-hwe elif [ "$variant" = "intel" ]; then kernel_metapkg=linux-intel-iotg-edge flavor=intel-iotg else echo "bogus variant: $variant" exit 1 fi # Make preparations mkdir -p $KERNEL_BITS_ROOT $KERNEL_BITS_OVERLAY mount_overlay "$INSTALLER_ROOT/" "$KERNEL_BITS_OVERLAY/" "$KERNEL_BITS_ROOT/" setup_mountpoint $KERNEL_BITS_ROOT # Our initramfs hook implements a kind of extreme version of # cloud-initramfs-copymods, so remove that and prevent duelling hooks env DEBIAN_FRONTEND=noninteractive chroot $KERNEL_BITS_ROOT apt-get -y remove cloud-initramfs-copymods ubuntu-server || true # Configure initramfs creation mkdir -p "$KERNEL_BITS_ROOT"/etc/initramfs-tools/conf.d/ if [ -n "$LB_INITRAMFS_COMPRESSION" ]; then echo "COMPRESS=$LB_INITRAMFS_COMPRESSION" > "$KERNEL_BITS_ROOT"/etc/initramfs-tools/conf.d/livecd-rootfs.conf fi echo "export CASPER_GENERATE_UUID=1" > "$KERNEL_BITS_ROOT"/etc/initramfs-tools/conf.d/casper.conf # Add a hook to record which kernel was booted and mount the # modules.squashfs created below. cat < "$KERNEL_BITS_ROOT"/etc/initramfs-tools/scripts/init-bottom/live-server #!/bin/sh case \$1 in prereqs) exit 0;; esac echo ${kernel_metapkg} > /run/kernel-meta-package mkdir -p \$rootmnt/usr/lib/modules mount \$rootmnt/cdrom/casper/extras/modules.squashfs-$flavor \$rootmnt/usr/lib/modules mkdir -p /run/systemd/system/usr-lib-modules.mount.d echo '[Mount]' >> /run/systemd/system/usr-lib-modules.mount.d/lazy.conf echo 'LazyUnmount=yes' >> /run/systemd/system/usr-lib-modules.mount.d/lazy.conf EOF chmod +x "$KERNEL_BITS_ROOT"/etc/initramfs-tools/scripts/init-bottom/live-server # Install the kernel! env DEBIAN_FRONTEND=noninteractive chroot $KERNEL_BITS_ROOT apt-get -y install ${kernel_metapkg} # Fish out generated kernel image and initrd mv "$KERNEL_BITS_ROOT"/boot/initrd.img-* ${PWD}/livecd.${PROJECT}.initrd-$flavor mv "$KERNEL_BITS_ROOT"/boot/vmlinu?-* ${PWD}/livecd.${PROJECT}.kernel-$flavor # Create squashfs containing all the modules modules_squashfs_path="${PWD}/livecd.${PROJECT}.modules.squashfs-$flavor" (cd "$KERNEL_BITS_ROOT/lib/modules" && mksquashfs . $modules_squashfs_path -no-progress -xattrs -comp xz) # And clean up teardown_mountpoint $KERNEL_BITS_ROOT umount $KERNEL_BITS_ROOT rm -rf $KERNEL_BITS_ROOT $KERNEL_BITS_OVERLAY done