diff --git a/toolkit/imageconfigs/baremetal.json b/toolkit/imageconfigs/baremetal.json index bd75941ae08..603ef781d01 100644 --- a/toolkit/imageconfigs/baremetal.json +++ b/toolkit/imageconfigs/baremetal.json @@ -57,6 +57,11 @@ "KernelOptions": { "default": "kernel" }, + "FinalizeImageScripts": [ + { + "Path": "scripts/cleanup.sh" + } + ], "Hostname": "azure-linux" } ] diff --git a/toolkit/imageconfigs/qemu-guest.json b/toolkit/imageconfigs/qemu-guest.json index 654e2b1552d..152b0330d30 100644 --- a/toolkit/imageconfigs/qemu-guest.json +++ b/toolkit/imageconfigs/qemu-guest.json @@ -55,6 +55,11 @@ "KernelOptions": { "default": "kernel-hci" }, + "FinalizeImageScripts": [ + { + "Path": "scripts/cleanup.sh" + } + ], "Hostname": "azure-linux" } ] diff --git a/toolkit/imageconfigs/scripts/cleanup.sh b/toolkit/imageconfigs/scripts/cleanup.sh new file mode 100755 index 00000000000..8c43b6ac31b --- /dev/null +++ b/toolkit/imageconfigs/scripts/cleanup.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. + +set -eux + +# cleanup symlinks created by the toolkit that are not needed for base images +if [ -L /srv ]; then + echo "Removing /srv symlink" + rm /srv +else + echo "/srv symlink does not exist" +fi + +# cleanup any logs that may have been created during the build +if [ -d /var/log ]; then + echo "Clearing /var/log" + rm -rf /var/log/* +else + echo "/var/log does not exist" +fi