blob: 0b0e4769e004fc88eeba74eb71ed6e4e2b6ddc6c [file] [log] [blame]
ramonsalguer8ac0f082020-06-03 20:13:34 +02001#!/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
15case "$PACKER_BUILDER_TYPE" in
16 qemu) exit 0 ;;
17esac
18
19# Whiteout root
20count=$(df --sync -kP / | tail -n1 | awk -F ' ' '{print $4}')
21count=$(($count-1))
22dd if=/dev/zero of=/tmp/whitespace bs=1M count=$count || echo "dd exit code $? is suppressed";
23rm /tmp/whitespace
24
25# Whiteout /boot
26count=$(df --sync -kP /boot | tail -n1 | awk -F ' ' '{print $4}')
27count=$(($count-1))
28dd if=/dev/zero of=/boot/whitespace bs=1M count=$count || echo "dd exit code $? is suppressed";
29rm /boot/whitespace
30
31set +e
32swapuuid="`/sbin/blkid -o value -l -s UUID -t TYPE=swap`";
33case "$?" in
34 2|0) ;;
35 *) exit 1 ;;
36esac
37set -e
38
39if [ "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";
46fi
47
48sync;