Naught McNoone suggested I produce a How To tutorial for this procedure which I recently discovered.
This is a method to let you make, using the Timeshift utility in Linux Mint (though it should be applicable to any Linux distro on which Timeshift can run), a system image of a system with all your settings as you like them and all your programs (including any exe programs run under Wine) installed. This image can be used to recover from a serious system disaster like the death of a hard-drive, it can also be used to make a snapshot to clone your OS setup on to other PCs. This is a means to back up a system, including not just your Linux OS's behind-the-scenes files, but also all your installed programs, operating system settings/customisations and any settings/customisations used in any programs you have, and possibly a few small files within it if you wanted to (test files to check programs open them properly, instruction documents you constntly refer back to, scripts you often use... but NOT big media file collections, this would be a very wasteful and inconvenient way for backing up that sort of thing).
Unlike a clonezilla type backup it should be noted that the system imade can be browsed to copy single files if you really need to, but this isn't the main use case here.
Note that the portable file you will produce, whilst large, is still usually rather smaller than your PCs total partition size. I did this for a freshly installed system, after I'd installed all my programs/settings/customisations... (which themselves added to tens of GB) and done the first few rounds of updates, where I have 100GB of root partition and 500GB of home partition anf 400GB of an extra data partition for big files. The Timeshift USB was able to fit on a "64" GB USB, the img file was around "64" GB, the portable 7z was "only" 30 GB.
This tutorial then discusses how to compress the timeshift image so it is a fully portable 7z file, rather than being a special magic USB which holds your Timeshift image and is both vulnerable to that special USB being damaged, and has all the general inconvenience of being not a file which can be simply copied from plce to place, and requires you use up a USB as a Timeshift partition.
The procedures described here are not that quick, and take some detailed following of instructions, but are the same for any system you want to keep an image of. What follows could probably be automated by some form of scripting.
Here's how to make the compressed image:
1. Create a timeshift snapshot of the system, with the various settings to copy home and other directories it normally wouldn't, but which you'll want to copy if you're to make the image contain programs (like exe files under wine) which live in a home directory. You'll probably want to copy hidden files (like the bash history) as well as all files.
1.5. In the Timeshift settings "Users" tab, tick "Include All Files" for /root, and tick both "Include Only Hidden Files" and "Include All Files" in /home/your_user_name. Then in the filters tab:
(+) + /root/**
(+) + /home/your_user_name/**
(-) X /home/your_user_name/Documents/***
(-) X /home/your_user_name/Music/***
(-) X /home/your_user_name/Videos/***
(-) X /media/your_user_name/***
(-) X /media/any_permanently_mounted_data_partition_you_want_to_ignore/***
(-) X /mnt/***
(+) + /home/your_user_name/.**
(-) X /home/your_user_name/Pictures/***
Where (+) or (-)represents the column to be ticked, and + or X represents the coloured figure shown at the start of each line. Ensure these are shown in this order. Note that there is no exclusion pattern for the Downloads folder, as I have the bad habit of using it as a store for some installed programs, you may exclude it if you do not. Any non-excluded sub-folder of /home/your_user_name/ will be backed up, as will all files directly in /home/your_user_name/ . If you happen to store any programs or settings in Documents then remove this line from the filter list.
2. Make this snapshot on the smallest USB which is big enough to fit it
3. I'd advise some restarting of the system and such at this point, in my use case it was months between making the timeshift USB and learning how to do the next bit. The next bit could also be done on a totally different system to the one on which the original timeshift USB was made.
4. Run
sudo dd if=/dev/sdX of=/home/username/timeshift_img/NameBackupSDB.img status=progress
with sdX being the name the USB gets given when plugged in (warning, it might have a different name depending what order you plug it in with compared to other devices connected at the time). It is very important to clone it as /dev/sdb, NOT as /dev/sdb1, you want the whole drive, not just the partition. Ensure you have spare HDD space big enough the whole USB's size before you begin.
5. Run, from inside the timeshift_img folder,
7z a SDBNameBackupCompressed.7z NameBackupSDB.img -p -mhe=on -mx=3
, mx=3 is useful here as it quickens the compressing by not trying to optimise too hard for file size
, mhe=on is optional, if you want to encrypt the backup, a wise move if your original timeshift snapshot had password files on the system which you copied and therefore now stored within it. Before running, ensure you have spare HDD space for a new 7z file sized to be a good proportion of the size of the img file. Note that even though only mx=3 compression level is used, the compression is typically quite good, getting down to about 50% of the original size, Timeshift snapshots are much more compressible than things like image or video files which are already compressed formats.
6. That 7z, albeit potentially a rather big file, is now fully portable. You can save it on any drive, anywhere, with any formatting for the drive so long as it can cope with BIG files (30GB or so for the 7z in my use case) (so NTFS formatted filesystems, but not FAT32 or exFAT).
Here's how to use it:
7. Start by installing your Linux OS fresh on a new system, ensure you install Timeshift within it if Timeshift isn't supplied by default (it is there by default in Mint 21.1, where I tested this). When installing make sure to match partition names, sizes and order to that of the original system you are cloning.
8. Once the fresh install is done and rebooted, so you don't have the live USB for it plugged in any more, copy the 7z file on to this system, uncompress it with 7z either via terminal or via the GUI archive extraction file program so as to create an extracted copy of NameBackupSDB.img on the new system.
9. Get an extra USB, larger than the one originally used for storing the snapshot, and use dd to write the img file to it. It is vital this be bigger than the original, it absolutely must not be smaller. If the original USB was 62GB*, even if only 30GB was used, you need a USB >62GB here even though only the first 30GB of the img file is used. I hear rumours that many drives keep a partition table at the very back end of the drive, so writing an overly large img file overwrites this and makes the drive useless until you've used gparted to wipe it and write a new partition table. I definitely found this the case, I had a 61555605504 byte original USB containing a 57GB timeshift partition plus free space, I initially tried to dd the img to a drive which had a real capacity of 61,530,439,680 bytes, dd gave no errors, but the USB created could not be read even though the only partition which mattered in the drive I had cloned from was only 57GB. I had to use Gparted to make a new partition table, which wiped what I had just dd'd on to it. I retried with a drive which read as 64GB actual capacity, all was fine this time.
sudo dd if=ExtractedNameBackupSDB.img of=/dev/sdc status=progress
sdc here is for the new USB ( >(original size) )you are writing to. If your original was, for example, 62GB and you can't find a truly 64GB USB, use a 128GB here.
*here you notice how important the diferences of advertised capacity and actual can be, many 64GB USBs are 62GB or 58GB... and you also note the irritaing differences of GB vs GiB (Giga vs Gibi, 1000 based vs 1024 based) and how you're never really sure which of Gb and GiB any given program displays figures in and a USB is advertised as
10. Safely eject the USB and restart the freshly installed system
11. When you have restarted, start timeshift on the new system and set it NOT to take automated (daily, or other timeframe) snapshots
11.5. Turn OFF screensaver settings, tell the PC not to go to sleep, or lock the screen
12. Now plug in the USB which you dd'd the img file to, in Timeshift's settings tell Timeshift to look to that USB's partition as the place for snapshots
13. Leaving timeshift's settings alone, proceed to restore the snapshot from that USB
13.5. At the "select target device" stage pick the paths for "/" and "/home" to be the relevant sdaY and sdaZ partitions of the internal HDD, leave "/boot" and "/boot/efi" as "Keep on root device". In bootloder options select the defaults (do "(Re)install Grub2 on:" and pick your SDA hard drive as the device, do not pick a partition, do not update initramfs, do "update grub menu").
14. Timeshift will do its stuff, and then put the PC in to a state where the whole screen is taken up by a listing of the files Timeshift is restoring
15. Then it will try to restart, and then it will crash
16. Power down the PC, and boot from he live USB again
17. With the live USB booted, mount the root partition of the internal HDD, and run
sudo caja
to create an elevated privilege file browser.
18. Browse to /etc/fstab on the internal HDD's root partition and open it in the elevated privilege text editor
19. Open the Live USB's "Disks" program
20. Edit /etc/fstab so each UUID it presently shows is replaced by the appropriate UUID seen in the Disks window, copy and paste from the Disks window to the /etc/fstab text file each UUID, or the EFI partition, root partition, home partition and any others. Note, if there were a way to work the other way round, telling the live system what UUIDs you want for each partition at an earlier point in time, I'd be interested in understanding that option too if anyone can tell me of ways to choose the UUID during installation of the OS to the HDD while booted from a Live USB.
21. Shut down the PC, remove the Live USB, now boot normally, log in, and open Timeshift again. Note that during pre-login the desktop background will match any custom one you have set, but after login it will still look like the default used on the fresh install.
22. At this point some parts of the snapshot have been restored, but some haven't, now we'll get them all restored
23. When you open Timeshift now it will have all the correct folder filters as were used when your original snapshot was made. Plug in your timeshift snapshot USB, select it as the device to restore from under "Location". When restoring from it use the same "select target device" settings as you did earlier on.
24. Allow it to restore, and go to the screen of scrolling file names again, and shut itself down
25. This time when it restarts it will crash again, you'll need to use the live USB again to make the /etc/fstab changes
26. With those changes made, the same way as before, shut down
27. Then take out the live USB, power up, and you'll have a new system as a clone of the original, having been transferred via a fully portable 7z file
28. You can then wipe the USB used as the timeshift snapshot (wipe just the larger later one, or both of them) and use for normal file storage. You have a 7z file which can be used as a means of generating a timeshift partition USB when one is needed, but when it isn't needed you don't need to use up USB space with the timeshift snapshot, you can store it as just a file on a large enough ntfs partition within any data storage device you have to hand.
Hope this helped you.
Edited by rp88, 12 October 2023 - 03:13 PM.