The officially official Devuan Forum!

You are not logged in.

#1 2025-10-12 17:49:55

dchmelik
Member
Registered: 2024-04-28
Posts: 11  

cloning/template installation

My family has three Devuan PCs and will get a fourth rebuilt.  I also have four Debian virtual private servers (VPS) which unfortunately run in something such as OpenVZ with systemd so didn't work to convert to SysVInit and still be able to reboot properly (did work for daemons while they were up)... bot those VPS are mostly off-topic; just saying I use Debian for some serious uses since maybe 1999 when it was still how Devuan is now, such as for workstations for computer programming/science (CS) and servers.

I have a set of configuration files I use for family PCs such as /etc/pam.d/common-auth, /etc/sudoers, /etc/default stuff, /etc/passwd, /etc/group, some /etc/apt*, /etc/inittab, /etc/inetd.conf, /etc/nanorc, /etc/screenrc, /etc/hosts template, /etc/resolv.conf, /etc/dhcp/dhclient-enter-hooks.d, /etc/aliases, /etc/rc.local* & /etc/profile.d files (my own environment.sh, functions.sh though were for bash), /var/spool/cron/crontabs, /usr/local/{bin|lib}, /etc/X11, etc.  I was pretty disappointed our 101-key IBM model M keyboards were undetected: you assumed 104-key/Windows so I needed /etc/default/keyboard, but I also have /etc/default/grub for improvements including reasonable/non-hurried boot time.

Are there any other configuration files you'd suggest?  I know some are in /var, which leads to something else.

