History

Support building GCP ready images

Michael Aldridge committed 9 years ago

Commit 04bf2e81 parent a4b3dd33 files · +70 −4Browse files

Unified · Split

3 files
  1. .gitignore +2 −0
  2. mkimage.sh.in +62 −2
  3. mkrootfs.sh.in +6 −2
.gitignore+2−0
@@ -2,4 +2,6 @@ · 1 unmodified line
22 *.img
33 *.xz
44 *.iso
5+*.raw
6+*.tar.gz
57 xbps-cachedir*
mkimage.sh.in+62−2
@@ -1,6 +1,7 @@
11 #!/bin/sh
22 #-
33 # Copyright (c) 2013-2016 Juan Romero Pardines.
4+# Copyright (c) 2017 Google
45 # All rights reserved.
56 #
67 # Redistribution and use in source and binary forms, with or without
@@ -29,7 +30,20 @@ readonly ARCH=$(uname -m) · 22 unmodified lines
2930
3031 trap 'printf "\nInterrupted! exiting...\n"; cleanup; exit 0' INT TERM HUP
3132
33+mount_pseudofs() {
34+ for f in sys dev proc; do
35+ mkdir -p $ROOTFSDIR/$f
36+ mount --bind /$f $ROOTFSDIR/$f
37+ done
38+}
39+umount_pseudofs() {
40+ umount -f $ROOTFSDIR/sys >/dev/null 2>&1
41+ umount -f $ROOTFSDIR/dev >/dev/null 2>&1
42+ umount -f $ROOTFSDIR/proc >/dev/null 2>&1
43+}
44+
3245 cleanup() {
46+ unmount_pseudofs
3347 umount -f ${ROOTFSDIR}/boot 2>/dev/null
3448 umount -f ${ROOTFSDIR} 2>/dev/null
3549 if [ -e "$LOOPDEV" ]; then
@@ -113,7 +127,7 @@ fi · 77 unmodified lines
113127
114128 # double check PLATFORM is supported...
115129 case "$PLATFORM" in
116− bananapi|beaglebone|cubieboard2|cubietruck|odroid-c2|odroid-u2|rpi|rpi2|rpi3|usbarmory|*-musl);;
130+ bananapi|beaglebone|cubieboard2|cubietruck|odroid-c2|odroid-u2|rpi|rpi2|rpi3|usbarmory|GCP|*-musl);;
117131 *) die "The $PLATFORM is not supported, exiting..."
118132 esac
119133
@@ -212,6 +226,41 @@ ci20*) · 92 unmodified lines
212226 dd if=${ROOTFSDIR}/boot/u-boot-spl.bin of=${LOOPDEV} obs=512 seek=1 >/dev/null 2>&1
213227 dd if=${ROOTFSDIR}/boot/u-boot.img of=${LOOPDEV} obs=1K seek=14 >/dev/null 2>&1
214228 ;;
229+GCP*)
230+ # Setup GRUB
231+ mount_pseudofs
232+ chroot ${ROOTFSDIR} grub-install ${LOOPDEV}
233+ sed -i "s:page_poison=1:page_poison=1 console=ttyS0,38400n8d:" ${ROOTFSDIR}/etc/default/grub
234+ chroot ${ROOTFSDIR} update-grub
235+ umount_pseudofs
236+
237+ # Setup the GCP Guest services
238+ for _service in dhcpcd sshd agetty-console nanoklogd socklog-unix GCP-Guest-Initialization GCP-accounts GCP-clock-skew GCP-ip-forwarding ; do
239+ chroot ${ROOTFSDIR} ln -sv /etc/sv/$_service /etc/runit/runsvdir/default/$_service
240+ done
241+
242+ # Turn off the agetty's since we can't use them anyway
243+ rm -v ${ROOTFSDIR}/etc/runit/runsvdir/default/agetty-tty*
244+
245+ # Disable root login over ssh and lock account
246+ sed -i "s:PermitRootLogin yes:PermitRootLogin no:" ${ROOTFSDIR}/etc/ssh/sshd_config
247+ chroot ${ROOTFSDIR} passwd -l root
248+
249+ # Set the Timezone
250+ chroot ${ROOTFSDIR} ln -svf /usr/share/zoneinfo/UTC /etc/localtime
251+
252+ # Generate glibc-locales if necessary (this is a noop on musl)
253+ if [ "$PLATFORM" = GCP ] ; then
254+ chroot ${ROOTFSDIR} xbps-reconfigure -f glibc-locales
255+ fi
256+
257+ # Remove SSH host keys (these will get rebuilt on first boot)
258+ rm -v ${ROOTFSDIR}/etc/ssh/*key*
259+ rm -v ${ROOTFSDIR}/etc/ssh/moduli
260+
261+ # Force hte hostname since this isn't read from DHCP
262+ echo "void-GCE" > ${ROOTFSDIR}/etc/hostname
263+ ;;
215264 esac
216265
217266 mountpoint -q ${ROOTFSDIR}/boot && umount ${ROOTFSDIR}/boot
@@ -220,6 +269,17 @@ losetup -d $LOOPDEV · 2 unmodified lines
220269 rmdir $ROOTFSDIR
221270
222271 chmod 644 $FILENAME
223−info_msg "Successfully created $FILENAME image."
272+case "$PLATFORM" in
273+ GCP*)
274+ mv void-GCP*.img disk.raw
275+ info_msg "Compressing disk.raw"
276+ tar Sczf "${FILENAME/.img/.tar.gz}" disk.raw
277+ rm disk.raw
278+ info_msg "Sucessfully created ${FILENAME/.img/.tar.gz/} image."
279+ ;;
280+ *)
281+ info_msg "Successfully created $FILENAME image."
282+ ;;
283+esac
224284
225285 # vim: set ts=4 sw=4 et:
mkrootfs.sh.in+6−2
@@ -1,6 +1,7 @@
11 #!/bin/sh
22 #-
33 # Copyright (c) 2013-2015 Juan Romero Pardines.
4+# Copyright (c) 2017 Google
45 # All rights reserved.
56 #
67 # Redistribution and use in source and binary forms, with or without
@@ -45,7 +46,7 @@ usage() { · 38 unmodified lines
4546 cat <<_EOF
4647 Usage: $PROGNAME [options] <platform>
4748
48−Supported platforms: i686, i686-musl, x86_64, x86_64-musl,
49+Supported platforms: i686, i686-musl, x86_64, x86_64-musl, GCP, GCP-musl
4950 dockstar, bananapi, beaglebone, cubieboard2, cubietruck,
5051 odroid-c2, odroid-u2, rpi, rpi2 (armv7), rpi3 (aarch64),
5152 usbarmory, ci20
@@ -138,6 +139,8 @@ SUBPLATFORM=$PLATFORM · 86 unmodified lines
138139 case "$PLATFORM" in
139140 i686*) _TARGET_ARCH="$PLATFORM"; _ARCH="i686";;
140141 x86_64*) _TARGET_ARCH="$PLATFORM"; _ARCH="x86_64";;
142+ GCP) _TARGET_ARCH="x86_64"; _ARCH="x86_64";;
143+ GCP-musl) _TARGET_ARCH="x86_64-musl"; _ARCH="x86_64";;
141144 dockstar) _TARGET_ARCH="armv5tel"; _ARCH="armv5tel";;
142145 rpi-musl) _TARGET_ARCH="armv6l-musl"; _ARCH="armv6l";;
143146 rpi) _TARGET_ARCH="armv6l"; _ARCH="armv6l";;
@@ -178,6 +181,7 @@ case "$PLATFORM" in · 34 unmodified lines
178181 odroid-c2*) SUBPLATFORM=${PLATFORM%-musl}; QEMU_BIN=qemu-aarch64-static;;
179182 i686*) QEMU_BIN=qemu-i386-static;;
180183 x86_64*) QEMU_BIN=qemu-x86_64-static;;
184+ GCP*) SUBPLATFORM=${PLATFORM%-*}; QEMU_BIN=qemu-x86_64-static;;
181185 *) die "$PROGNAME: invalid platform!";;
182186 esac
183187
@@ -233,7 +237,7 @@ fi · 49 unmodified lines
233237 if [ -n "${_ARCH}" ]; then
234238 info_msg "Reconfiguring packages for ${_ARCH} ..."
235239 case "$PLATFORM" in
236− i686*|x86_64*)
240+ i686*|x86_64*|GCP*)
237241 run_cmd "XBPS_ARCH=${PLATFORM} xbps-reconfigure -r $rootfs base-files"
238242 ;;
239243 *)

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t