How to Prepare Vultr Marketplace Snapshots

Last Updated: Wed, May 26, 2021
Vultr Marketplace


After you've installed the required software, configured your application, and set up Marketplace Variables, we strongly suggest optimizing the server before making the snapshot. Some steps to consider are:

  • Remove old logs and temporary files.
  • Uninstall unneeded software.
  • Overwrite free disk sectors with zeros. This allows significant compression and makes customer deployment much faster.

👋 In addition to these optional steps, you must clean the cloud-init cache before taking the snapshot. Do not skip this step. It's near the end of this guide just before the final shutdown step.

You should adapt the suggested code snippets that follow based on your needs and your OS distribution.

Verify /tmp

Verify the /tmp directory exists and has the proper permissions.

# mkdir /tmp
# chmod 1777 /tmp

Update the Server

For yum-based distributions:

# yum update -y
# yum clean all

For apt-based distributions:

# apt-get -y update
# apt-get -y upgrade
# apt-get -y autoremove
# apt-get -y autoclean

Clean Temporary Files

Clean the temporary directories.

# rm -rf /tmp/*
# rm -rf /var/tmp/*

Clean SSH Keys.

# rm -f /root/.ssh/authorized_keys /etc/ssh/*key*
# touch /etc/ssh/revoked_keys
# chmod 600 /etc/ssh/revoked_keys

Clean the logs.

# find /var/log -mtime -1 -type f -exec truncate -s 0 {} \;
# rm -rf /var/log/*.gz
# rm -rf /var/log/*.[0-9]
# rm -rf /var/log/*-????????
# echo "" >/var/log/auth.log

Clean old cloud-init information.

# rm -rf /var/lib/cloud/instances/*

Clean the session history.

# history -c
# cat /dev/null > /root/.bash_history
# unset HISTFILE

Update mlocate

Update the mlocate database.

# /usr/bin/updatedb

Wipe Random Seed

Wipe the random seed file.

# rm -f /var/lib/systemd/random-seed

Wipe Machine ID

Distributions that use systemd should wipe the machine identifier to prevent boot problems.

# rm -f /etc/machine-id
# touch /etc/machine-id

Clear login History

Clear the login log history.

# cat /dev/null > /var/log/lastlog
# cat /dev/null > /var/log/wtmp

Wipe Free Space

Wipe unused disk space with zeros for security and compression.

# dd if=/dev/zero of=/zerofile
# sync
# rm /zerofile
# sync

Discard Unused Filesystem Blocks

Not all Linux distributions support fstrim, but you may consider running this final step before making the snapshot.

# fstrim /

Clean the cloud-init Cache

Before shutdown, the final step is to clean the cloud-init cache, which forces cloud-init to treat the next boot as the "first boot" for this image. You can read more about first boot determination in the cloud-init documentation.

# cloud-init clean

Halt and Power Down

Vultr can snapshot a running server, but you may prefer a clean shutdown. If so, consider halting and powering off the server before taking the snapshot.

# shutdown -h now

To power off:

  1. Click your server name in the customer portal to open the server information page.
  2. Click the Server Stop button in the upper left.

Make the Snapshot

  1. Navigate to the Add Snapshot page in the Vultr Customer Portal.
  2. Select your instance in the dropdown.
  3. Enter a descriptive label
  4. Click Take Snapshot.

Next Steps

After you've created your snapshot, add it to your Vultr Marketplace app as the live image.

More Information

These steps are also available as an example shell script on our GitHub repository.

This guide is part of the Vultr Marketplace documentation. Please see the documentation overview for more information.

Want to contribute?

You could earn up to $300 by adding new articles