2013-08-11 10:17:18 +00:00
|
|
|
#!/bin/sh
|
|
|
|
#-
|
2016-04-26 13:00:55 +00:00
|
|
|
# Copyright (c) 2013-2016 Juan Romero Pardines.
|
2017-07-24 00:55:41 +00:00
|
|
|
# Copyright (c) 2017 Google
|
2013-08-11 10:17:18 +00:00
|
|
|
# All rights reserved.
|
|
|
|
#
|
|
|
|
# Redistribution and use in source and binary forms, with or without
|
|
|
|
# modification, are permitted provided that the following conditions
|
|
|
|
# are met:
|
|
|
|
# 1. Redistributions of source code must retain the above copyright
|
|
|
|
# notice, this list of conditions and the following disclaimer.
|
|
|
|
# 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
# notice, this list of conditions and the following disclaimer in the
|
|
|
|
# documentation and/or other materials provided with the distribution.
|
|
|
|
#
|
|
|
|
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
#-
|
|
|
|
|
2017-08-13 03:55:31 +00:00
|
|
|
readonly PROGNAME=$(basename "$0")
|
2013-08-11 10:17:18 +00:00
|
|
|
readonly ARCH=$(uname -m)
|
|
|
|
|
|
|
|
trap 'printf "\nInterrupted! exiting...\n"; cleanup; exit 0' INT TERM HUP
|
|
|
|
|
2017-08-13 03:55:31 +00:00
|
|
|
# This source pulls in all the functions from lib.sh. This set of
|
|
|
|
# functions makes it much easier to work with chroots and abstracts
|
|
|
|
# away all the problems with running binaries with QEMU.
|
|
|
|
# shellcheck source=./lib.sh
|
|
|
|
. ./lib.sh
|
2017-07-24 00:55:41 +00:00
|
|
|
|
2017-08-13 08:40:19 +00:00
|
|
|
# This script has a special cleanup() function since it needs to
|
|
|
|
# unmount the rootfs as mounted on a loop device. This function is
|
|
|
|
# defined after sourcing the library functions to ensure it is the
|
|
|
|
# last one defined.
|
2013-08-11 10:17:18 +00:00
|
|
|
cleanup() {
|
2017-08-14 00:44:51 +00:00
|
|
|
umount_pseudofs
|
2017-08-13 03:55:31 +00:00
|
|
|
umount -f "${ROOTFS}/boot" 2>/dev/null
|
|
|
|
umount -f "${ROOTFS}" 2>/dev/null
|
2014-01-22 16:15:57 -01:00
|
|
|
if [ -e "$LOOPDEV" ]; then
|
2017-08-13 03:55:31 +00:00
|
|
|
partx -d "$LOOPDEV" 2>/dev/null
|
|
|
|
losetup -d "$LOOPDEV" 2>/dev/null
|
2014-01-22 16:15:57 -01:00
|
|
|
fi
|
|
|
|
|
2017-08-13 03:55:31 +00:00
|
|
|
[ -d "$ROOTFS" ] && rmdir "$ROOTFS"
|
2013-08-11 10:17:18 +00:00
|
|
|
}
|
|
|
|
|
2017-08-13 08:40:19 +00:00
|
|
|
|
|
|
|
# This script is designed to take in a complete platformfs and spit
|
|
|
|
# out an image that is suitable for writing with dd. The image is
|
|
|
|
# configurable in terms of the filesystem layout, but not in terms of
|
|
|
|
# the installed system itself. Customization to the installed system
|
|
|
|
# should be made during the mkplatformfs step.
|
2013-08-11 10:17:18 +00:00
|
|
|
usage() {
|
2014-01-28 15:04:15 -01:00
|
|
|
cat <<_EOF
|
|
|
|
Usage: $PROGNAME [options] <rootfs-tarball>
|
|
|
|
|
|
|
|
The <rootfs-tarball> argument expects a tarball generated by void-mkrootfs.
|
|
|
|
The platform is guessed automatically by its name.
|
|
|
|
|
2016-04-26 13:00:55 +00:00
|
|
|
Accepted sizes suffixes: KiB, MiB, GiB, TiB, EiB.
|
2014-01-28 15:04:15 -01:00
|
|
|
|
|
|
|
OPTIONS
|
|
|
|
-b <fstype> Set /boot filesystem type (defaults to FAT)
|
2016-04-26 13:00:55 +00:00
|
|
|
-B <bsize> Set /boot filesystem size (defaults to 64MiB)
|
2014-01-28 15:04:15 -01:00
|
|
|
-r <fstype> Set / filesystem type (defaults to EXT4)
|
|
|
|
-s <totalsize> Set total image size (defaults to 2GB)
|
|
|
|
-o <output> Set image filename (guessed automatically)
|
2017-08-21 07:04:17 +00:00
|
|
|
-x <num> Use <num> threads to compress the image (dynamic if unset)
|
2014-01-28 15:04:15 -01:00
|
|
|
-h Show this help
|
|
|
|
-V Show version
|
|
|
|
|
|
|
|
Resulting image will have 2 partitions, /boot and /.
|
|
|
|
_EOF
|
2013-08-11 10:17:18 +00:00
|
|
|
exit 0
|
|
|
|
}
|
|
|
|
|
2017-08-13 03:55:31 +00:00
|
|
|
# ########################################
|
|
|
|
# SCRIPT EXECUTION STARTS HERE
|
|
|
|
# ########################################
|
|
|
|
|
2017-08-21 07:04:17 +00:00
|
|
|
while getopts "b:B:o:r:s:x:h:V" opt; do
|
2013-08-11 10:17:18 +00:00
|
|
|
case $opt in
|
|
|
|
b) BOOT_FSTYPE="$OPTARG";;
|
2014-01-28 15:04:15 -01:00
|
|
|
B) BOOT_FSSIZE="$OPTARG";;
|
2013-08-11 10:17:18 +00:00
|
|
|
o) FILENAME="$OPTARG";;
|
|
|
|
r) ROOT_FSTYPE="$OPTARG";;
|
2014-01-28 15:04:15 -01:00
|
|
|
s) IMGSIZE="$OPTARG";;
|
2017-08-21 07:04:17 +00:00
|
|
|
x) COMPRESSOR_THREADS="$OPTARG" ;;
|
2013-08-11 10:17:18 +00:00
|
|
|
V) echo "$PROGNAME @@MKLIVE_VERSION@@"; exit 0;;
|
|
|
|
h) usage;;
|
|
|
|
esac
|
|
|
|
done
|
2017-08-13 03:55:31 +00:00
|
|
|
shift $((OPTIND - 1))
|
2013-08-11 10:17:18 +00:00
|
|
|
ROOTFS_TARBALL="$1"
|
2017-08-13 03:55:31 +00:00
|
|
|
|
2013-08-11 10:17:18 +00:00
|
|
|
if [ -z "$ROOTFS_TARBALL" ]; then
|
|
|
|
usage
|
|
|
|
elif [ ! -r "$ROOTFS_TARBALL" ]; then
|
2017-08-13 03:55:31 +00:00
|
|
|
# In rare cases the tarball can wind up owned by the wrong user.
|
|
|
|
# This leads to confusing failures if execution is allowed to
|
|
|
|
# proceed.
|
2013-08-11 10:17:18 +00:00
|
|
|
die "Cannot read rootfs tarball: $ROOTFS_TARBALL"
|
|
|
|
fi
|
|
|
|
|
2017-08-13 03:55:31 +00:00
|
|
|
# By default we build all platform images with a 64MiB boot partition
|
2017-08-13 08:40:19 +00:00
|
|
|
# formated FAT16, and an approximately 1.9GiB root partition formated
|
2017-08-13 03:55:31 +00:00
|
|
|
# ext4. More exotic combinations are of course possible, but this
|
|
|
|
# combination works on all known platforms.
|
|
|
|
: "${IMGSIZE:=2G}"
|
|
|
|
: "${BOOT_FSTYPE:=vfat}"
|
|
|
|
: "${BOOT_FSSIZE:=64MiB}"
|
|
|
|
: "${ROOT_FSTYPE:=ext4}"
|
|
|
|
|
|
|
|
# Verify that the required tooling is available
|
|
|
|
readonly REQTOOLS="sfdisk partx losetup mount truncate mkfs.${BOOT_FSTYPE} mkfs.${ROOT_FSTYPE}"
|
|
|
|
check_tools
|
|
|
|
|
|
|
|
# Setup the platform variable. Here we want just the name and
|
|
|
|
# optionally -musl if this is the musl variant.
|
2014-01-28 15:04:15 -01:00
|
|
|
PLATFORM="${ROOTFS_TARBALL#void-}"
|
2017-08-19 04:13:48 +00:00
|
|
|
PLATFORM="${PLATFORM%-PLATFORMFS*}"
|
2014-01-28 15:04:15 -01:00
|
|
|
|
2017-08-13 08:40:19 +00:00
|
|
|
# This is an awful hack since the script isn't using privesc
|
2017-08-13 03:55:31 +00:00
|
|
|
# mechanisms selectively. This is a TODO item.
|
2013-08-11 10:17:18 +00:00
|
|
|
if [ "$(id -u)" -ne 0 ]; then
|
|
|
|
die "need root perms to continue, exiting."
|
|
|
|
fi
|
|
|
|
|
2017-08-13 03:55:31 +00:00
|
|
|
# Set the default filename if none was provided above. The default
|
|
|
|
# will include the platform the image is being built for and the date
|
|
|
|
# on which it was built.
|
2013-08-11 10:17:18 +00:00
|
|
|
if [ -z "$FILENAME" ]; then
|
2014-01-28 15:04:15 -01:00
|
|
|
FILENAME="void-${PLATFORM}-$(date +%Y%m%d).img"
|
2013-08-11 10:17:18 +00:00
|
|
|
fi
|
|
|
|
|
2017-08-13 03:55:31 +00:00
|
|
|
# Be absolutely certain the platform is supported before continuing
|
2014-01-26 18:32:54 -01:00
|
|
|
case "$PLATFORM" in
|
2017-07-24 00:55:41 +00:00
|
|
|
bananapi|beaglebone|cubieboard2|cubietruck|odroid-c2|odroid-u2|rpi|rpi2|rpi3|usbarmory|GCP|*-musl);;
|
2014-01-28 15:04:15 -01:00
|
|
|
*) die "The $PLATFORM is not supported, exiting..."
|
2014-01-26 18:32:54 -01:00
|
|
|
esac
|
|
|
|
|
2017-08-13 03:55:31 +00:00
|
|
|
# Create the base image. This was previously accomplished with dd,
|
|
|
|
# but truncate is markedly faster.
|
2013-08-11 10:17:18 +00:00
|
|
|
info_msg "Creating disk image ($IMGSIZE) ..."
|
2017-08-13 03:55:31 +00:00
|
|
|
truncate -s "${IMGSIZE}" "$FILENAME" >/dev/null 2>&1
|
|
|
|
|
|
|
|
# Grab a tmpdir for the rootfs. If this fails we need to halt now
|
|
|
|
# because otherwise things will go very badly for the host system.
|
|
|
|
ROOTFS=$(mktemp -d) || die "Could not create tmpdir for ROOTFS"
|
2013-08-11 10:17:18 +00:00
|
|
|
|
|
|
|
info_msg "Creating disk image partitions/filesystems ..."
|
|
|
|
if [ "$BOOT_FSTYPE" = "vfat" ]; then
|
2017-08-13 08:40:19 +00:00
|
|
|
# The mkfs.vfat program tries to make some "intelligent" choices
|
|
|
|
# about the type of filesystem it creates. Instead we set options
|
|
|
|
# if the type is vfat to ensure that the same options will be used
|
|
|
|
# every time.
|
2014-12-05 09:06:39 -01:00
|
|
|
_args="-I -F16"
|
2013-08-11 10:17:18 +00:00
|
|
|
fi
|
2017-08-13 03:55:31 +00:00
|
|
|
|
2015-05-21 10:12:17 +00:00
|
|
|
case "$PLATFORM" in
|
2017-08-13 03:55:31 +00:00
|
|
|
cubieboard2|cubietruck|ci20*|odroid-c2*)
|
2017-08-13 08:40:19 +00:00
|
|
|
# These platforms use a single partition for the entire filesystem.
|
2017-08-13 03:55:31 +00:00
|
|
|
sfdisk "${FILENAME}" <<_EOF
|
2016-04-29 12:17:49 +00:00
|
|
|
label: dos
|
2016-04-26 13:00:55 +00:00
|
|
|
2048,,L
|
|
|
|
_EOF
|
2017-08-13 03:55:31 +00:00
|
|
|
LOOPDEV=$(losetup --show --find --partscan "$FILENAME")
|
|
|
|
mkfs.${ROOT_FSTYPE} -O '^64bit,^extra_isize,^has_journal' "${LOOPDEV}p1" >/dev/null 2>&1
|
|
|
|
mount "${LOOPDEV}p1" "$ROOTFS"
|
|
|
|
ROOT_UUID=$(blkid -o value -s UUID "${LOOPDEV}p1")
|
|
|
|
;;
|
|
|
|
*)
|
2017-08-13 08:40:19 +00:00
|
|
|
# These platforms use a partition layout with a small boot
|
|
|
|
# partition (64M by default) and the rest of the space as the
|
|
|
|
# root filesystem. This is the generally preferred disk
|
|
|
|
# layout for new platforms.
|
2017-08-13 03:55:31 +00:00
|
|
|
sfdisk "${FILENAME}" <<_EOF
|
2016-04-29 12:17:49 +00:00
|
|
|
label: dos
|
2016-08-10 05:40:35 +00:00
|
|
|
2048,${BOOT_FSSIZE},b,*
|
2016-11-29 20:57:25 -01:00
|
|
|
,+,L
|
2016-04-26 13:00:55 +00:00
|
|
|
_EOF
|
2017-08-13 03:55:31 +00:00
|
|
|
LOOPDEV=$(losetup --show --find --partscan "$FILENAME")
|
|
|
|
# Normally we need to quote to prevent argument splitting, but
|
|
|
|
# we explicitly want argument splitting here.
|
|
|
|
# shellcheck disable=SC2086
|
|
|
|
mkfs.${BOOT_FSTYPE} $_args "${LOOPDEV}p1" >/dev/null
|
|
|
|
case "$ROOT_FSTYPE" in
|
2017-08-13 08:40:19 +00:00
|
|
|
# Because the images produced by this script are generally
|
|
|
|
# either on single board computers using flash memory or
|
|
|
|
# in cloud environments that already provide disk
|
|
|
|
# durability, we shut off the journal for ext filesystems.
|
|
|
|
# For flash memory this greatly extends the life of the
|
|
|
|
# memory and for cloud images this lowers the overhead by
|
|
|
|
# a small amount.
|
2017-08-13 03:55:31 +00:00
|
|
|
ext[34]) disable_journal="-O ^has_journal";;
|
|
|
|
esac
|
|
|
|
mkfs.${ROOT_FSTYPE} "$disable_journal" "${LOOPDEV}p2" >/dev/null 2>&1
|
|
|
|
mount "${LOOPDEV}p2" "$ROOTFS"
|
|
|
|
mkdir -p "${ROOTFS}/boot"
|
|
|
|
mount "${LOOPDEV}p1" "${ROOTFS}/boot"
|
|
|
|
BOOT_UUID=$(blkid -o value -s UUID "${LOOPDEV}p1")
|
|
|
|
ROOT_UUID=$(blkid -o value -s UUID "${LOOPDEV}p2")
|
|
|
|
;;
|
2014-11-29 16:16:50 -01:00
|
|
|
esac
|
2013-08-11 10:17:18 +00:00
|
|
|
|
2017-08-13 08:40:19 +00:00
|
|
|
# This step unpacks the platformfs tarball made by mkplatformfs.sh.
|
2014-12-05 03:46:05 -01:00
|
|
|
info_msg "Unpacking rootfs tarball ..."
|
2014-12-05 09:06:39 -01:00
|
|
|
if [ "$PLATFORM" = "beaglebone" ]; then
|
2017-08-13 08:40:19 +00:00
|
|
|
# The beaglebone requires some special extra handling. The MLO
|
|
|
|
# program is a special first stage boot loader that brings up
|
|
|
|
# enough of the processor to then load u-boot which loads the rest
|
|
|
|
# of the system. The noauto option also prevents /boot from being
|
|
|
|
# mounted during system startup.
|
2014-12-05 09:06:39 -01:00
|
|
|
fstab_args=",noauto"
|
2017-08-13 03:55:31 +00:00
|
|
|
tar xfp "$ROOTFS_TARBALL" -C "$ROOTFS" ./boot/MLO
|
|
|
|
tar xfp "$ROOTFS_TARBALL" -C "$ROOTFS" ./boot/u-boot.img
|
|
|
|
touch "$ROOTFS/boot/uEnv.txt"
|
|
|
|
umount "$ROOTFS/boot"
|
2014-12-05 09:06:39 -01:00
|
|
|
fi
|
2017-08-13 08:40:19 +00:00
|
|
|
|
|
|
|
# In the general case, its enough to just unpack the ROOTFS_TARBALL
|
|
|
|
# onto the ROOTFS. This will get a system that is ready to boot, save
|
|
|
|
# for the bootloader which is handled later.
|
2017-08-13 03:55:31 +00:00
|
|
|
tar xfp "$ROOTFS_TARBALL" --xattrs --xattrs-include='*' -C "$ROOTFS"
|
2013-08-11 10:17:18 +00:00
|
|
|
|
2017-08-13 08:40:19 +00:00
|
|
|
# For f2fs the system should not attempt an fsck at boot. This
|
|
|
|
# filesystem is in theory self healing and does not use the standard
|
|
|
|
# mechanisms. All other filesystems should use fsck at boot.
|
2015-01-17 09:31:10 -01:00
|
|
|
fspassno="1"
|
|
|
|
if [ "$ROOT_FSTYPE" = "f2fs" ]; then
|
|
|
|
fspassno="0"
|
|
|
|
fi
|
2017-08-13 08:40:19 +00:00
|
|
|
|
|
|
|
# Void images prefer uuids to nodes in /dev since these are not
|
|
|
|
# dependent on the hardware layout. On a single board computer this
|
|
|
|
# may not matter much but it makes the cloud images easier to manage.
|
2017-08-13 03:55:31 +00:00
|
|
|
echo "UUID=$ROOT_UUID / $ROOT_FSTYPE defaults 0 ${fspassno}" >> "${ROOTFS}/etc/fstab"
|
2015-05-21 10:12:17 +00:00
|
|
|
if [ -n "$BOOT_UUID" ]; then
|
2017-08-13 03:55:31 +00:00
|
|
|
echo "UUID=$BOOT_UUID /boot $BOOT_FSTYPE defaults${fstab_args} 0 2" >> "${ROOTFS}/etc/fstab"
|
2015-05-21 10:12:17 +00:00
|
|
|
fi
|
2014-01-26 18:32:54 -01:00
|
|
|
|
2017-08-13 08:40:19 +00:00
|
|
|
# This section does final configuration on the images. In the case of
|
|
|
|
# SBCs this writes the bootloader to the image or sets up other
|
|
|
|
# required binaries to boot. In the case of images destined for a
|
|
|
|
# Cloud, this sets up the services that the cloud will expect to be
|
|
|
|
# running and a suitable bootloader. When adding a new platform,
|
|
|
|
# please add a comment explaining what the steps you are adding do,
|
|
|
|
# and where information about your specific platform's boot process
|
|
|
|
# can be found.
|
2017-08-13 03:55:31 +00:00
|
|
|
info_msg "Configuring image for platform $PLATFORM"
|
2015-05-16 18:16:32 +00:00
|
|
|
case "$PLATFORM" in
|
2016-04-26 13:47:56 +00:00
|
|
|
bananapi*|cubieboard2*|cubietruck*)
|
2017-08-13 03:55:31 +00:00
|
|
|
dd if="${ROOTFS}/boot/u-boot-sunxi-with-spl.bin" of="${LOOPDEV}" bs=1024 seek=8 >/dev/null 2>&1
|
2015-05-16 18:16:32 +00:00
|
|
|
;;
|
2016-05-06 12:41:04 +00:00
|
|
|
odroid-c2*)
|
2017-08-13 03:55:31 +00:00
|
|
|
dd if="${ROOTFS}/boot/bl1.bin.hardkernel" of="${LOOPDEV}" bs=1 count=442 >/dev/null 2>&1
|
|
|
|
dd if="${ROOTFS}/boot/bl1.bin.hardkernel" of="${LOOPDEV}" bs=512 skip=1 seek=1 >/dev/null 2>&1
|
|
|
|
dd if="${ROOTFS}/boot/u-boot.bin" of="${LOOPDEV}" bs=512 seek=97 >/dev/null 2>&1
|
2016-05-06 12:41:04 +00:00
|
|
|
;;
|
2016-04-26 13:47:56 +00:00
|
|
|
odroid-u2*)
|
2017-08-13 03:55:31 +00:00
|
|
|
dd if="${ROOTFS}/boot/E4412_S.bl1.HardKernel.bin" of="${LOOPDEV}" seek=1 >/dev/null 2>&1
|
|
|
|
dd if="${ROOTFS}/boot/bl2.signed.bin" of="${LOOPDEV}" seek=31 >/dev/null 2>&1
|
|
|
|
dd if="${ROOTFS}/boot/u-boot.bin" of="${LOOPDEV}" seek=63 >/dev/null 2>&1
|
|
|
|
dd if="${ROOTFS}/boot/E4412_S.tzsw.signed.bin" of="${LOOPDEV}" seek=2111 >/dev/null 2>&1
|
2015-05-16 18:16:32 +00:00
|
|
|
;;
|
2016-04-26 13:47:56 +00:00
|
|
|
usbarmory*)
|
2017-08-13 03:55:31 +00:00
|
|
|
dd if="${ROOTFS}/boot/u-boot.imx" of="${LOOPDEV}" bs=512 seek=2 conv=fsync >/dev/null 2>&1
|
2015-05-16 18:16:32 +00:00
|
|
|
;;
|
2016-04-26 13:47:56 +00:00
|
|
|
ci20*)
|
2017-08-13 03:55:31 +00:00
|
|
|
dd if="${ROOTFS}/boot/u-boot-spl.bin" of="${LOOPDEV}" obs=512 seek=1 >/dev/null 2>&1
|
|
|
|
dd if="${ROOTFS}/boot/u-boot.img" of="${LOOPDEV}" obs=1K seek=14 >/dev/null 2>&1
|
2016-04-26 09:20:14 +00:00
|
|
|
;;
|
2017-07-24 00:55:41 +00:00
|
|
|
GCP*)
|
2017-08-13 08:40:19 +00:00
|
|
|
# Google Cloud Platform image configuration for Google Cloud
|
|
|
|
# Engine. The steps below are built in reference to the
|
|
|
|
# documentation on building custom images available here:
|
|
|
|
# https://cloud.google.com/compute/docs/images/import-existing-image
|
|
|
|
# The images produced by this script are ready to upload and boot.
|
|
|
|
|
2017-07-24 00:55:41 +00:00
|
|
|
# Setup GRUB
|
|
|
|
mount_pseudofs
|
2017-08-14 00:45:22 +00:00
|
|
|
run_cmd_chroot "${ROOTFS}" "grub-install ${LOOPDEV}"
|
2017-08-13 03:55:31 +00:00
|
|
|
sed -i "s:page_poison=1:page_poison=1 console=ttyS0,38400n8d:" "${ROOTFS}/etc/default/grub"
|
2017-08-14 00:45:22 +00:00
|
|
|
run_cmd_chroot "${ROOTFS}" update-grub
|
2017-07-24 00:55:41 +00:00
|
|
|
|
|
|
|
# Setup the GCP Guest services
|
|
|
|
for _service in dhcpcd sshd agetty-console nanoklogd socklog-unix GCP-Guest-Initialization GCP-accounts GCP-clock-skew GCP-ip-forwarding ; do
|
2017-08-14 00:45:22 +00:00
|
|
|
run_cmd_chroot "${ROOTFS}" "ln -sv /etc/sv/$_service /etc/runit/runsvdir/default/$_service"
|
2017-07-24 00:55:41 +00:00
|
|
|
done
|
|
|
|
|
|
|
|
# Turn off the agetty's since we can't use them anyway
|
2017-08-14 00:45:22 +00:00
|
|
|
rm -v "${ROOTFS}/etc/runit/runsvdir/default/agetty-tty"*
|
2017-07-24 00:55:41 +00:00
|
|
|
|
|
|
|
# Disable root login over ssh and lock account
|
2017-08-13 03:55:31 +00:00
|
|
|
sed -i "s:PermitRootLogin yes:PermitRootLogin no:" "${ROOTFS}/etc/ssh/sshd_config"
|
2017-08-14 00:45:22 +00:00
|
|
|
run_cmd_chroot "${ROOTFS}" "passwd -l root"
|
2017-07-24 00:55:41 +00:00
|
|
|
|
|
|
|
# Set the Timezone
|
2017-08-14 00:45:22 +00:00
|
|
|
run_cmd_chroot "${ROOTFS}" "ln -svf /usr/share/zoneinfo/UTC /etc/localtime"
|
2017-07-24 00:55:41 +00:00
|
|
|
|
|
|
|
# Generate glibc-locales if necessary (this is a noop on musl)
|
|
|
|
if [ "$PLATFORM" = GCP ] ; then
|
2017-08-14 00:45:22 +00:00
|
|
|
run_cmd_chroot "${ROOTFS}" "xbps-reconfigure -f glibc-locales"
|
2017-07-24 00:55:41 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Remove SSH host keys (these will get rebuilt on first boot)
|
2017-08-13 03:55:31 +00:00
|
|
|
rm -f "${ROOTFS}/etc/ssh/*key*"
|
|
|
|
rm -f "${ROOTFS}/etc/ssh/moduli"
|
2017-07-24 00:55:41 +00:00
|
|
|
|
2017-08-13 08:40:19 +00:00
|
|
|
# Force the hostname since this isn't read from DHCP
|
2017-08-13 03:55:31 +00:00
|
|
|
echo void-GCE > "${ROOTFS}/etc/hostname"
|
2017-08-14 00:45:22 +00:00
|
|
|
|
|
|
|
# Cleanup the chroot from anything that was setup for the
|
|
|
|
# run_cmd_chroot commands
|
|
|
|
cleanup_chroot
|
2017-07-24 00:55:41 +00:00
|
|
|
;;
|
2015-05-16 18:16:32 +00:00
|
|
|
esac
|
2014-01-26 18:32:54 -01:00
|
|
|
|
2017-08-13 08:40:19 +00:00
|
|
|
# Release all the mounts, deconfigure the loop device, and remove the
|
|
|
|
# rootfs mountpoint. Since this was just a mountpoint it should be
|
|
|
|
# empty. If it contains stuff we bail out here since something went
|
|
|
|
# very wrong.
|
2017-08-13 03:55:31 +00:00
|
|
|
umount -R "$ROOTFS"
|
|
|
|
losetup -d "$LOOPDEV"
|
|
|
|
rmdir "$ROOTFS" || die "$ROOTFS not empty!"
|
2013-08-11 10:17:18 +00:00
|
|
|
|
2017-08-13 08:40:19 +00:00
|
|
|
# We've been working with this as root for a while now, so this makes
|
|
|
|
# sure the permissions are sane.
|
2017-08-13 03:55:31 +00:00
|
|
|
chmod 644 "$FILENAME"
|
2017-08-13 08:40:19 +00:00
|
|
|
|
|
|
|
# The standard images are ready to go, but the cloud images require
|
|
|
|
# some minimal additional post processing.
|
2017-07-24 00:55:41 +00:00
|
|
|
case "$PLATFORM" in
|
|
|
|
GCP*)
|
2017-08-13 08:40:19 +00:00
|
|
|
# This filename is mandated by the Google Cloud Engine import
|
|
|
|
# process, the archive name is not.
|
2017-08-31 08:28:33 +00:00
|
|
|
mv "$FILENAME" disk.raw
|
2017-07-24 00:55:41 +00:00
|
|
|
info_msg "Compressing disk.raw"
|
2017-08-13 03:55:31 +00:00
|
|
|
tar Sczf "${FILENAME%.img}.tar.gz" disk.raw
|
2017-08-13 08:40:19 +00:00
|
|
|
# Since this process just produces something that can be
|
|
|
|
# uploaded, we remove the original disk image.
|
2017-07-24 00:55:41 +00:00
|
|
|
rm disk.raw
|
2017-08-13 03:55:31 +00:00
|
|
|
info_msg "Sucessfully created ${FILENAME%.img}.tar.gz image."
|
2017-07-24 00:55:41 +00:00
|
|
|
;;
|
|
|
|
*)
|
2017-08-19 07:14:12 +00:00
|
|
|
info_msg "Compressing $FILENAME with xz (level 9 compression)"
|
2017-08-21 07:04:17 +00:00
|
|
|
xz "-T${COMPRESSOR_THREADS:-0}" -9 "$FILENAME"
|
2017-07-24 00:55:41 +00:00
|
|
|
info_msg "Successfully created $FILENAME image."
|
|
|
|
;;
|
|
|
|
esac
|