Support building GCP ready images
This commit is contained in:
parent
a4b3dd36c9
commit
04bf2e873b
|
@ -2,4 +2,6 @@
|
||||||
*.img
|
*.img
|
||||||
*.xz
|
*.xz
|
||||||
*.iso
|
*.iso
|
||||||
|
*.raw
|
||||||
|
*.tar.gz
|
||||||
xbps-cachedir*
|
xbps-cachedir*
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
#-
|
#-
|
||||||
# Copyright (c) 2013-2016 Juan Romero Pardines.
|
# Copyright (c) 2013-2016 Juan Romero Pardines.
|
||||||
|
# Copyright (c) 2017 Google
|
||||||
# All rights reserved.
|
# All rights reserved.
|
||||||
#
|
#
|
||||||
# Redistribution and use in source and binary forms, with or without
|
# Redistribution and use in source and binary forms, with or without
|
||||||
|
@ -29,7 +30,20 @@ readonly ARCH=$(uname -m)
|
||||||
|
|
||||||
trap 'printf "\nInterrupted! exiting...\n"; cleanup; exit 0' INT TERM HUP
|
trap 'printf "\nInterrupted! exiting...\n"; cleanup; exit 0' INT TERM HUP
|
||||||
|
|
||||||
|
mount_pseudofs() {
|
||||||
|
for f in sys dev proc; do
|
||||||
|
mkdir -p $ROOTFSDIR/$f
|
||||||
|
mount --bind /$f $ROOTFSDIR/$f
|
||||||
|
done
|
||||||
|
}
|
||||||
|
umount_pseudofs() {
|
||||||
|
umount -f $ROOTFSDIR/sys >/dev/null 2>&1
|
||||||
|
umount -f $ROOTFSDIR/dev >/dev/null 2>&1
|
||||||
|
umount -f $ROOTFSDIR/proc >/dev/null 2>&1
|
||||||
|
}
|
||||||
|
|
||||||
cleanup() {
|
cleanup() {
|
||||||
|
unmount_pseudofs
|
||||||
umount -f ${ROOTFSDIR}/boot 2>/dev/null
|
umount -f ${ROOTFSDIR}/boot 2>/dev/null
|
||||||
umount -f ${ROOTFSDIR} 2>/dev/null
|
umount -f ${ROOTFSDIR} 2>/dev/null
|
||||||
if [ -e "$LOOPDEV" ]; then
|
if [ -e "$LOOPDEV" ]; then
|
||||||
|
@ -113,7 +127,7 @@ fi
|
||||||
|
|
||||||
# double check PLATFORM is supported...
|
# double check PLATFORM is supported...
|
||||||
case "$PLATFORM" in
|
case "$PLATFORM" in
|
||||||
bananapi|beaglebone|cubieboard2|cubietruck|odroid-c2|odroid-u2|rpi|rpi2|rpi3|usbarmory|*-musl);;
|
bananapi|beaglebone|cubieboard2|cubietruck|odroid-c2|odroid-u2|rpi|rpi2|rpi3|usbarmory|GCP|*-musl);;
|
||||||
*) die "The $PLATFORM is not supported, exiting..."
|
*) die "The $PLATFORM is not supported, exiting..."
|
||||||
esac
|
esac
|
||||||
|
|
||||||
|
@ -212,6 +226,41 @@ ci20*)
|
||||||
dd if=${ROOTFSDIR}/boot/u-boot-spl.bin of=${LOOPDEV} obs=512 seek=1 >/dev/null 2>&1
|
dd if=${ROOTFSDIR}/boot/u-boot-spl.bin of=${LOOPDEV} obs=512 seek=1 >/dev/null 2>&1
|
||||||
dd if=${ROOTFSDIR}/boot/u-boot.img of=${LOOPDEV} obs=1K seek=14 >/dev/null 2>&1
|
dd if=${ROOTFSDIR}/boot/u-boot.img of=${LOOPDEV} obs=1K seek=14 >/dev/null 2>&1
|
||||||
;;
|
;;
|
||||||
|
GCP*)
|
||||||
|
# Setup GRUB
|
||||||
|
mount_pseudofs
|
||||||
|
chroot ${ROOTFSDIR} grub-install ${LOOPDEV}
|
||||||
|
sed -i "s:page_poison=1:page_poison=1 console=ttyS0,38400n8d:" ${ROOTFSDIR}/etc/default/grub
|
||||||
|
chroot ${ROOTFSDIR} update-grub
|
||||||
|
umount_pseudofs
|
||||||
|
|
||||||
|
# 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
|
||||||
|
chroot ${ROOTFSDIR} ln -sv /etc/sv/$_service /etc/runit/runsvdir/default/$_service
|
||||||
|
done
|
||||||
|
|
||||||
|
# Turn off the agetty's since we can't use them anyway
|
||||||
|
rm -v ${ROOTFSDIR}/etc/runit/runsvdir/default/agetty-tty*
|
||||||
|
|
||||||
|
# Disable root login over ssh and lock account
|
||||||
|
sed -i "s:PermitRootLogin yes:PermitRootLogin no:" ${ROOTFSDIR}/etc/ssh/sshd_config
|
||||||
|
chroot ${ROOTFSDIR} passwd -l root
|
||||||
|
|
||||||
|
# Set the Timezone
|
||||||
|
chroot ${ROOTFSDIR} ln -svf /usr/share/zoneinfo/UTC /etc/localtime
|
||||||
|
|
||||||
|
# Generate glibc-locales if necessary (this is a noop on musl)
|
||||||
|
if [ "$PLATFORM" = GCP ] ; then
|
||||||
|
chroot ${ROOTFSDIR} xbps-reconfigure -f glibc-locales
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Remove SSH host keys (these will get rebuilt on first boot)
|
||||||
|
rm -v ${ROOTFSDIR}/etc/ssh/*key*
|
||||||
|
rm -v ${ROOTFSDIR}/etc/ssh/moduli
|
||||||
|
|
||||||
|
# Force hte hostname since this isn't read from DHCP
|
||||||
|
echo "void-GCE" > ${ROOTFSDIR}/etc/hostname
|
||||||
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
mountpoint -q ${ROOTFSDIR}/boot && umount ${ROOTFSDIR}/boot
|
mountpoint -q ${ROOTFSDIR}/boot && umount ${ROOTFSDIR}/boot
|
||||||
|
@ -220,6 +269,17 @@ losetup -d $LOOPDEV
|
||||||
rmdir $ROOTFSDIR
|
rmdir $ROOTFSDIR
|
||||||
|
|
||||||
chmod 644 $FILENAME
|
chmod 644 $FILENAME
|
||||||
info_msg "Successfully created $FILENAME image."
|
case "$PLATFORM" in
|
||||||
|
GCP*)
|
||||||
|
mv void-GCP*.img disk.raw
|
||||||
|
info_msg "Compressing disk.raw"
|
||||||
|
tar Sczf "${FILENAME/.img/.tar.gz}" disk.raw
|
||||||
|
rm disk.raw
|
||||||
|
info_msg "Sucessfully created ${FILENAME/.img/.tar.gz/} image."
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
info_msg "Successfully created $FILENAME image."
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
# vim: set ts=4 sw=4 et:
|
# vim: set ts=4 sw=4 et:
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
#-
|
#-
|
||||||
# Copyright (c) 2013-2015 Juan Romero Pardines.
|
# Copyright (c) 2013-2015 Juan Romero Pardines.
|
||||||
|
# Copyright (c) 2017 Google
|
||||||
# All rights reserved.
|
# All rights reserved.
|
||||||
#
|
#
|
||||||
# Redistribution and use in source and binary forms, with or without
|
# Redistribution and use in source and binary forms, with or without
|
||||||
|
@ -45,7 +46,7 @@ usage() {
|
||||||
cat <<_EOF
|
cat <<_EOF
|
||||||
Usage: $PROGNAME [options] <platform>
|
Usage: $PROGNAME [options] <platform>
|
||||||
|
|
||||||
Supported platforms: i686, i686-musl, x86_64, x86_64-musl,
|
Supported platforms: i686, i686-musl, x86_64, x86_64-musl, GCP, GCP-musl
|
||||||
dockstar, bananapi, beaglebone, cubieboard2, cubietruck,
|
dockstar, bananapi, beaglebone, cubieboard2, cubietruck,
|
||||||
odroid-c2, odroid-u2, rpi, rpi2 (armv7), rpi3 (aarch64),
|
odroid-c2, odroid-u2, rpi, rpi2 (armv7), rpi3 (aarch64),
|
||||||
usbarmory, ci20
|
usbarmory, ci20
|
||||||
|
@ -138,6 +139,8 @@ SUBPLATFORM=$PLATFORM
|
||||||
case "$PLATFORM" in
|
case "$PLATFORM" in
|
||||||
i686*) _TARGET_ARCH="$PLATFORM"; _ARCH="i686";;
|
i686*) _TARGET_ARCH="$PLATFORM"; _ARCH="i686";;
|
||||||
x86_64*) _TARGET_ARCH="$PLATFORM"; _ARCH="x86_64";;
|
x86_64*) _TARGET_ARCH="$PLATFORM"; _ARCH="x86_64";;
|
||||||
|
GCP) _TARGET_ARCH="x86_64"; _ARCH="x86_64";;
|
||||||
|
GCP-musl) _TARGET_ARCH="x86_64-musl"; _ARCH="x86_64";;
|
||||||
dockstar) _TARGET_ARCH="armv5tel"; _ARCH="armv5tel";;
|
dockstar) _TARGET_ARCH="armv5tel"; _ARCH="armv5tel";;
|
||||||
rpi-musl) _TARGET_ARCH="armv6l-musl"; _ARCH="armv6l";;
|
rpi-musl) _TARGET_ARCH="armv6l-musl"; _ARCH="armv6l";;
|
||||||
rpi) _TARGET_ARCH="armv6l"; _ARCH="armv6l";;
|
rpi) _TARGET_ARCH="armv6l"; _ARCH="armv6l";;
|
||||||
|
@ -178,6 +181,7 @@ case "$PLATFORM" in
|
||||||
odroid-c2*) SUBPLATFORM=${PLATFORM%-musl}; QEMU_BIN=qemu-aarch64-static;;
|
odroid-c2*) SUBPLATFORM=${PLATFORM%-musl}; QEMU_BIN=qemu-aarch64-static;;
|
||||||
i686*) QEMU_BIN=qemu-i386-static;;
|
i686*) QEMU_BIN=qemu-i386-static;;
|
||||||
x86_64*) QEMU_BIN=qemu-x86_64-static;;
|
x86_64*) QEMU_BIN=qemu-x86_64-static;;
|
||||||
|
GCP*) SUBPLATFORM=${PLATFORM%-*}; QEMU_BIN=qemu-x86_64-static;;
|
||||||
*) die "$PROGNAME: invalid platform!";;
|
*) die "$PROGNAME: invalid platform!";;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
|
@ -233,7 +237,7 @@ fi
|
||||||
if [ -n "${_ARCH}" ]; then
|
if [ -n "${_ARCH}" ]; then
|
||||||
info_msg "Reconfiguring packages for ${_ARCH} ..."
|
info_msg "Reconfiguring packages for ${_ARCH} ..."
|
||||||
case "$PLATFORM" in
|
case "$PLATFORM" in
|
||||||
i686*|x86_64*)
|
i686*|x86_64*|GCP*)
|
||||||
run_cmd "XBPS_ARCH=${PLATFORM} xbps-reconfigure -r $rootfs base-files"
|
run_cmd "XBPS_ARCH=${PLATFORM} xbps-reconfigure -r $rootfs base-files"
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
|
|
Loading…
Reference in New Issue