Linux Sysprep Better May 2026

Run it as root, then capture the image from the powered-off VM. When you deploy from this image, pass cloud-init user-data:

echo "=== Sysprep complete. Shutting down for imaging. ===" shutdown -h now linux sysprep

On Linux, there is no sysprep command. There is no single magic incantation. And that leads to a dangerous misconception: "Linux doesn't need sysprep. Just clone the disk." Run it as root, then capture the image

#!/bin/bash set -e echo "=== Linux Sysprep - Generalizing System ===" find /var/log -type f -exec truncate -s 0 {} ; rm -rf /var/cache/* /tmp/* /var/tmp/* 2. Remove unique IDs echo -n > /etc/machine-id rm -f /var/lib/systemd/random-seed 3. Remove SSH host keys rm -f /etc/ssh/ssh_host_* 4. Remove network interface persistence rm -f /etc/udev/rules.d/70-persistent-net.rules rm -f /etc/network/interfaces.d/50-cloud-init.cfg # if using netplan 5. Clean package manager cache apt clean || yum clean all || dnf clean all 6. Remove shell history unset HISTFILE history -c find /home -name ".*history" -exec rm -f {} ; rm -f /root/.bash_history 7. Prepare for first-boot provisioning Ensure cloud-init is installed and enabled systemctl enable cloud-init 8. Remove udev hardware database (forces re-detection) rm -f /etc/udev/hwdb.bin ===" shutdown -h now On Linux, there is no sysprep command