The most popular open source tool for that purpose for bare metal hardware is probably Clonezilla. https://clonezilla.org/
There are other ways to do it. I’ve often just used dd
in the past, though things have gotten weirder with UEFI booting and partitioning and volumes and such.
These days (at my day job I maintain a large fleet of devices, but not web servers and they have a somewhat more complicated bringup process as they’re tied to hardware that has to be calibrated to the specific devices attached), I prefer to make a custom installer. I was using this tool, with some customizations: GitHub - linuxrrze/ubuntu-24.04-autoinstall-generator: Generate a fully-automated Ubuntu ISO for unattended installations.
But, Ubuntu has, once again, broken bundling custom packages into the image and the newer autoinstall features in Ubuntu suck. So, I’m not really happy with my options. I don’t consider Clonezilla a suitable option (though it is for many people), as it requires you to install and configure the OS, and then make a clone of it, all a manual process, subject to user error. Also time-consuming. I need something I can check into git, so I can track changes, and never rely on a human doing the work. You could write an postinstall script that you run after OS installation that removes most of the variables, but that’s still pretty clunky, IMHO. But, if you only need to do it every few months or whatever, it’s no big deal.
Note that cloud-init also allows customizations at first boot time (and subsequent boots), so that may also be a suitable option for getting a fresh OS virtual machine image into a suitable state.
For virtual machines and containers, I’ve used Hashicorp Packer. That is, IMHO, the most reasonable way to do things (works from a config file, can be checked into git, reproducible without human error), but it doesn’t support making a bootable installer ISO for bare metal, which is a requirement for my use case (and maybe not yours, you didn’t mention if you’re dealing with hardware or virtual machines, the latter is much simpler to contend with and there are better tools for the job).