The best would be NixOS, but if you just want to automate your install which you have then Ansible.
Linux
From Wikipedia, the free encyclopedia
Linux is a family of open source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991 by Linus Torvalds. Linux is typically packaged in a Linux distribution (or distro for short).
Distributions include the Linux kernel and supporting system software and libraries, many of which are provided by the GNU Project. Many Linux distributions use the word "Linux" in their name, but the Free Software Foundation uses the name GNU/Linux to emphasize the importance of GNU software, causing some controversy.
Rules
- Posts must be relevant to operating systems running the Linux kernel. GNU/Linux or otherwise.
- No misinformation
- No NSFW content
- No hate speech, bigotry, etc
Related Communities
Community icon by Alpár-Etele Méder, licensed under CC BY 3.0
Came here to say this. I don't like NixOS but it literally excels at reproducibility, and Ansible is easy enough to start with most "classic" distros.
You should have a look at NixOS. It's a Linux distro where you declare the whole system in configuration like files, in a language called Nix (hence NixOS), then you run a command and that gets resolved into your system.
It takes a long time to setup the first time, but it's a breeze when you need to reinstall, and you will never need to reinstall as every boot is a fresh copy of the system you declared.
There's also a thing called home-manager which uses the Nix language to declare your home configuration. That part can be used in any other Linux by installing the home-manager package.
You can declare your OS in a way that the home part is portable for machines running other systems. I do that, then my machines are very easy to declare, and with some groups for things like Base (Terminal, prompt, some things I expect to have on every system like Python, nvim fully configured, etc), Gaming (Steam mostly), UI (Sway, many GUI things I use like browser with extensions, etc) I can add configs for a new machine in instants depending on what I expected for it, and if I ever want to convert my "Steam machine" into a desktop it's just a couple line changes, regenerate the config and it's exactly the same as my laptop.
Honestly I don't think Nix is for everyone, but it's a very niche thing that works extremely well for what it sets up to do, and if you're in the target audience it's a game changer.
I love NixOS but I wouldn't commend it to people who are at a point in their sysadmin trajectory where they haven't heard of Ansible. (It's not just that Nix has a learning curve, it's that you're seriously screwed if you can't tell the difference between a Nix problem and a regular package / kernel issue.)
OP, use Ansible.
Yeah, I can see that. But I don't think that knowing Ansible will teach you that difference. OP seems to know enough about Linux to be comfortable so I would expect him to be able to distinguish between those.
I agree that Nix has a steep learning curve and it's not for everyone, but OP specifically asked for a way to declare their system, and Ansible doesn't work for something you'll setup now to use in 6 months when you decide to reinstall the system, because the best case scenario is you get your system as it was 6 months ago, but more realistically it doesn't work and you have to spend time fixing it or doing it manually.
Don't get me wrong, Ansible is great, I manage my home server with it, but if I go a while without running the pipeline when I do it rolls back several changes I made manually to test and forgot to consolidate. Nix is annoying because it forces you to declare everything every time, but you're guaranteed to get the same result you have now, which is very important for the case OP asked about.
Skip Ansible (IMO). Bit of a hole and slow, pain to write and debug (slow cycles).
Bite the bullet learn the hard right thing, nixos.
I have never in my life touched Ansible and daily drive NixOS on servers and desktop. +1 to skipping Ansible
NixOS
I frequently reinstall Linux.
Like, how many times in a year? And secondly, for what reason?
Usually if I've made a mess with installs or config and want a clean slate, but this time I'm doing it cos I tried out a new OS and it didn't work out.
Hard to say exactly, how much, maybe twice a year, but when I do reinstall I often reinstall like three times in quick succession until I get a good foundation.
Aight. Understood. Thank you!
In your case, I'd propose something like NixOS then. As your full system configuration can be contained within a (set of) config file(s), the very same ones you use to install/config stuff, a reinstall just becomes very easy. Heck, if you're willing to embrace the "Erase your darlings"-lifestyle, then I don't even think you'd ever feel the need for a reinstall. Because, frankly, the clean slate is just a reboot away.
EDIT: Perhaps Guix System is also worth considering as an alternative to NixOS*.
EDIT2: If you still want to explore other distros, then it's worth noting that nix, i.e. NixOS' package manager, is available on most distros and offers a lot of the benefits already. Like, you could configure your system using it, and then use that config on another distro to get your config back. Good stuff.
Why don't you try distros in a virtual machine first?
I do, but something about it doesn't feel right. Maybe I'm just not committing to it cos I can too easily jump back to the host OS
To be fair, testing in a VM is for seeing the basic fundamentals of the OS. Ok, let me try to help with a couple of things then.
For finding you distro:
- Find your favourite environment. Is it GNOME, is it KDE, Cinnamon, maybe it's Xmonad or dwm? There are a lot of these and you should test this first. Distro doesn't really matter in this step. Just find one with the desired environment and test it in a VM.
- Once you find your perfect environment, find out if you want a really stable system or something cutting edge? Maybe something balanced in between. Distro still doesn't matter in this step. Once you decide what you want, now you can find distros that suit this.
- Choose you favourite init system (Optional). Some people like to control what's under the hood. Just note that, not choosing systemd will filter a lot of distros here. If you don't care what's under the hood, skip this step.
- Now you have narrowed down to possibly 3-10 distros. Still a lot. However this step is where you choose your favourite package manager. If you don't care about the mechanism, just pick one you liked from the default installations of them. If you are using Linux for some time, you might already have a favourite package manager.
- Congratulations, you have found your distro. Just use it and see for yourself.
- Wait, it might still not be the correct one. However you cannot know this without using them daily. Some people stay with what distro they start, some people distrohop a lot and settle on Debian. And some other love their niche distro that works nicely for them. Stay with what really clicks with you.
If you want to learn a new tool, look at Ansible. If you just want to get the job done, make a list of the packages you need and track your dotfiles.
If a debian based distro there's several ways to copy your package choices from one machine to another, the likes of using dpkg --get-selections and using that output on the new machine with --set-selections, but probably the easiest way is to use apt-clone, which streamlines that process to install the same packages on the new machine.
As for your firefox and desktop packages, they'll be saved in /home/username (usually in .hidden dirs) - so just copy all of that over.
Alternatively, use an image cloner like clonezilla to make an exact disk copy and install that.
Or run your machine as a vm inside Proxmox or another hypervisor. That way you can have instant snapshots before you do risky things, as well as multiple scheduled entire-machine backups.
Or ansible (which I do a lot of), which can set whatever packages and copy your golden-image files over as you want. (But keeping those up to date requires a little thought)
Ansible, Salt, Puppet, Chef, Terraform, …
imo, the best solution for this is easily NixOS explicit reproducible system configuration
Fedora offers kickstart.
Others have cloudinit or ignition.
Those are the ones if used personally.
GuixSD is another distro that allows you to keep a reproducible config file from which reinstall everything from base to apps to dotfiles.
The con is that it can feel a bit alien compared to other distros.
There are communities on Lemmy about it:
There's always pyinfra.
However. The easiest solution is probably a custom shell script that checks which OS it is and does different things based on that. It doesn't have to pretty as long as it works for you.
Edit: Why do you keep reinstalling your operating system?
This is why we put /home on a separate partition for reuse on new installs. It saves your users' files. Your steam, WM, Firefox config, even document files are already basically portable between installs.
And in those files, we may as well put a bash script that does your pacman/apt/dnf/emerge/yay for the everything. This could be easy like with Gentoo or a PITA like with Debian to just scrape from the system right before migration.
Firefox is weird when you hop between distros. Some distros use the LTS (long term stable) version, others use the normal Stable branch... Does Debian still maintain an IceWeasel fork of Firefox? This means you may want to manually copy a folder to a backup location to manually slot it in after the distro-hop. Either way, you want to download a popular privacy-focused user.js file from Github ;)
Good point
I think the Archinstall script (that is part of the official Arch iso) can save the configuration, to reinstall with same setup again. But it does not go into details like your Firefox environment. Its there to setup the basic installation and eventually additional packages.
guix is pretty useful. You can install it on top of any distro, feed it the declaration of your desired set-up and it will reproduce it everytime
+1 for ansible
I use two tools for this:
- https://www.chezmoi.io/ for all my various dotfiles
- A bash script I’ve put together over the years that has a list of all the basics that I want and calls whatever the right installer is for them: apt, cargo, brew, or whatever. It has targets for a local workstation, a remote headless server, and MacOS. Then at then the end it runs chezmoi.
Now, my use case is less “constant fresh install” and more “keep my environment the same across various devices”, as I mostly run Debian Stable and don’t feel the need to constantly tweak things.
I think the most optimal way of doing this would be a self-made shell script that expresses your preferences. You could then run it from whatever live-environment you choose and the result would be a familiar setup. The /home directory being on a separate partition from the rest is useful for preserving large-quantities of user-data.
I've been impressed with the capacity of microSD cards. The idea of mounting /home to a microSD card and having a materially-portable home has been a novelty I've so far resisted.
I had found myself reinstalling and reconfiguring a lot of the same things over and over while distro hopping, so I came up with a bash script with some of the most common configuration changes and such. As an example, here is my Fedora post=install script:
script
#!/usr/bin/env bash
# remove all permission restrictions from current directory
#sudo chmod -R a+rwX .
sudo hostnamectl set-hostname [redacted]
# prompt for ssh password to use later
if [[ $1 == "" ]]; then
read -p "Enter ssh password: " ssh_pass
else
ssh_pass=$1
fi
# default dnf prompts to 'y'
sudo sh -c "echo 'defaultyes=True' >> /etc/dnf/dnf.conf"
# install packages that are needed to add repos and other packages
sudo dnf up -y && sudo dnf in curl flatpak wget -y
#add repos
sudo dnf copr enable lilay/topgrade -y
sudo dnf copr enable aflyhorse/libjpeg -y
sudo dnf config-manager addrepo --from-repofile=https://repository.mullvad.net/rpm/stable/mullvad.repo
sudo dnf in https://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-$(rpm -E %fedora).noarch.rpm -y
sudo dnf in https://download1.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-$(rpm -E %fedora).noarch.rpm -y
sudo sh -c 'curl -fsSL https://repo.librewolf.net/librewolf.repo | pkexec tee /etc/yum.repos.d/librewolf.repo'
sudo flatpak remote-add --if-not-exists flathub https://dl.flathub.org/repo/flathub.flatpakrepo
echo -e "[gitlab.com_paulcarroty_vscodium_repo]\nname=gitlab.com_paulcarroty_vscodium_repo\nbaseurl=https://paulcarroty.gitlab.io/vscodium-deb-rpm-repo/rpms//nenabled=1/ngpgcheck=1/nrepo_gpgcheck=1/ngpgkey=https://gitlab.com/paulcarroty/vscodium-deb-rpm-repo/raw/master/pub.gpg/nmetadata_expire=1h" | sudo tee -a /etc/yum.repos.d/vscodium.repo
#install packages
sudo dnf in augeas-devel btop cairo-devel cairo-gobject-devel cargo cmake codium dbus-devel expat-devel gifsicle gimp git kde-connect kdenlive libavcodec-freeworld librewolf libxkbcommon-devel lightdm-gtk-greeter-settings mpv mullvad-vpn ninja-build openssh-server openssl openssl-devel pipx python3-dbus python3-devel python3-pip rpmbuild syncthing thunderbird topgrade vlc sshpass -y
sudo dnf in $(curl -s https://raw.githubusercontent.com/teervo/bitwig-fedora/refs/heads/main/bitwig-rpm.sh | bash -s 4.4.10) -y
sudo dnf swap ffmpeg-free ffmpeg --allowerasing -y
export PATH="$HOME/.cargo/bin:$PATH" && echo $'export PATH= \"$HOME/.cargo/bin:$PATH \"' >> ~/.bashrc
cargo install gifski cargo-updateflatpak install com.github.iwalton3.jellyfin-media-player -y
#pipx install numlockw
pip install pandas odfpy
#create ssh key, copy to servers
ssh-keygen -q -t rsa -N '' <<< $'\ny' >/dev/null 2>&1
hosts=("10.0.0.10" "10.0.0.11")
for host in "${hosts[@]}"; do
ssh-keyscan -H $host >> ~/.ssh/known_hosts && sshpass -p "$ssh_pass" ssh-copy-id -o StrictHostKeyChecking=no [redacted]@$host && ssh -q [redacted]@$host exit
done
#enable/start ssh server
sudo systemctl enable sshd
sudo systemctl start sshd
#add external drive to fstab to automount
directory_secondary_drive=$HOME/nvme
uuid=[redacted]
sudo blkid
sudo cp /etc/fstab /etc/fstab.bak
sudo sh -c "echo 'UUID=$uuid $directory_secondary_drive btrfs rw,auto,user,exec 0 0' >> /etc/fstab"
sudo mount -a
#copy over custom config files
directory_software=$directory_secondary_drive/sync/software
cp -r $directory_software/setup/configs/* $HOME/.local/share/
#install fonts
cp $directory_software/fonts/* $HOME/.fonts
fc-cache -vf
#set git credentials
git config --global user.name "[redacted]" && git config --global user.email "[redacted]@yourdomain.com"
#add aliases to bashrc
echo $'alias pipup=\'pip list -o | cut -f1 -d\'\\\'\' \'\\\'\' | tr " " " " | awk \'\\\'\'{if(NR>=3)print}\'\\\'\' | cut -d\'\\\'\' \'\\\'\' -f1 | xargs -n1 pip install -U\'' >> ~/.bashrc
echo $'alias up=\"topgrade -y && echo \'\\nChecking pip\\n\' && pipup\"' >> ~/.bashrc
echo $'alias e=\"exit\"' >> ~/.bashrc
#https://support.mozilla.org/en-US/kb/compact-mode-workaround-firefox
#print ssh key
echo $'\nPublic SSH key:'
cat $HOME/.ssh/*.pub
Note that I used [redacted] here in places for anonymity reasons. This could give you a decent starting point to do something similar.
There is a lot but I think you will find a lot of them more enterprise focused rather than consumer. For apps installed to home, why aren't you preserving your /home partition? For system apps, could you create an image? (Although it should be basically a one liner?) There is a lot of missing detail, why are you reinstalling, what distribution(s)?
It's probably better to write a script in a repo that downloads and installs everything..
Then for configuration files create a dotfiles repo. I use chezmoi but there are a bunch of solutions for this.
bootc image
I've started creating an ansible playbook. I've added flatpaks, os specific packages, Firefox extensions, samba Mount point services in there. As of now I use it for PC (Ubuntu) and laptop (Fedora) only 3 is packages needed separate names. I'll have a look at tuxmate as suggested in other post but just running playbook once every week also does update.
The canonical method was with a kickstart, and if it looks like too complex, remember you should have one stashed in /root already that you just need to mod.
Normally a kickstart is a bit much, otherwise, though. I use a suite of tools but the best one I used was a simple virtual package to bring in the others, drop configs in and start daemons. We did this in like 2001 to great effect.
Their are a load of ways to do this. I have seen some good once posted already like Ansible. But to give you some more options. Their is also imaging. You setup a system how you like and clone it essentially. A good tool for that is a fog server. Works cross platform too.
I'm now trying out SUSE microOS for my mini servers. These are initially setup via combustion / ignition. you add these scripts to a usb stick and insert them during the first boot where they initialize fhe system. As far as I saw, at least ignition is quite open and supported by most distros
all configuration management languages do this and have forums where people share their code so that you copy/paste and then tweak them to your own needs. ansible galaxy comes to mind.
if you want pure linux, there's also kickstart or preseed.
It’s possible to create a custom Linux ISO. That will solve the application installation problem.
There are several tools. Ansible is an excellent cross platform tool for provisioning systems. I use it to manage packages, users, network and firewall configs, etc. across several systems.
Not a full reinstall solution, but aptik is one of the only utilities I've found useful enough to pay for. Last time I reinstalled it saved me many hours of configuring.