[SOLVED] Full disk backup without empty sectors

Questions about other topics - please check if your question fits better in another category before posting here
Forum rules
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
Post Reply
User avatar
Shady Medic
Level 1
Level 1
Posts: 13
Joined: Thu Jan 18, 2024 2:45 pm

[SOLVED] Full disk backup without empty sectors

Post by Shady Medic »

Hi there,

I'm trying to achieve something that would allow me to quickly restore my setup on any computer/laptop, however, I don't have much information about what options I have. AI didn't help me much, seems like my requirements are too specific for it.

I am rather new to Linux and I enjoy experimenting. This comes at a cost of completely bricking my whole system here and there.

I have two operating systems on my laptop: Linux Mint 21.3 and Windows 10. My 450 GB drive is partitioned in the following way:

Code: Select all

AME   FSTYPE FSVER LABEL             UUID                                 FSAVAIL FSUSE% MOUNTPOINTS
sda1  vfat   FAT32                   CEAB-59BC                              64,9M    32% /boot/efi
sda2               Microsoft Reserved                                       16,8M
sda3  ntfs         Windows           1CD42404D423DF30                         36G    29% /media/shady/1CD42404D423DF30
sda4  ntfs         Windows Recovery  A84ECC6B4ECC33BA                       88,1M    84% /media/shady/A84ECC6B4ECC33BA
sda5  ntfs         Userfiles Windows 403CE1943CE1856E                       68,1G     1% /media/shady/Userfiles Windows
sda6  ext4   1.0   Linux Home        38dc8b72-b297-4017-a60b-b738b62aa3bd  174,6G     1% /home
sda7  ext4   1.0   Linux Root        b315ed2b-7362-4154-87a5-029043cf89db   14,8G    65% /
sr0
As you can see, I have two separate partitions for both systems (sda3, sda7) and then two separate partition for user files (/home or C:\Users) in both systems (sda5, sda6). And then some other technical partitions (sda1, sda2, sda4). The user files partitions are almost empty.

It took me quite some time to partition the disk properly and install both systems and I don't really want to go through that again every time I mess up something.

So, what I'd like to achieve: I have a 64 GB flash disk, that I'd like to use to save a snapshot of my system at this state (both systems installed, setup/customized and working, almost no user files), so the next time I brick my laptop, I can somehow just plug in the flash disk, load the snapshot back into my 450 GB disk and then just fill the user files partitions with my data (saved in cloud) later again.

The problem is that I know how to make bit image using dd, but that'll always try to copy the whole user files partitions, including the empty space, meaning that the image will not fit to my 64 GB flash drive. At the same time, I want to save the existence of these two partitions, so I just need to expand them after recovery (or, even better, somehow make them expand automatically to predefined sizes).

Is there a way to do this? And if there isn't, what the closest I can get?

Will appreciate any suggestions.
Last edited by Shady Medic on Sat Apr 13, 2024 3:51 am, edited 1 time in total.
User avatar
Lady Fitzgerald
Level 15
Level 15
Posts: 5821
Joined: Tue Jan 07, 2020 3:12 pm
Location: AZ, SSA (Squabbling States of America)

Re: Full disk backup without empty sectors

Post by Lady Fitzgerald »

First, I suggest you use a larger external drive instead the 64GB flash drive you are using. 500 and 1TB HDDs, and even SSDs, are not very expensive anymore, probably for $50 or less. They are also more reliable that USB sticks.

Second, I suggest you look into installing Foxclone on a bootable USB stick using Ventoy and using it to create images you can use to recreate your systems back onto the original drive (I keep several on hand in case one dies or I lose one). In a nutshell, you use the bootable USB stick to run Foxclone and create an image and use the larger external drive to save the image onto. This link will take you Foxclone's user manual that goes into more detail. https://foxclone.org/uguide.html

I use Foxclone and highly recommend it. It's popular with many users here and the developer is also a member here.
Jeannie

To ensure the safety of your data, you have to be proactive, not reactive, so, back it up!
User avatar
fatso
Level 4
Level 4
Posts: 255
Joined: Sat Jul 11, 2020 6:48 pm

Re: Full disk backup without empty sectors

Post by fatso »

Rescuezilla is another great option. Been using it for years, but backups can be large depending on how full the partitions are.
User avatar
Shady Medic
Level 1
Level 1
Posts: 13
Joined: Thu Jan 18, 2024 2:45 pm

Re: Full disk backup without empty sectors

Post by Shady Medic »

Hi, thank you both for your replies. Sorry for my delay, but I've been experimenting some more and looked into different things.

Thank you for your recommendations, but I believe that the mentioned applications offer rather functionalities than I need.

After some more chatting with AI and searching, I think I got most of the procedures needed to achieve what I want figured out, I just ran into a few roadblocks that I could use some help with.

