Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce Linux box size by not packing a swap partition gubbish #281

Merged
merged 1 commit into from
Oct 17, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packer/freebsd-10.0-amd64.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"scripts/common/chef.sh",
"scripts/freebsd/cleanup.sh",
"scripts/freebsd/vmtools.sh",
"scripts/common/minimize.sh"
"scripts/freebsd/minimize.sh"
],
"execute_command": "export {{.Vars}} && cat {{.Path}} | su -m"
}
Expand Down
2 changes: 1 addition & 1 deletion packer/freebsd-10.0-i386.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"scripts/common/chef.sh",
"scripts/freebsd/cleanup.sh",
"scripts/freebsd/vmtools.sh",
"scripts/common/minimize.sh"
"scripts/freebsd/minimize.sh"
],
"execute_command": "export {{.Vars}} && cat {{.Path}} | su -m"
}
Expand Down
2 changes: 1 addition & 1 deletion packer/freebsd-9.3-amd64.json
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
"scripts/freebsd/vmtools.sh",
"scripts/common/chef.sh",
"scripts/freebsd/cleanup.sh",
"scripts/common/minimize.sh"
"scripts/freebsd/minimize.sh"
],
"type": "shell"
}
Expand Down
2 changes: 1 addition & 1 deletion packer/freebsd-9.3-i386.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
"scripts/freebsd/vmtools.sh",
"scripts/common/chef.sh",
"scripts/freebsd/cleanup.sh",
"scripts/common/minimize.sh"
"scripts/freebsd/minimize.sh"
],
"type": "shell"
}
Expand Down
8 changes: 8 additions & 0 deletions packer/scripts/common/minimize.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
#!/bin/sh -eux

# Whiteout the swap partition to reduce box size
# Swap is disabled till reboot
readonly swapuuid=$(/sbin/blkid -o value -l -s UUID -t TYPE=swap)
readonly swappart=$(readlink -f /dev/disk/by-uuid/"$swapuuid")
/sbin/swapoff "$swappart"
dd if=/dev/zero of="$swappart" bs=1M || echo "dd exit code $? is suppressed"
/sbin/mkswap -U "$swapuuid" "$swappart"

dd if=/dev/zero of=/EMPTY bs=1M
rm -f /EMPTY
# Block until the empty file has been removed, otherwise, Packer
Expand Down
7 changes: 7 additions & 0 deletions packer/scripts/freebsd/minimize.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/sh -eux

dd if=/dev/zero of=/EMPTY bs=1M
rm -f /EMPTY
# Block until the empty file has been removed, otherwise, Packer
# will try to kill the box while the disk is still full and that's bad
sync