Saturday, May 9, 2026

Ubuntu Server Best Practice for image cloning

When you use some kind of virtualization platform like VMware vSphere. VMware Workstation, VMware Fusion, Oracle Virtual Box, you name it, then Virtual Machine cloning is a big thing and operational simplification.

In this blog post I document best practice for image cloning of Ubuntu Server.

1. Install Ubuntu server

Install Ubuntu including applications you would like to have in your Golden Image.

2. Delete machine-id 

sudo truncate -s 0 /etc/machine-id
sudo rm -f /var/lib/dbus/machine-id 

3. Delete SSH host keys

sudo rm -f /etc/ssh/ssh_host_*

4. Clean cloud-init

sudo cloud-init clean --logs

5. Clean system logs

sudo journalctl --rotate
sudo journalctl --vacuum-time=1s

6. Clean temporary data

sudo rm -rf /tmp/*

7. Shutdown system

sudo shutdown -h now

Conclusion

You can use all cleaning commands together, create your golden image and always start from that point. 
 
# switch to shell as a root 
sudo /bin/sh
 
# run all cleanings ...
truncate -s 0 /etc/machine-id
rm -f /var/lib/dbus/machine-id 
rm -f /etc/ssh/ssh_host_*
cloud-init clean --logs
journalctl --rotate
journalctl --vacuum-time=1s
rm -rf /tmp/*
 
# shutdown the system to have golden image 
shutdown -h now 

Such batch  of commands should anonymize the system and it is a good practice for using system image cloning.

Hope you enjoy it.

 

 


 

 

No comments:

Post a Comment

Kubernetes and Helm Chart Applications

A Helm chart is a packaging format for Kubernetes, acting as a blueprint to define, install, and upgrade complex applications. It bundles m...