path: root/imgpkg/
diff options
authorRichard Maw <>2014-03-18 16:42:03 +0000
committerRichard Maw <>2014-03-20 16:33:34 +0000
commitfcf5150e927147bbce338a61101ccbb3d760f07c (patch)
tree371099eaffd417f61878f0c756a50964c35ba2b6 /imgpkg/
parent31aadea7e49617a783f924fe373e642c88157a2b (diff)
Add write extension for making a package that allows deferred instansiationbaserock/richardmaw/S10721-img-pkg
This is a write extension for making a package that can be used to install the produced system. Ideally we'd instead have Baserock everywhere to do the deployment, but we need to support this workflow until that is possible. It gets configured with a script templates that get filled in with the paths to the rootfs tarball as @@ROOTFS_TAR_PATH@@, script directory as @@SCRIPT_DIR@@ and copied boot-files as @@IMAGE_DIR@@. Scripts to include are specified as a relative path to your morphologies repository, separated by : characters in the INCLUDE_SCRIPTS variable. If another separator is convenient, it can be specified in the INCLUDE_SCRIPTS_SEPARATOR variable, which has the same semantics as the shell IFS variable. Other files needed to create the disk image, such as bootloader image files can be specified in BOOTLOADER_BLOBS, relative to the root of the rootfs, separated with similar rules to INCLUDE_SCRIPTS. The name of the rootfs tarball, the scripts subdirectory and the bootloader blobs subdirectory can be changed with the ROOTFS_TAR, SCRIPT_SUBDIR and IMAGE_SUBDIR variables, but the default should be sufficient. The compression of the rootfs tarball, and the package tarball can be specified by specifying a shell command that reads the uncompressed tarball from stdin and writes to stdout in the ROOTFS_COMPRESS and OUTPUT_COMPRESS variables.
Diffstat (limited to 'imgpkg/')
1 files changed, 71 insertions, 0 deletions
diff --git a/imgpkg/ b/imgpkg/
new file mode 100644
index 00000000..08473a6b
--- /dev/null
+++ b/imgpkg/
@@ -0,0 +1,71 @@
+ echo "$@"
+ echo "$@" >&2
+ echo "$@" >&2
+ tar -C "$1" -xf @@ROOTFS_TAR_PATH@@ .
+ truncate --size "$1" "$2"
+ local disk="$1"
+ mkfs.ext4 -F -L rootfs "$disk"
+ local mountpoint="$1"
+ local rootdisk="${2-/dev/vda}"
+ cat >>"$mountpoint/etc/fstab" <<EOF
+$rootdisk / ext4 rw,errors=remount-ro 0 0
+ install -D -m 644 /proc/self/fd/0 "$mountpoint/boot/extlinux.conf" <<EOF
+DEFAULT baserock
+LABEL baserock
+SAY Booting Baserock
+LINUX /boot/vmlinuz
+APPEND root=$rootdisk
+ local disk="$1"
+ local mountpoint="$2"
+ dd if=@@IMAGE_DIR@@/mbr.bin conv=notrunc bs=440 count=1 of="$disk"
+ extlinux --install "$mountpoint/boot"
+ losetup --show --find "$1"
+ #losetup --detach "$1"
+ # unlooping handled by umount -d, for busybox compatibility
+ true
+ local mp="$(mktemp -d)"
+ if ! mount "$@" "$mp"; then
+ rmdir "$mp"
+ return 1
+ fi
+ echo "$mp"
+ # Unmount and detach in one step for busybox compatibility
+ umount -d "$1"
+ rmdir "$1"