| ramonsalguer | 8ac0f08 | 2020-06-03 20:13:34 +0200 | [diff] [blame] | 1 | #!/bin/sh -eux |
| 2 | |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | # you may not use this file except in compliance with the License. |
| 5 | # You may obtain a copy of the License at |
| 6 | # |
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | # See the License for the specific language governing permissions and |
| 13 | # limitations under the License. |
| 14 | |
| 15 | case "$PACKER_BUILDER_TYPE" in |
| 16 | qemu) exit 0 ;; |
| 17 | esac |
| 18 | |
| 19 | # Whiteout root |
| 20 | count=$(df --sync -kP / | tail -n1 | awk -F ' ' '{print $4}') |
| 21 | count=$(($count-1)) |
| 22 | dd if=/dev/zero of=/tmp/whitespace bs=1M count=$count || echo "dd exit code $? is suppressed"; |
| 23 | rm /tmp/whitespace |
| 24 | |
| 25 | # Whiteout /boot |
| 26 | count=$(df --sync -kP /boot | tail -n1 | awk -F ' ' '{print $4}') |
| 27 | count=$(($count-1)) |
| 28 | dd if=/dev/zero of=/boot/whitespace bs=1M count=$count || echo "dd exit code $? is suppressed"; |
| 29 | rm /boot/whitespace |
| 30 | |
| 31 | set +e |
| 32 | swapuuid="`/sbin/blkid -o value -l -s UUID -t TYPE=swap`"; |
| 33 | case "$?" in |
| 34 | 2|0) ;; |
| 35 | *) exit 1 ;; |
| 36 | esac |
| 37 | set -e |
| 38 | |
| 39 | if [ "x${swapuuid}" != "x" ]; then |
| 40 | # Whiteout the swap partition to reduce box size |
| 41 | # Swap is disabled till reboot |
| 42 | swappart="`readlink -f /dev/disk/by-uuid/$swapuuid`"; |
| 43 | /sbin/swapoff "$swappart"; |
| 44 | dd if=/dev/zero of="$swappart" bs=1M || echo "dd exit code $? is suppressed"; |
| 45 | /sbin/mkswap -U "$swapuuid" "$swappart"; |
| 46 | fi |
| 47 | |
| 48 | sync; |