I've been trying to use AMD's OpenCL on these PCs.  Often amdgpu-install works once on a PC but if the driver doesn't work so you have to uninstall & reinstall older, it no longer installs or sometimes might then doesn't work--network problem?  Might take some tens minutes or hours or just another day/week until any version installs again.  What I found is rsyncing /*bin, /etc (after backup like fstab, files containing hostname), /lib*, /opt, /srv, /usr, /var from another Devuan workstation/server fixes this and immediately makes OpenCL installed and working.  Is there a 'right' way to do this, like I know some configuration is also in /var or maybe some machine-specific files are installed elsewhere?  It'd also be a way one might quickly copy a Devuan install from an old to new PC without having to do an entire new installation.

Two the workstations--now more servers--I do this with are identical hardware except slightly different multi-function hubs (media dashboards for memory card readers, USB, audio, eSATA, molex power, etc.) though I was careful to not rsync /boot (despite they don't boot UEFI) or various specific/system stuff (/dev, /proc, /run, /sys, /tmp).  I'd guess anything different these two have is in /lib/modules and part of the main kernel packages anyway: I didn't install any additional firmware (well, likely main package, but didn't choose individual firmware packages) just some might get loaded (happens somewhere else?) in each but not the other.

Suppose those two are exactly the same, or if two have slightly different CPU, system-/logic-/main-/mother-board or peripherals, if you have preset/template configuration but want to save time by rsyncing, what's the right way to do this: stuff to omit or add or edit or look out for?  In /etc I just did 'grep -ir hostname *' for the hostname and it was quick, easy to fix, but configuration elsewhere (/var?) is another matter (might take hours to grep)... if you try this, however make sure to backup /etc/fstab and all /etc/* containing hostname and restore before any rebooting.  If you don't, the reboot process will halt, and you have to remount '/' rw and restore fstab, and you may have hostname/network issues.  No big deal but on one of several occasions I made this mistake, which if someone is new to this process might feel a bit intimidating (for an old UNIX user it was all kind of obvious).

When the installation CD/DVD is relatively small but we download some GB other packages, and instead of editing all configuration by hand on each new installation, I prefer presets/template for those, and in the case of something such as OpenCL no longer completing installation, then I find cloning with rsync to be easiest instead of trying for days and not being able to number-crunch for Berkeley Open Infrastructure for Network Computing (BOINC) for science until later.

Last edited by dchmelik (2025-10-12 18:11:43)

Offline

#2 2025-10-12 22:53:50

RedGreen925
Member
Registered: 2024-12-07
Posts: 181  

Re: cloning/template installation

It'd also be a way one might quickly copy a Devuan install from an old to new PC without having to do an entire new installation.

In my backup script I use I have this for the main backup of root.

# Snyc/Copy the / directory.
		rsync -ahPHAXx --delete --exclude={/boot/efi/*,/dev/*,/proc/*,/sys/*,/tmp/*,/run/*,/mnt/*,/media/*,/swapfile,/lost+found} / /tmp/root/
		echo "Completed Sync/Copy to /tmp/root directory used for root files backup"

That is run to copy to external usb drive which then get booted on the machine it will be installed on. An example of the files copied to the external drive.

6)
		# Backup the install to the Intel_Spare drive for use in my spare machine full install with extra directories mounted on HD & NVMe drive
		cp /root/bin/EFI_intel_grub.cfg /tmp/efi/EFI/debian/grub.cfg
		cp /root/bin/boot_intel_grub.cfg /tmp/root/boot/grub/grub.cfg
		cp /root/bin/intel_fstab_spare /tmp/root/etc/fstab
	;;

As you can see it is option number six of sixteen in that script which backs up to various drives and machine they will be booted on. Including cloning to the internal boot drive on the machines. I have quite the number of files used in this procedure depending on the machine involved. In addition there are sections in the script that solve the hostname problem.

# For changing the host name

HNAME=$(hostname)

echo "The host name is currently ""$HNAME"
read -r -p  "Change it to another name? (y/n)? " choice

case "$choice" in

	y|Y )

		# Get new host name
		read -r -p "Enter new hostname " newNAME
		sed -i "s/$HNAME/$newNAME/g" /tmp/root/etc/hostname
		sed -i "s/$HNAME/$newNAME/g" /tmp/root/etc/samba/smb.conf

		# If 8400 hostname machine
		if  [ $newNAME == 8400 ]; then
			cp /root/bin/etc_hosts_8400 /tmp/root/etc/hosts
			echo "Copied /root/bin/etc_hosts_8400 to /tmp/root/etc/hosts"
			cp /root/bin/gkrellm_user-config_8400 /tmp/home/$USER/.gkrellm2/user-config
			cp /root/bin/gkrellm_sensor-config_8400 /tmp/home/$USER/.gkrellm2/sensor-config
			chown $USER:$USER /tmp/home/$USER/.gkrellm2/user-config
			chown $USER:$USER /tmp/home/$USER/.gkrellm2/sensor-config
			echo "Copied /root/bin/gkrellm_user-config_8400 to home directory"
			echo "Copied /root/bin/gkrellm_sensor-config_8400 to home directory"
			cp /root/bin/rtorrent-rc_8400 /tmp/home/$USER/.rtorrent.rc
			chown $USER:$USER /tmp/home/$USER/.rtorrent.rc
			echo "Copied /root/bin/rtorrent-rc_8400 to home directory"
			rm /tmp/root/etc/rc0.d/K01apcupsd
			rm /tmp/root/etc/rc1.d/K01apcupsd
			rm /tmp/root/etc/rc2.d/S03apcupsd
			rm /tmp/root/etc/rc3.d/S03apcupsd
			rm /tmp/root/etc/rc4.d/S03apcupsd
			rm /tmp/root/etc/rc5.d/S03apcupsd
			rm /tmp/root/etc/rc6.d/K01apcupsd
			echo "Removed apcupsd init.d startup/shutdown files"
			rm /tmp/root/etc/rc0.d/K01rtorrent
			rm /tmp/root/etc/rc1.d/K01rtorrent
			rm /tmp/root/etc/rc2.d/S03rtorrent
			rm /tmp/root/etc/rc3.d/S03rtorrent
			rm /tmp/root/etc/rc4.d/S03rtorrent
			rm /tmp/root/etc/rc5.d/S03rtorrent
			rm /tmp/root/etc/rc6.d/K01rtorrent
            echo "Removed rtorrent init.d startup/shutdown files"
		fi

There you can see in this section what is to be done for the machine 8400 I change the hostname in the three places it needs to be done. Copy over the gkrellm config files for the machine, the rtorrent.rc while at the same time disabling the started of the rtorrent and the apcupsd. As those are not needed on startup on that machine but can be used if necessary. Since all my machines are efi booting I also have section in there for it too.

		# remove files on /tmp/efi gets only the files present on the install.
		rm -r /tmp/efi/*
		echo "efi directory now empty"
		# Snyc/Copy the efi directory.
		scp -r /boot/efi/* /tmp/efi/
		echo "Completed Sync/Copy to /tmp/efi directory used for efi files backup"

The machine specific file for the efi is copied in its drive section to be set by it so it will boot. I also have separate home partition I backup this uses a file I found years ago to stop my rsync from including things it should not be.

root@9600k:~# cat /usr/local/bin/rsync-homedir-excludes.txt
# rsync-homedir-excludes
#
# A list of files to exclude when backing up *nix home directories using rsync.
#
# Author: Ruben Barkow-Kuder <https://github.com/rubo77/rsync-homedir-excludes>
# Version: 2019-11-30
#

The section of the home backup in the script.

		# Snyc/Copy the /home directory.
		USER=zeus
        	# Delete the SingletonLock on target drive if there so these browsers do not get stuck opening.
        	if [ -d "/tmp/home/$USER/.config/BraveSoftware/Brave-Browser/SingletonLock" ]; then
                	     rm "/tmp/home/$USER/.config/BraveSoftware/Brave-Browser/SingletonLock"
               		     echo "Removed /tmp/home/$USER/.config/BraveSoftware/Brave-Browser/SingletonLock"
        	fi
       		if [ -d "/tmp/home/$USER/.config/chromium/SingletonLock" ]; then
              	      rm "/tmp/home/$USER/.config/chromium/SingletonLock"
                	    echo "Removed /tmp/home/$USER/.config/chromium/SingletonLock"
        	fi
	        if [ -d "/tmp/home/$USER/.config/microsoft-edge/SingletonLock" ]; then
                	    rm "/tmp/home/$USER/.config/microsoft-edge/SingletonLock"
        	            echo "Removed /tmp/home/$USER/.config/microsoft-edge/SingletonLock"
	        fi
		rsync -avP --delete --exclude-from=/usr/local/bin/rsync-homedir-excludes.txt /home/$USER/.[^.]* /tmp/home/$USER/
		rsync -avP --delete /home/$USER/bin /tmp/home/$USER/
		rsync -avP --delete /home/$USER/Desktop /tmp/home/$USER/
		rsync -avP --delete /home/$USER/Documents /tmp/home/$USER/
		rsync -avP --delete /home/$USER/Downloads /tmp/home/$USER/
		rsync -avP --delete /home/$USER/Pictures /tmp/home/$USER/
		rsync -avP --delete /home/$USER/Public /tmp/home/$USER/
		rsync -avP --delete /home/$USER/src /tmp/home/$USER/
		rsync -avP --delete /home/$USER/Templates /tmp/home/$USER/
		rsync -avP --delete /home/$USER/Videos /tmp/home/$USER/
		# For my wallpapers to be copied
		mkdir -p /tmp/home/$USER/.cache/gnome-control-center/backgrounds
		chown $USER:$USER /tmp/home/$USER/.cache/gnome-control-center/backgrounds
		cp -vp /home/$USER/Pictures/background/* /tmp/home/$USER/.cache/gnome-control-center/backgrounds/
		# For the Music directory that is not synced, if this is fresh formatted disk
		# so the mount point will exist and it not fail on boot due lack of it.
		if [ ! -d "/tmp/home/$USER/Music" ]; then
			mkdir "/tmp/home/$USER/Music"
			chown $USER:$USER "/tmp/home/$USER/Music"
			echo "Created home/$USER/Music directory"
		fi
		# For the rtorrent directory that is not synced, if this is fresh formatted disk
		# so the mount point will exist and it not fail on boot due lack of it.
		if [ ! -d "/tmp/home/$USER/rtorrent" ]; then
			mkdir "/tmp/home/$USER/rtorrent"
			chown $USER:$USER "/tmp/home/$USER/rtorrent"
			echo "Created home/$USER/rtorrent directory"
		fi

		echo "Completed Sync/Copy to /tmp/home directory used for home files backup"

Hopefully this will give you some ideas on how to do it, it took me some amount of time to get it right threw trail and error to have a script that works flawlessly now for years. I use it may times a week to clone my install to install to my backup machine if testing something new. It is also the basis for my cron jobs that backup my machine to a drive in the machine every two hours.

Oh almost forgot the grub files.

root@9600k:~# ll bin/boot_
boot_crucial_grub.cfg              boot_nvme_external_spare_grub.cfg
boot_ediloca_8500t_grub.cfg        boot_nvme_grub.cfg
boot_elements_grub.cfg             boot_nvme_spare_grub.cfg
boot_intel_grub.cfg                boot_samsung_256_grub.cfg
boot_kingston_grub.cfg             boot_sp_external_grub.cfg
boot_lenovo_grub.cfg               boot_sp_nvme_grub.cfg
boot_mushkin_8500t_grub.cfg        boot_wd_nvme_spare_grub.cfg
boot_mushkin_grub.cfg              

Those files get copied over depening on the option chosen and after every kernel upgrade I run the fix for the files so everything will continue to boot.

root@9600k:~# ll bin/fix_
fix_apcupsd.sh                 fix_grub_samsung_256.sh
fix_grub_crucial_nvme.sh       fix_grub_sp_nvme.sh
fix_grub_ediloca_8500t.sh      fix_grub_sp_nvme_spare.sh
fix_grub_intel_external.sh     fix_grub_wd_nvme_spare.sh
fix_grub_kingston_ssd.sh       fix_rtorrent.sh
fix_grub_lenovo.sh             fix_swap.sh
fix_grub_mushkin_8500t_ssd.sh  fix_timeout_grub.sh

A section of one of the files.

root@9600k:~# cat bin/fix_grub_crucial_nvme.sh 
#!/bin/bash

# A script to fix the GRUB loader that is put into the boot directory when
# making a copy of my install. It is used when a kernel is upgraded so it will
# have a proper /boot/grub/grub.cfg to boot the install after the copying his done.
# Used when booted from my Crucial 4TB NVMe 9600k drive

# Fix the always 30 countdown in grub with a 5 second one before doing
# the rest of this.
sed -i "s/timeout=30/timeout=5/g" /boot/grub/grub.cfg

# My main Crucial NVMe install.
cp /boot/grub/grub.cfg /root/bin/boot_crucial_grub.cfg
sed -i "s/766dcfc3-a1e4-495f-86e2-570205723fef/766dcfc3-a1e4-495f-86e2-570205723fef/g" /root/bin/boot_crucial_grub.cfg
# My spare SP NVMe install.
cp /boot/grub/grub.cfg /root/bin/boot_sp_nvme_grub.cfg
sed -i "s/766dcfc3-a1e4-495f-86e2-570205723fef/a4410a13-b1ea-4007-b22f-6eb9e0a2ead4/g" /root/bin/boot_sp_nvme_grub.cfg
# My spare machine SP NVMe install.
cp /boot/grub/grub.cfg /root/bin/boot_nvme_spare_grub.cfg
sed -i "s/766dcfc3-a1e4-495f-86e2-570205723fef/f5b84b31-ce88-48ed-bbe4-edeec7a29fb2/g" /root/bin/boot_nvme_spare_grub.cfg
# My Intel external
cp /boot/grub/grub.cfg /root/bin/boot_intel_grub.cfg
sed -i "s/766dcfc3-a1e4-495f-86e2-570205723fef/6977106c-69db-4634-b33f-9a03da4b46ed/g" /root/bin/boot_intel_grub.cfg
# My laptop
cp /boot/grub/grub.cfg /root/bin/boot_lenovo_grub.cfg
sed -i "s/766dcfc3-a1e4-495f-86e2-570205723fef/cd974621-e821-401a-9df2-82054deed073/g" /root/bin/boot_lenovo_grub.cfg

As you can see it is a rather involved process I have developed to get this done but it has worked for years for me now. It will take time for you to get your own up and running but if you keep at it you can get it done.

Online

#3 Yesterday 05:14:58

dchmelik
Member
Registered: 2024-04-28
Posts: 11  

Re: cloning/template installation

That looks advanced (good) but I'm slightly bewildered why you'd backup /dev, /proc, /sys, /run, /tmp, swap when these are unique to not only each computer but sometimes current user/session, and the first three get recreated on reboot, and others (other than if you build packages saved to /tmp) don't matter after reboot.  Anyway, I want to develop my own script(s) like this.  If I do it, I'd backup what I described (before rsync) because those seem more important.

Last edited by dchmelik (Yesterday 05:16:18)

Offline

#4 Yesterday 10:48:43

greenjeans
Member
Registered: 2017-04-07
Posts: 1,217  
Website

Re: cloning/template installation

It all seems like a lot of unnecessary hoo-ha, but maybe that's just me. wink

For cloning and re-deploying a custom OS, Refracta Snapshot is the way to go IMO, utterly simple and dependable.


https://sourceforge.net/projects/vuu-do/ New Vuu-do isos uploaded October 2025!
Vuu-do GNU/Linux, minimal Devuan-based Openbox and Mate systems to build on. Also a max version for OB.
Devuan 5 mate-mini iso, pure Devuan, 100% no-vuu-do. wink Devuan 6 version also available for testing.
Please donate to support Devuan and init freedom! https://devuan.org/os/donate

Offline

#5 Yesterday 13:27:11

RedGreen925
Member
Registered: 2024-12-07
Posts: 181  

Re: cloning/template installation

but I'm slightly bewildered why you'd backup /dev, /proc, /sys, /run, /tmp, swap

You must have missed the exclude= in front of those things, they are not backed up as they are not necessary to do so. The computer recreates all of those directories on boot as that line is for a running system. It is even easier for a system booted from as USB stick a simple mounting of the machine drive and then the back to drive and an rsync of everything on the machine drive to the backup is done. There is no need to exclude anything all that needs to be done on the backup drive you need to make the changes required to boot it on the new machine, in the efi, grub.cfg, fstab, hosts, hostname and any other things you need done. Once completed it should just boot on the new machine. Just make your script going bit by bit at a time testing it along the way until you get it done. Other tools mentioned when I first tried this many years ago not a single one of them could preform a backup and restore so I just carried on and got my solution which works flawlessly after all these years so I see no point in even trying them to judge the state of them now. All they are anyways is just someones code to do the same thing mine does, which if it goes wrong I have no clue where to search to make it work. With mine I know it inside and out and know exactly where to look if my recent change caused some problem. Worse case I go back to the previously working backed up script and try again with new one.

Edit: Oh one of those excluded items are needed the /swap but on an existing install you need not do anything with copying it. It is cleared and used on the reboot/boot of the machine like the /tmp directory. One thing I do need though is the fix_swap.sh run if it is new install drive as it will not exist and you will get a warning error on boot. So I run this file on such a drive and everything is back to normal as it should be.

root@9600k:~# cat bin/fix_swap.sh 
#!/bin/bash

# A script to fix the swapfile missed when using new partition without one already there for a backup/clone/restore.

# make the /swapfile file
fallocate -l 2G /swapfile

# correct the permissions
chmod 600 /swapfile

# format as swap space
mkswap /swapfile

# load the /swapfile
swapon /swapfile

I use swap file as I am not interested in dedicated partition for the purpose that is just one more UUID to keep track of one each and every install.

Last edited by RedGreen925 (Yesterday 13:38:03)

Online

Board footer