Install guest additions, enable passwordless sudo for vagrant user, set root password to 'vagrant', clean/minimize the resulting image
This commit is contained in:
parent
11e58921d9
commit
178c887e83
22
packer.json
22
packer.json
|
@ -9,6 +9,28 @@
|
|||
"install -m0700 -o {{user `user`}} -g {{user `user`}} -d /home/{{user `user`}}/.ssh",
|
||||
"curl -SsL https://raw.githubusercontent.com/mitchellh/vagrant/master/keys/vagrant.pub -o /home/{{user `user`}}/.ssh/authorized_keys"
|
||||
]
|
||||
},
|
||||
{ "type": "shell",
|
||||
"execute_command": "{{ .Vars }} sudo -E -S sh '{{ .Path }}'",
|
||||
"inline": [
|
||||
"mount -o loop ${HOME}/VBoxGuestAdditions.iso /mnt",
|
||||
"/mnt/VBoxLinuxAdditions.run install",
|
||||
"umount /mnt",
|
||||
"rm ${HOME}/VBoxGuestAdditions.iso"
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "ansible",
|
||||
"playbook_file": "ansible/playbook.yml"
|
||||
},
|
||||
{ "type": "shell",
|
||||
"execute_command": "{{ .Vars }} sudo -E -S sh '{{ .Path }}'",
|
||||
"script": "scripts/clean.sh"
|
||||
},
|
||||
{
|
||||
"type": "shell",
|
||||
"execute_command": "{{ .Vars }} sudo -E -S sh '{{ .Path }}'",
|
||||
"script": "scripts/minimize.sh"
|
||||
}
|
||||
],
|
||||
"builders": [
|
||||
|
|
|
@ -40,5 +40,7 @@ d-i passwd/user-password password vagrant
|
|||
d-i passwd/user-password-again password vagrant
|
||||
d-i user-setup/allow-password-weak boolean true
|
||||
d-i user-setup/encrypt-home boolean false
|
||||
d-i passwd/user-default-groups vagrant sudo
|
||||
d-i passwd/user-uid string 900
|
||||
d-i preseed/late_command string \
|
||||
echo 'vagrant ALL=(ALL) NOPASSWD: ALL' > /target/etc/sudoers.d/vagrant ; \
|
||||
in-target chmod 440 /etc/sudoers.d/vagrant ;
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
#!/bin/sh -eux
|
||||
|
||||
# Delete all Linux headers
|
||||
dpkg --list \
|
||||
| awk '{ print $2 }' \
|
||||
| grep 'linux-headers' \
|
||||
| xargs apt-get -y purge;
|
||||
|
||||
# Remove specific Linux kernels, such as linux-image-3.11.0-15 but
|
||||
# keeps the current kernel and does not touch the virtual packages,
|
||||
# e.g. 'linux-image-amd64', etc.
|
||||
dpkg --list \
|
||||
| awk '{ print $2 }' \
|
||||
| grep 'linux-image-[234].*' \
|
||||
| grep -v `uname -r` \
|
||||
| xargs apt-get -y purge;
|
||||
|
||||
# Delete Linux source
|
||||
dpkg --list \
|
||||
| awk '{ print $2 }' \
|
||||
| grep linux-source \
|
||||
| xargs apt-get -y purge;
|
||||
|
||||
# Delete X11 libraries
|
||||
apt-get -y purge libx11-data xauth libxmuu1 libxcb1 libx11-6 libxext6;
|
||||
|
||||
# Delete obsolete networking
|
||||
apt-get -y purge ppp pppconfig pppoeconf;
|
||||
|
||||
# Delete oddities
|
||||
apt-get -y purge popularity-contest;
|
||||
|
||||
apt-get -y autoremove;
|
||||
apt-get -y clean;
|
||||
|
||||
# delete any logs that have built up during the install
|
||||
find /var/log/ -name *.log -exec rm -f {} \;
|
|
@ -0,0 +1,36 @@
|
|||
#!/bin/sh -eux
|
||||
|
||||
case "$PACKER_BUILDER_TYPE" in
|
||||
qemu) exit 0 ;;
|
||||
esac
|
||||
|
||||
# Whiteout root
|
||||
count=$(df --sync -kP / | tail -n1 | awk -F ' ' '{print $4}')
|
||||
count=$(($count-1))
|
||||
dd if=/dev/zero of=/tmp/whitespace bs=1M count=$count || echo "dd exit code $? is suppressed";
|
||||
rm /tmp/whitespace
|
||||
|
||||
# Whiteout /boot
|
||||
count=$(df --sync -kP /boot | tail -n1 | awk -F ' ' '{print $4}')
|
||||
count=$(($count-1))
|
||||
dd if=/dev/zero of=/boot/whitespace bs=1M count=$count || echo "dd exit code $? is suppressed";
|
||||
rm /boot/whitespace
|
||||
|
||||
set +e
|
||||
swapuuid="`/sbin/blkid -o value -l -s UUID -t TYPE=swap`";
|
||||
case "$?" in
|
||||
2|0) ;;
|
||||
*) exit 1 ;;
|
||||
esac
|
||||
set -e
|
||||
|
||||
if [ "x${swapuuid}" != "x" ]; then
|
||||
# Whiteout the swap partition to reduce box size
|
||||
# Swap is disabled till reboot
|
||||
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";
|
||||
fi
|
||||
|
||||
sync;
|
Loading…
Reference in New Issue