So what I came up with:
- I can create .img files from all 7 of my partitions with the empty space compressed (so they take around 25 GB of space in total).
- I will copy these files to the flash drive and also turn it into a bootable media for installing Linux Mint.
- I also create a bash script to reformat and repartition the disk and restore data from the IMG files into the new partitions (AI generated what you can see in an attachement, I'll definitelly test it before using). This script will also be saved to the flash drive.
- The next time I brick my system, I'll plug in the flash drive, boot into live session and run the script, that will restore all the partitions to the state when I took the snapshot (created the IMG files).

Now my issue is: how can I create a media that will
1. Be bootable into live session
2. Be able to store the 7 .img files and 1 .sh file (probably on a different partition than the unpacked Linux Mint ISO)
3. Be able to access the files mentioned in the previous point during live session

I managed to create a multi-partition bootable media using Ventoy, however, I was unable to mount the data partition (with the IMGs and SH file) during live session.

Also, one more neat thing would be if there's a way to add an icon to the live session's desktop that would run the script stored along with the IMGs. I tried modifying the downloaded ISO file by unpacking it, adding a .desktop file to /casper/filesystem.squashfs/etc/skel/ and then repacking it and using it to create the bootable media, but it didn't appear on the desktop. But this would be just a great addition that could make a system like this useful for others than me, not something that I really need to have.
Attachments
RestoreScript.sh.txt
The script generated by AI (DO NOT RUN, IT CAN DELETE YOUR DRIVE)
(735 Bytes) Downloaded 13 times
User avatar
AndyMH
Level 21
Level 21
Posts: 13759
Joined: Fri Mar 04, 2016 5:23 pm
Location: Wiltshire

Re: Full disk backup without empty sectors

Post by AndyMH »

That sounds like hard work, but it's your computer. I'm the dev for foxclone.

Looking at your script, if you really want to save the partition table, you can dump it to a text file and restore it with sfdisk. But if you want to rely on AI...
Thinkcentre M720Q - LM21.3 cinnamon, 4 x T430 - LM21.3 cinnamon, Homebrew desktop i5-8400+GTX1080 Cinnamon 19.0
User avatar
Lady Fitzgerald
Level 15
Level 15
Posts: 5821
Joined: Tue Jan 07, 2020 3:12 pm
Location: AZ, SSA (Squabbling States of America)

Re: Full disk backup without empty sectors

Post by Lady Fitzgerald »

Why do all that work when using an imaging program like Foxlone or Rescuezilla is so much easier and more reliable?
Jeannie

To ensure the safety of your data, you have to be proactive, not reactive, so, back it up!
User avatar
Shady Medic
Level 1
Level 1
Posts: 13
Joined: Thu Jan 18, 2024 2:45 pm

Re: Full disk backup without empty sectors

Post by Shady Medic »

Why do things the easy way when we can do them the hard way.
–My past math teacher

She meant it ironically, but I took it literally in this case.

The thing is, that I'm trying to optimize the process of system recovery as much as possible (its execution, not its development) and also I really have only that 64 GB flash drive. HDDs of the same size as the drive in my laptop might not be expensive to some, but I'm a poor eastern Europe student with not that much cash I could spare, so I'm trying to work with what I have.

Although I gotta admit, that the mentioned programs definitely look like they have many features that I was unable to notice, so if they allow me to do what I need (store snapshot of non-empty sectors in my 500 GB drive to my 64 GB flash drive and restore them from live boot/make the backup bootable), please tell me.

Please don't feel obliged to help me, I know that my though processes seem like a waste of time to many, so if that's the case, don't waste YOUR time on that. I just thought that I might find someone who was already trying to solve something similar with similar resources.
User avatar
AndyMH
Level 21
Level 21
Posts: 13759
Joined: Fri Mar 04, 2016 5:23 pm
Location: Wiltshire

Re: Full disk backup without empty sectors

Post by AndyMH »

All three utilities mentioned only backup used blocks on partitions with known filesystems like ext4 and ntfs. Foxclone and rescuezilla additionally compress the image files to save further space. Clonezilla will as well but I don't know if it is a default.

Foxclone and rescuezilla are front ends for a terminal utility, partclone, which is used to backup partitions. Foxclone uses sfdisk to save the partition table as a text file and then restore it when doing a restore, rescuezilla probably does the same.

If there is an "industry standard" for linux image backup and cloning, it is clonezilla. The trouble with clonezilla is that it is terminal only, has lots of options (it is the most comprehensive of all the utilities) and can be confusing to new users (I found it intimidating when I first started). Partclone was developed by the same people as Clonezilla (and I think based in Taiwan), so it has a good pedigree.

All three work the same way - download an iso, burn it to a stick (or use ventoy) and boot from it. Clonezilla is the smallest iso, because the other two have a full GUI (based on ubuntu), their isos are much larger.

Everything these utilities do, you can do from the command line. They incorporate more checks to make sure you don't do anything stupid.
Thinkcentre M720Q - LM21.3 cinnamon, 4 x T430 - LM21.3 cinnamon, Homebrew desktop i5-8400+GTX1080 Cinnamon 19.0
Post Reply

Return to “Other topics”