Contents
Notes on how to create a Vagrant image
This is about VirtualBox only so far.
Also see Vagrant.
Local
Use Mageia 8 DVD ISO to install Linux on a virtual machine named "merlin" for instance.
Since this is a cloud image, I do not select GUI and uncheck most of the default items.
Then :
vagrant package --base merlin --output merlin.box md5sum merlin.box b95ab1272f18ccccccccccccffddc9fc merlin.box vagrant box add --checksum-type md5 --checksum b95ab1272f18ccccccccccccffddc9fc --name merlin merlin.box
You can then use it on your local machine with name "merlin"
mkdir mymerlintest cd mymerlintest vagrant init merlin vagrant up
Cloud
In order to make your image available to everyone, you need to create an account and log into https://app.vagrantup.com
And provide a name like <your account name>/<box name>
Then you can upload the box file.
Inside
Here are some hints and details on what to do, so that "vagrant up" ends with success.
Enable sshd
# dnf install openssh openssh-server # systemctl enable sshd.service # update-crypto-policies --set LEGACY
Last command is to be compatible with Vagrant 2.2.9
sudoers.d
Having a file to allow Vagrant to switch to root without password:
# usermod -a -G wheel vagrant # id vagrant uid=2012(vagrant) gid=2012(vagrant) groupes=2012(vagrant),10(wheel) # cat /etc/sudoers.d/wheeler %wheel ALL=(ALL) NOPASSWD: ALL
Cleanup script
Here is a script to reduce image size (https://github.com/boxcutter/centos/blob/master/eol/script/cleanup.sh)
#!/bin/bash -eux echo "==> Clear out machine id" rm -f /etc/machine-id touch /etc/machine-id DISK_USAGE_BEFORE_CLEANUP=$(df -h) echo "==> Clean up dnf cache of metadata and packages to save space" dnf -y --enablerepo='*' clean all echo "==> Removing temporary files used to build box" rm -rf /tmp/* echo "==> Rebuild RPM DB" rpmdb --rebuilddb rm -f /var/lib/rpm/__db* # delete any logs that have built up during the install find /var/log/ -name *.log -exec rm -f {} \; echo '==> Clear out swap and disable until reboot' 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 echo '==> Zeroing out empty area to save space in the final image' # Zero out the free space to save space in the final image. Contiguous # zeroed space compresses down to nothing. dd if=/dev/zero of=/EMPTY bs=1M || echo "dd exit code $? is suppressed" 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 echo "==> Disk usage before cleanup" echo "${DISK_USAGE_BEFORE_CLEANUP}" echo "==> Disk usage after cleanup" df -h