diff --git a/images/linux/scripts/installers/validate-disk-space.sh b/images/linux/scripts/installers/validate-disk-space.sh new file mode 100644 index 0000000000..208a0e0f62 --- /dev/null +++ b/images/linux/scripts/installers/validate-disk-space.sh @@ -0,0 +1,14 @@ +#!/bin/bash +################################################################################ +## File: validate-disk-space.sh +## Desc: Validate free disk space +################################################################################ + +availableSpaceMB=$(df / -hm | sed 1d | awk '{ print $4}') +minimumFreeSpaceMB=$(( 18*1024 )) + +echo "Available disk space: $availableSpaceMB MB" +if [ $availableSpaceMB -le $minimumFreeSpaceMB ]; then + echo "Not enough disk space on the image (minimum available space: $minimumFreeSpaceMB MB)" + exit 1 +fi \ No newline at end of file diff --git a/images/linux/ubuntu1604.json b/images/linux/ubuntu1604.json index 62081af541..0c42a224af 100644 --- a/images/linux/ubuntu1604.json +++ b/images/linux/ubuntu1604.json @@ -306,6 +306,12 @@ ], "execute_command": "sudo sh -c '{{ .Vars }} {{ .Path }}'" }, + { + "type": "shell", + "scripts":[ + "{{template_dir}}/scripts/installers/validate-disk-space.sh" + ] + }, { "type": "file", "source": "{{user `metadata_file`}}", diff --git a/images/linux/ubuntu1804.json b/images/linux/ubuntu1804.json index 41b758976a..6afea17b59 100644 --- a/images/linux/ubuntu1804.json +++ b/images/linux/ubuntu1804.json @@ -310,6 +310,12 @@ ], "execute_command": "sudo sh -c '{{ .Vars }} {{ .Path }}'" }, + { + "type": "shell", + "scripts":[ + "{{template_dir}}/scripts/installers/validate-disk-space.sh" + ] + }, { "type": "file", "source": "{{user `metadata_file`}}", diff --git a/images/win/Windows2016-Azure.json b/images/win/Windows2016-Azure.json index 55a1e611e8..dce3ccd640 100644 --- a/images/win/Windows2016-Azure.json +++ b/images/win/Windows2016-Azure.json @@ -883,6 +883,12 @@ "{{ template_dir }}/scripts/Installers/Validate-Kind.ps1" ] }, + { + "type": "powershell", + "scripts":[ + "{{ template_dir }}/scripts/Installers/Validate-DiskSpace.ps1" + ] + }, { "type": "file", "source": "C:\\InstalledSoftware.md", diff --git a/images/win/Windows2019-Azure.json b/images/win/Windows2019-Azure.json index ab28c810c4..8dc78665cd 100644 --- a/images/win/Windows2019-Azure.json +++ b/images/win/Windows2019-Azure.json @@ -886,6 +886,12 @@ "{{ template_dir }}/scripts/Installers/Validate-AliyunCli.ps1" ] }, + { + "type": "powershell", + "scripts":[ + "{{ template_dir }}/scripts/Installers/Validate-DiskSpace.ps1" + ] + }, { "type": "file", "source": "C:\\InstalledSoftware.md", diff --git a/images/win/scripts/Installers/Validate-DiskSpace.ps1 b/images/win/scripts/Installers/Validate-DiskSpace.ps1 new file mode 100644 index 0000000000..d5b4f9966e --- /dev/null +++ b/images/win/scripts/Installers/Validate-DiskSpace.ps1 @@ -0,0 +1,14 @@ +################################################################################ +## File: Validate-DiskSpace.ps1 +## Desc: Validate free disk space +################################################################################ + +$availableSpaceMB = [math]::Round((Get-PSDrive -Name C).Free / 1MB) +$minimumFreeSpaceMB = 15 * 1024 + +Write-Host "Available disk space: $availableSpaceMB MB" +if ($availableSpaceMB -le $minimumFreeSpaceMB) +{ + Write-Host "Not enough disk space on the image (minimum available space: $minimumFreeSpaceMB MB)" + exit 1 +}