How to Build an Image from a Snapshot

Updated on 05 August, 2026

Build a Vultr Marketplace application image from an instance snapshot using the Vultr Console or Vultr API to package a configured server as your app.


Building from a snapshot means you pre-install your application on a server, set up post-deployment scripts, and take a snapshot of the disk image. When customers deploy your app, they get your snapshot, and cloud-init runs your scripts. Prefer building from Vendor Data when your application supports it, since it avoids maintaining a snapshot.

This guide explains how to prepare a server and build an image from its snapshot using the Vultr Console or the Vultr API.

  • Vultr Console
  • Vultr API

To open the snapshot selector, click Marketplace in the Vultr Console's left-hand menu, click the application name, click the Builds tab, then click the Build From Snapshot button to switch from the default Vendor Data view.

Optimize the server before you take the snapshot:

  • Design your app for the marketplace-2c-2gb plan, which is optimized for Marketplace applications. This plan includes 2 vCPUs, 2 GB of memory, and 8 GB of storage.
  • 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.

Adapt the following code snippets to your needs and your OS distribution. These steps are also available as an example shell script in our GitHub repository.

Verify the Temporary Directory

  1. Create the /tmp directory if it doesn't already exist.

    console
    # mkdir /tmp
    
  2. Set the proper permissions on the directory.

    console
    # chmod 1777 /tmp
    

Update the Server

  • For yum-based distributions:

    1. Update installed packages.

      console
      # yum update -y
      
    2. Clean the package cache.

      console
      # yum clean all
      
  • For apt-based distributions:

    1. Refresh the package index.

      console
      # apt-get -y update
      
    2. Upgrade installed packages.

      console
      # apt-get -y upgrade
      
    3. Remove packages that are no longer needed.

      console
      # apt-get -y autoremove
      
    4. Clean the package cache.

      console
      # apt-get -y autoclean
      

Clean Temporary Files

  • Clean the temporary directories.

    • Clean /tmp.

      console
      # rm -rf /tmp/*
      
    • Clean /var/tmp.

      console
      # rm -rf /var/tmp/*
      
  • Clean SSH keys.

    1. Remove the authorized keys and existing host keys.

      console
      # rm -f /root/.ssh/authorized_keys /etc/ssh/*key*
      
    2. Create an empty revoked keys file.

      console
      # touch /etc/ssh/revoked_keys
      
    3. Set the proper permissions on the revoked keys file.

      console
      # chmod 600 /etc/ssh/revoked_keys
      
  • Clean the logs.

    • Truncate logs modified in the last day.

      console
      # find /var/log -mtime -1 -type f -exec truncate -s 0 {} \;
      
    • Remove compressed log archives.

      console
      # rm -rf /var/log/*.gz
      
    • Remove numbered rotated logs.

      console
      # rm -rf /var/log/*.[0-9]
      
    • Remove date-stamped rotated logs.

      console
      # rm -rf /var/log/*-????????
      
    • Clear the auth log.

      console
      # echo "" >/var/log/auth.log
      
  • Clean old cloud-init information.

    console
    # rm -rf /var/lib/cloud/instances/*
    
  • Clean the session history.

    1. Clear the current shell session's history.

      console
      # history -c
      
    2. Clear the saved history file.

      console
      # cat /dev/null > /root/.bash_history
      
    3. Unset the history file variable so nothing is written back to it before the snapshot.

      console
      # unset HISTFILE
      

Update mlocate

Update the mlocate database.

console
# /usr/bin/updatedb

Wipe Random Seed

Wipe the random seed file.

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

Wipe Machine ID

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

  1. Remove the existing machine ID. Some distributions keep a separate copy at /var/lib/dbus/machine-id instead of symlinking it to /etc/machine-id, so remove both.

    console
    # rm -f /etc/machine-id /var/lib/dbus/machine-id
    
  2. Create an empty replacement file. systemd generates a new machine ID the next time the system boots.

    console
    # touch /etc/machine-id
    

Clear Login History

  • Clear the last login log.

    console
    # cat /dev/null > /var/log/lastlog
    
  • Clear the login/logout record.

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

Wipe Free Space

Wipe unused disk space with zeros for security and compression.

  1. Fill the free space with a zeroed file.

    console
    # dd if=/dev/zero of=/zerofile
    

    The command runs until the disk is full and exits with a No space left on device error. This is the expected result.

  2. Flush the write to disk.

    console
    # sync
    
  3. Remove the zeroed file.

    console
    # rm /zerofile
    
  4. Flush the deletion to disk.

    console
    # sync
    

Discard Unused Filesystem Blocks

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

console
# fstrim /

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.

console
# shutdown -h now

To power off:

  1. Click your server name in the Vultr Console 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 Console.

  2. Select your instance in the dropdown.

  3. Enter a descriptive label.

  4. Click Take Snapshot. Wait a few minutes for the snapshot to complete.

  5. Click Marketplace in the left-hand menu, then click the application name.

  6. Click the Builds tab.

  7. Select the snapshot image you just created.

  8. Click Build App Image. The Vultr Marketplace takes your snapshot and builds it into an App Image.

Send a POST request to the Create Marketplace App Build Image endpoint with use_vendor_data set to false. Replace {app-id} with the app's ID and SNAPSHOT-ID with the ID of the snapshot you prepared.

console
$ curl "https://api.vultr.com/v2/marketplace/apps/{app-id}/builds" \
    -X POST \
    -H "Authorization: Bearer ${VULTR_API_KEY}" \
    -H "Content-Type: application/json" \
    -d '{
        "use_vendor_data": false,
        "snapshot_id": "SNAPSHOT-ID"
    }'

A successful request returns an HTTP 201 Created response with the build's marketplace_image_id.

Comments